3 unstable releases

Uses old Rust 2015

0.2.0 May 11, 2018
0.1.1 Apr 8, 2018
0.1.0 Feb 19, 2018

#872 in Science

Download history 25/week @ 2024-03-11 22/week @ 2024-03-18 28/week @ 2024-03-25 61/week @ 2024-04-01 14/week @ 2024-04-08 42/week @ 2024-04-15 37/week @ 2024-04-22 10/week @ 2024-04-29 20/week @ 2024-05-06 18/week @ 2024-05-13 16/week @ 2024-05-20 18/week @ 2024-05-27 16/week @ 2024-06-03 17/week @ 2024-06-10 10/week @ 2024-06-17 22/week @ 2024-06-24

67 downloads per month
Used in 4 crates (via madgwick)

MIT/Apache

14KB
325 lines

mat

Statically sized matrices for no_std applications

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

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:

#[macro_use]
extern crate mat;

use mat::traits::Matrix;

fn main() {
    // 2 by 3 matrix
    let a = mat!(i32, [
        [1, 2, 3],
        [3, 4, 5],
    ]);

    // 3 by 2 matrix
    let b = mat!(i32, [
        [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.

  • Operations 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.

Dependencies

~260KB