#matrix #structure #dimension #size #matrixes #nd-matrix

nthD_Matrix

A library for using matrixes of any arbitrary size and dimension

3 releases

0.1.2 Apr 8, 2023
0.1.1 Apr 7, 2023
0.1.0 Apr 6, 2023

#984 in Math

31 downloads per month

MIT/Apache

11KB
183 lines

A simple library that allows you to use matrixes of any size and dimension, and access their internals as a regular old vector. NdMatrix provides a flexible data structure for any data, with basic arithmetic operations (thanks num_traits!). Check the Docs.md file on github for more info.

Matrixes can be initialized easily with the matrix! macro:

//dimensions, type, default
let matrix = matrix!([10,10,10]; usize, 15);

And then accessed with either coordinates or an absolute index into the vector:

let value1 = matrix.pos(vec![3,2,4])?;
let value2 = matrix.nth(15)?;

This setup makes iteration through a matrix straightforward, with no messy nested for loops:

for i in 0..matrix.len() {
    let pos:Vec<usize> = matrix.nth_to_pos(i)?;
    //do stuff with the position!
}

(iterators are a thing now too)

Basic arithmetic is also available for numeric types:

let mut matrix_a = matrix!([5,5]; usize, 10);
let matrix_b = matrix!([5,5]; usize, 10);

matrix_a.add(matrix_b);//adds 2 matrixes
matrix_a.const_add(15);//adds one value to every element of a matrix

add, sub, mul, and div can be called, along with their constant counterparts. Note that the 2 matrixes MUST be the same size, and mul is not the traditional "matrix multiplication," it simply multiplies each element together (coming soon).

Dependencies

~150KB