#matrix-operations #macro #basic #scalar

rustrix

Supports macro and basic operations for matrix

4 releases

0.2.0 Aug 7, 2024
0.1.2 Mar 27, 2024
0.1.1 Mar 22, 2024
0.1.0 Jan 21, 2024

#636 in Rust patterns

Download history 3/week @ 2024-08-14 9/week @ 2024-09-11 3/week @ 2024-09-18 7/week @ 2024-09-25 7/week @ 2024-10-02

191 downloads per month

MIT license

13KB
274 lines

Rustrix

Supports macro and basic operations for matrix.

Initialization

use rustrix::*;

let m = mx![
    1, 2, 3;
    4, 5, 6;
];

let (rows, cols, init) = (2, 3, 1);
let m1 = mx!(rows, cols; init);
let m2 = mx![
    1, 1, 1;
    1, 1, 1;
];

assert_eq!(m1, m2)

Add

use rustrix::*;

let m = mx!(2, 3; 2) + mx!(2, 3; 3);

Subtract

use rustrix::*;

let m = mx!(2, 3; 4) - mx!(2, 3; 1);

Dot product

use rustrix::*;

let m1 = mx![
    1, 1;
    2, 2;
];

let m2 = mx![
    1, 1, 1, 1;
    2, 2, 2, 2;
];

let m = m1 * m2;

Transpose

use rustrix::*;

let m1 = mx![
    1, 2;
    3, 4;
    5, 6;
];

let m2 = m1.tp();
let m3 = m1.transpose();

Scalar multiplication

use rustrix::*;

let m1 = mx![
    1, 2, 3;
    4, 5, 6;
];

let m2 = m1.mul_scalar(2);

lib.rs:

Supports macro and basic operations for matrix.

Initialization

use rustrix::*;

let m = mx![
    1, 2, 3;
    4, 5, 6;
];

let (rows, cols, init) = (2, 3, 1);
let m1 = mx!(rows, cols; init);
let m2 = mx![
    1, 1, 1;
    1, 1, 1;
];

assert_eq!(m1, m2)

Add

use rustrix::*;

let m = mx!(2, 3; 2) + mx!(2, 3; 3);

Subtract

use rustrix::*;

let m = mx!(2, 3; 4) - mx!(2, 3; 1);

Dot product

use rustrix::*;

let m1 = mx![
    1, 1;
    2, 2;
];

let m2 = mx![
    1, 1, 1, 1;
    2, 2, 2, 2;
];

let m = m1 * m2;

Transpose

use rustrix::*;

let m1 = mx![
    1, 2;
    3, 4;
    5, 6;
];

let m2 = m1.tp();
let m3 = m1.transpose();

Scalar multiplication

use rustrix::*;

let m1 = mx![
    1, 2, 3;
    4, 5, 6;
];

let m2 = m1.mul_scalar(2);

No runtime deps