Crate mat [] [src]

Statically sized matrices for no_std applications

This library provides support for creating and performing mathematical operations on statically sized matrices. That is matrices whose dimensions are known at compile time. The main use case for this library are no_std programs where a memory allocator is not available.

Since the matrices are statically allocated the dimensions of the matrix are stored in the type system and used to prevent invalid operations (e.g. adding a 3x4 matrix to a 4x3 matrix) at compile time.

For performance reasons all operations, except for the indexing get method, are lazy and perform no actual computation. An expression like a * b + c; simply builds an expression tree. get can be used to force evaluation of such a tree; see below:

#![feature(proc_macro)]

use mat::mat;
use mat::traits::Matrix;

// 2 by 3 matrix
let a = mat![
    [1, 2, 3],
    [3, 4, 5],
];

// 3 by 2 matrix
let b = mat![
    [1, 2],
    [3, 4],
    [5, 6],
];

// build an expression tree
let c = &a * &b;

// partially evaluate the tree
assert_eq!(c.get(0, 0), 22);

This program does not allocate and compute a whole new matrix C of size 2x2; it simply performs the operations required to get the element at row 0 and column 0 that such matrix C would have.

Out of scope

The following features are out of scope for this library.

  • Operation that require dynamic memory allocation
  • SIMD acceleration
  • n-dimensional arrays

If you are looking for such features check out the ndarray crate.

Development status

This library is unlikely to see much development until support for const generics lands in the compiler.

Re-exports

pub use mat_macros::mat;

Modules

traits

Traits

Structs

Mat

Statically allocated (row major order) matrix

Product

The product of two matrices

Sum

The sum of two matrices

Transpose

The transpose of a matrix