mlx_rs

Macro array

Source
macro_rules! array {
    ([$($x:expr),*], shape=[$($s:expr),*]) => { ... };
    ([$([$([$($x:expr),*]),*]),*]) => { ... };
    ([$([$($x:expr),*]),*]) => { ... };
    ([$($x:expr),*]) => { ... };
    ($x:expr) => { ... };
    () => { ... };
}
Expand description

A helper macro to create an array with up to 3 dimensions.

ยงExamples

use mlx_rs::array;

// Create an empty array
// Note that an empty array defaults to f32 and one dimension
let empty = array!();

// Create a scalar array
let s = array!(1);
// Scalar array has 0 dimension
assert_eq!(s.ndim(), 0);

// Create a one-element array (singleton matrix)
let s = array!([1]);
// Singleton array has 1 dimension
assert!(s.ndim() == 1);

// Create a 1D array
let a1 = array!([1, 2, 3]);

// Create a 2D array
let a2 = array!([
    [1, 2, 3],
    [4, 5, 6]
]);

// Create a 3D array
let a3 = array!([
    [
        [1, 2, 3],
        [4, 5, 6]
    ],
    [
        [7, 8, 9],
        [10, 11, 12]
    ]
]);

// Create a 2x2 array by specifying the shape
let a = array!([1, 2, 3, 4], shape=[2, 2]);