reshape

reshape#

Reshape an operator by giving it new sizes. The total size of the reshaped operator must match the original size.

template<int RANK, typename T, typename ShapeType, std::enable_if_t<!std::is_array_v<typename remove_cvref<ShapeType>::type>, bool> = true>
__MATX_INLINE__ auto matx::reshape(const T &op, ShapeType &&s)#

Operator to reshape a tensor or operator.

This operator can appear as an rvalue or lvalue.

Template Parameters:
  • RANK – the reshaped rank

  • T – Input operator/tensor type

Parameters:
  • op – Input operator

  • s – the size of each reshaped dimension

Returns:

reshaped operator

template<int RANK, typename T>
__MATX_INLINE__ auto matx::reshape(const T &op, const index_t (&sizes)[RANK])#

Operator to reshape a tensor or operator.

This operator can appear as an rvalue or lvalue.

Template Parameters:
  • RANK – the reshaped rank

  • T – Input operator/tensor type

Parameters:
  • op – Input operator

  • sizes – the size of each reshaped dimension

Returns:

reshaped operator

Examples#

auto A = make_tensor<TestType>({2*4*8*16});
for(int i = 0; i < A.Size(0); i++) {
  A(i) = static_cast<typename inner_op_type_t<TestType>::type>(i);
}

// op is a 4D operator
auto op = reshape(A, {2, 4, 8, 16});

// op2 is a 1D operator
auto op2 = reshape(op, {2 * 4 * 8 * 16});