#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

#631 in Rust patterns

Download history 18/week @ 2024-07-29 117/week @ 2024-08-05 6/week @ 2024-08-12 10/week @ 2024-09-16 4/week @ 2024-09-23 12/week @ 2024-09-30

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