#matrix-operations #basic #macro #i32 #dot

rustrix

Supports macro and basic operations for matrix

3 releases

0.1.2 Mar 27, 2024
0.1.1 Mar 22, 2024
0.1.0 Jan 21, 2024

#552 in Rust patterns

Download history 4/week @ 2024-02-16 13/week @ 2024-02-23 11/week @ 2024-03-01 55/week @ 2024-03-08 1/week @ 2024-03-15 248/week @ 2024-03-22 45/week @ 2024-03-29 3/week @ 2024-04-05

297 downloads per month

MIT license

11KB
240 lines

Rustrix

Supports macro and basic operations for matrix.
Please note that safety for overflow or other edge cases is not tested.

  • Matrices can now contain generic type values. (i32 and f64 are tested.)

Initialization

use rustrix::*;

let mx = mx![
    1, 2, 3;
    4, 5, 6;
];
use rustrix::*;

let (rows, cols, initial_value) = (2, 3, 1);
let mx = mx!(rows, cols; initial_value);

// 1 1 1
// 1 1 1

Add

use rustrix::*;

let m1 = mx!(3, 3; 2);
let m2 = mx!(3, 3; 3);
let mx = m1 + m2;

// 5 5 5
// 5 5 5
// 5 5 5

Subtract

use rustrix::*;

let m1 = mx!(3, 3; 2);
let m2 = mx!(3, 3; 3);
let mx = m1 - m2;

// -1 -1 -1
// -1 -1 -1
// -1 -1 -1

Dot product

use rustrix::*;

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

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

let mx = m1 * m2;

//  6  6  6  6
// 12 12 12 12

Transpose

use rustrix::*;

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

let tp = mx.tp();

// 1 3 5
// 2 4 6

No runtime deps