tensor

Macro tensor 

Source
macro_rules! tensor {
    ($([$([$([$([$([$($x:expr),* $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?) => { ... };
    ($([$([$([$([$($x:expr),* $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?) => { ... };
    ($([$([$([$($x:expr),* $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?) => { ... };
    ($([$([$($x:expr),* $(,)?]),+ $(,)?]),+ $(,)?) => { ... };
    ($([$($x:expr),* $(,)?]),+ $(,)?) => { ... };
    ($($x:expr),* $(,)?) => { ... };
    ([[[[[$elem:expr; $i:expr]; $j:expr]; $k:expr]; $l:expr]; $m:expr]; $n:expr) => { ... };
    ([[[[$elem:expr; $i:expr]; $j:expr]; $k:expr]; $l:expr]; $m:expr) => { ... };
    ([[[$elem:expr; $i:expr]; $j:expr]; $k:expr]; $l:expr) => { ... };
    ([[$elem:expr; $i:expr]; $j:expr]; $k:expr) => { ... };
    ([$elem:expr; $i:expr]; $j:expr) => { ... };
    ($elem:expr; $i:expr) => { ... };
}
Expand description

Creates a dense multidimensional array containing the arguments.

This macro is used to create an array, similar to the vec! macro for vectors. There are two forms of this macro:

  • Create an array containing a given list of elements:
use mdarray::{DTensor, tensor};

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

assert_eq!(a, DTensor::<_, 2>::from([[1, 2, 3], [4, 5, 6]]));
  • Create an array from a given element and shape by cloning the element:
use mdarray::{tensor, Tensor};

let a = tensor![[1; 3]; 2];

assert_eq!(a, Tensor::from_elem([2, 3], 1));

In the second form, like for vectors the shape does not have to be constant.