65 releases (31 breaking)

Uses new Rust 2024

0.38.3 Oct 23, 2025
0.37.1 Oct 12, 2025
0.33.1 Jul 23, 2025
0.28.2 Mar 28, 2025
0.15.2 Jul 12, 2024

#263 in Data structures

Download history 247/week @ 2025-07-19 23/week @ 2025-07-26 330/week @ 2025-08-16 56/week @ 2025-08-23 2/week @ 2025-08-30 110/week @ 2025-09-06 143/week @ 2025-09-13 128/week @ 2025-09-20 52/week @ 2025-09-27 14/week @ 2025-10-04 519/week @ 2025-10-11 469/week @ 2025-10-18 54/week @ 2025-10-25

1,042 downloads per month
Used in lifegame

MIT license

430KB
9K SLoC

matreex

Crates.io Documentation License

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![[2, 2], [2, 2], [2, 2]];
assert_eq!(lhs * rhs, matrix![[12, 12], [30, 30]]);

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_operation(&rhs, |lhs, rhs| lhs / 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.

Is it no_std compatible?

This crate is no_std compatible if the parallel feature is not enabled.

Dependencies

~0.3–1.3MB
~28K SLoC