flatten#

Flatten an operator into a 1D operator where the total length is the product of all sizes of the original operator

template<typename T1>
auto __MATX_INLINE__ matx::flatten(const T1 &a)#

Flatten operator

The flatten operator takes an operator of rank 2 or higher and flattens every dimension into a single 1D tensor.

Template Parameters:

T1 – Operator type

Returns:

Operator of flattened input

Examples#

auto t2 = make_tensor<TestType>({10, 2});
auto val = GenerateData<TestType>();

for (index_t i = 0; i < t2.Size(0); i++) {
  for (index_t j = 0; j < t2.Size(1); j++) {
    t2(i,j) = val;
  }
}

auto t1 = make_tensor<TestType>({t2.Size(0)*t2.Size(1)});
(t1 = flatten(t2)).run(exec);