43 releases (21 breaking)

new 0.22.2 Jan 10, 2025
0.22.0 Dec 20, 2024
0.21.0 Nov 14, 2024
0.15.2 Jul 12, 2024

#369 in Data structures

Download history 49/week @ 2024-09-21 136/week @ 2024-09-28 120/week @ 2024-10-05 179/week @ 2024-10-12 25/week @ 2024-10-19 196/week @ 2024-10-26 59/week @ 2024-11-02 104/week @ 2024-11-09 24/week @ 2024-11-16 3/week @ 2024-11-23 502/week @ 2024-12-07 137/week @ 2024-12-14 94/week @ 2024-12-21 13/week @ 2024-12-28 19/week @ 2025-01-04

333 downloads per month

MIT license

220KB
4.5K SLoC

matreex

Crates.io Documentation License: MIT

A simple matrix implementation.

Quick Start

First, we need to import matrix!.

use matreex::matrix;

Addition

let lhs = matrix![[0, 1, 2], [3, 4, 5]];
let rhs = matrix![[2, 2, 2], [2, 2, 2]];
assert_eq!(lhs + rhs, matrix![[2, 3, 4], [5, 6, 7]]);

Subtraction

let lhs = matrix![[0, 1, 2], [3, 4, 5]];
let rhs = matrix![[2, 2, 2], [2, 2, 2]];
assert_eq!(lhs - rhs, matrix![[-2, -1, 0], [1, 2, 3]]);

Multiplication

let lhs = matrix![[0, 1, 2], [3, 4, 5]];
let rhs = matrix![[0, 1], [2, 3], [4, 5]];
assert_eq!(lhs * rhs, matrix![[10, 13], [28, 40]]);

Division

let lhs = matrix![[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]];
let rhs = matrix![[2.0, 2.0, 2.0], [2.0, 2.0, 2.0]];
assert_eq!(lhs / rhs, matrix![[0.0, 0.5, 1.0], [1.5, 2.0, 2.5]]);

Wait, matrix division isn't well-defined, remember? It won't compile. But don't worry, you might just need to perform elementwise division:

let lhs = matrix![[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]];
let rhs = matrix![[2.0, 2.0, 2.0], [2.0, 2.0, 2.0]];
assert_eq!(lhs.elementwise_div(&rhs), Ok(matrix![[0.0, 0.5, 1.0], [1.5, 2.0, 2.5]]));

Or scalar division:

let matrix = matrix![[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]];
assert_eq!(matrix / 2.0, matrix![[0.0, 0.5, 1.0], [1.5, 2.0, 2.5]]);

let matrix = matrix![[1.0, 2.0, 4.0], [8.0, 16.0, 32.0]];
assert_eq!(2.0 / matrix, matrix![[2.0, 1.0, 0.5], [0.25, 0.125, 0.0625]]);

Or maybe the inverse of a matrix?

Nah, we don't have that yet.

FAQs

Why named matreex?

Hmm ... Who knows? Could be a name conflict.

Dependencies

~1.5MB
~26K SLoC