macro_rules! matrix {
    () => { ... };
    ($( $( $x: expr ),*);*) => { ... };
}
Expand description

The matrix! macro enables easy construction of small matrices.

This is particularly useful when writing tests involving matrices. Note that the macro is just a convenient wrapper around the Matrix constructors, and as a result the matrix is still allocated on the heap.

Rows are separated by semi-colons, while commas separate the columns. Users of MATLAB will find this style familiar. If the dimensions don’t match, the macro will fail to compile.

Examples

#[macro_use]
extern crate rulinalg;

// Construct a 3x3 matrix of f64
let mat = matrix![1.0, 2.0, 3.0;
                  4.0, 5.0, 6.0;
                  7.0, 8.0, 9.0];

To construct matrices of other types, specify the type by the usual Rust syntax:

use rulinalg::matrix::Matrix;

// Construct a 2x3 matrix of f32
let mat: Matrix<f32> = matrix![1.0, 2.0, 3.0;
                               4.0, 5.0, 6.0];
// Or
let mat = matrix![1.0, 2.0, 3.0;
                  4.0, 5.0, 6.0f32];