Crates.io | mightrix |
lib.rs | mightrix |
version | 0.3.2 |
source | src |
created_at | 2023-08-17 15:03:32.178976 |
updated_at | 2023-08-23 11:10:21.671399 |
description | A library to treat continous memory as a matrix. |
homepage | |
repository | https://github.com/kojofl/mightrix |
max_upload_size | |
id | 947094 |
size | 67,472 |
The mightrix crate exposes matrix types that let continuous memory be used as
if it where a matrix. The dimensions of the matrix is asserted through const
generics. This way the owned variant of the matrix Stacktrix
can use
a fixed size array on the stack.
use mightrix::{ Reftrix, ColumnPrio, ColumnPrioMatrix };
fn main() {
let mut data = vec![1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4];
let mut matrix = Reftrix::<4, 4, ColumnPrio, u8>::from_values(&mut data[..]);
for el in matrix.get_mut_row(0) {
*el *= 2;
}
for col in matrix.cols_mut() {
for (i, cell) in col.into_iter().enumerate() {
*cell += i as u8;
}
}
assert_eq!(&data[..], &[2, 2, 3, 4, 4, 3, 4, 5, 6, 4, 5, 6, 8, 5, 6, 7]);
}
Matrix before:
Col0 | Col1 | Col2 | Col3 | |
---|---|---|---|---|
Row0 | 1 | 2 | 3 | 4 |
Row1 | 1 | 2 | 3 | 4 |
Row2 | 1 | 2 | 3 | 4 |
Row3 | 1 | 2 | 3 | 4 |
Matrix after:
Col0 | Col1 | Col2 | Col3 | |
---|---|---|---|---|
Row0 | 2 | 4 | 6 | 8 |
Row1 | 2 | 3 | 4 | 5 |
Row2 | 3 | 4 | 5 | 6 |
Row3 | 4 | 5 | 6 | 7 |