Skip to content

Numeric & tensor manipulation functions

Roman edited this page Sep 9, 2020 · 5 revisions

Numeric functions

The following numeric and tensor manipulation functions are available.

Sum [sum]

Sum all elements of a tensor. Works for any order tensors

Tensor<double,K,M,N> A;
double value = sum(A);

Product [product]

Multiply all elements of a tensor. Works for any order tensors

Tensor<double,K,M,N> A;
double value = product(A);

Min [min]

Compute the minimum element of a tensor. Works for any order tensors

Tensor<double,K,M,N> A;
double value = min(A);

Max [max]

Compute the maximum element of a tensor. Works for any order tensors

Tensor<double,K,M,N> A;
double value = max(A);

Reshape [reshape]

Reshape an existing tensor in to a tensor of different shape. Note that this reshapes in-place so changing the original tensor will change the reshaped tensor and vice versa

Tensor<double,3,4> A;
auto b = reshape<2,2,3>(A);

Flatten [flatten]

Flatten an existing multi-dimensional tensor in to a 1D tensor. Note that this flattens in-place so changing the original tensor will change the flattened tensor and vice versa

Tensor<double,2,3,4> A;
auto b = flatten(A); // will return TensorMap<double,24>

Squeeze [squeeze]

Squeeze a tensor - remove dimensions of 1 from a tensor. Note that this squeezes in-place so changing the original tensor will change the squeezed tensor and vice versa

Tensor<double,2,1,3,4,1> A;
auto b = sqeeze(A); // will return TensorMap<double,2,3,4>