#matrix-vector #matrix #const-generics #sized #linear-algebra #vector

nightly no-std sized_matrix

Sized matrices using const generics for better type checking and performance

8 releases

0.3.0 Jun 27, 2022
0.2.5 Apr 5, 2021
0.2.3 Nov 13, 2020
0.2.2 Sep 8, 2020
0.1.0 Aug 25, 2020

#1209 in Math

Download history 9/week @ 2024-02-25 1/week @ 2024-03-03 7/week @ 2024-03-10 91/week @ 2024-03-31

98 downloads per month
Used in noise_fn

MIT license

24KB
464 lines

sized_matrix

Crate

Documentation

Repository

Changelog

Sized matrices using const generics for better type checking and performance.

use sized_matrix::{Matrix, Vector};

let a: Matrix<i32, 3, 4> = Matrix::rows([
	[ 1,  2,  3,  4],
	[ 5,  6,  7,  8],
	[ 9, 10, 11, 12],
]);

let b: Matrix<i32, 4, 2> = Matrix::rows([
	[ 0,  1],
	[ 1,  2],
	[ 3,  5],
	[ 8, 13],
]);

let c: Matrix<i32, 3, 2> = a * b;

assert_eq!(c, Matrix::rows([
	[ 43,  72],
	[ 91, 156],
	[139, 240],
]));

let d: Vector<i32, 2> = Matrix::vector([-1, 1]);

let e: Vector<i32, 3> = c * d;

assert_eq!(e, Matrix::vector([
	 29,
	 65,
	101,
]));

To use this, add it as a dependency to your Cargo.toml:

[dependencies]
sized_matrix = "^0.3.0"

lib.rs:

Sized matrices using const generics for better type checking and performance.

use sized_matrix::{Matrix, Vector};

let a: Matrix<i32, 3, 4> = Matrix::rows([
    [ 1,  2,  3,  4],
    [ 5,  6,  7,  8],
    [ 9, 10, 11, 12],
]);

let b: Matrix<i32, 4, 2> = Matrix::rows([
    [ 0,  1],
    [ 1,  2],
    [ 3,  5],
    [ 8, 13],
]);

let c: Matrix<i32, 3, 2> = a * b;

assert_eq!(c, Matrix::rows([
    [ 43,  72],
    [ 91, 156],
    [139, 240],
]));

let d: Vector<i32, 2> = Matrix::vector([-1, 1]);

let e: Vector<i32, 3> = c * d;

assert_eq!(e, Matrix::vector([
     29,
     65,
    101,
]));

To use this, add it as a dependency to your Cargo.toml:

[dependencies]
sized_matrix = "^0.3.0"

Dependencies

~235KB