58 releases (27 breaking)

Uses new Rust 2024

new 0.28.4 Apr 5, 2025
0.28.2 Mar 28, 2025
0.22.0 Dec 20, 2024
0.21.0 Nov 14, 2024
0.15.2 Jul 12, 2024

#245 in Data structures

Download history 155/week @ 2024-12-13 144/week @ 2024-12-20 15/week @ 2024-12-27 23/week @ 2025-01-03 403/week @ 2025-01-10 108/week @ 2025-01-17 194/week @ 2025-01-24 53/week @ 2025-01-31 87/week @ 2025-02-07 69/week @ 2025-02-14 188/week @ 2025-02-21 663/week @ 2025-02-28 26/week @ 2025-03-07 108/week @ 2025-03-21 343/week @ 2025-03-28

482 downloads per month

MIT license

295KB
6K 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![[1, 2, 3], [4, 5, 6]];
let rhs = matrix![[2, 2, 2], [2, 2, 2]];
assert_eq!(lhs + rhs, matrix![[3, 4, 5], [6, 7, 8]]);

Subtraction

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

Multiplication

let lhs = matrix![[1, 2, 3], [4, 5, 6]];
let rhs = matrix![[1, 2], [3, 4], [5, 6]];
assert_eq!(lhs * rhs, matrix![[22, 28], [49, 64]]);

Division

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

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![[1.0, 2.0, 3.0], [4.0, 5.0, 6.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.5, 1.0, 1.5], [2.0, 2.5, 3.0]]));

Or scalar division:

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

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

~0–6.5MB
~37K SLoC