Matrijs 🔢
A small 2D f64 matrix library.
There are many like it, but this one is mine.
Note: The example below can be found in examples/basic.rs.
// The matrix! macro allows for quick initialization.
// m = | 0.0 1.0 |
// |-1.0 0.0 |
let mut m = matrix!;
// Scalar math.
m += 1.0;
m *= -10.0;
// You can also create a Matrix manually.
let m_expected = new;
assert_eq!;
// a = | 0.0 1.0 |
// | 2.0 3.0 |
// b = | 4.0 5.0 6.0 |
// | 7.0 8.0 9.0 |
let a = matrix!;
let b = matrix!;
// The dot product of `i` and `a` should be equal to `a` (idempotence).
let i = identity;
assert_eq!;
assert_eq!;
// You can append rows and columns to expand what you're working with.
let mut ones = one;
ones.append_row;
assert_eq!;
// When in doubt, take a look at the shape of the matrix.
assert_eq! // 3 rows, 2 columns
Abilities
- Creation
- From array:
Matrix::new(3, 2, &[0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) - With value:
Matrix::with_value(3, 16.1) - Zeros:
Matrix::zero(3) - Ones:
Matrix::one(3) - Identity:
Matrix::identity(3) - Diagonal:
Matrix::diagonal(&[1.0, 3.0, 1.0, 2.0])
- From array:
- Operations
- Transpose
- In place:
m.transpose(); - By value:
m.t()
- In place:
- Scalar operations
- Addition, subtraction, multiplication, division:
b = a + 1.0,b *= 2
- Addition, subtraction, multiplication, division:
- Matrix-matrix operations
- Entry-by-entry addition, subtraction, multiplication, division:
a + b - Dot product:
a.dot(&b)
- Entry-by-entry addition, subtraction, multiplication, division:
- Transpose
Implementation
The internal data structure is a Vec of entries, row after row.
That means that this is a row-major implementation.
Name
In Dutch, there is a word matrijs (pronounce mat-rice) which has a common ancestor with the word matrix. Matrijs refers to molds or stamps, often when laid out in arrays.
I like the name for this library, because it contains the 'ij' digraph, which is very similar to the letters i and j as seen in notation for entries in a matrix, such as aij.