asc2.reshape

asc2.reshape(input: LocalTensor, *shape: int) LocalTensor

Reshape a tensor to a new shape without changing its data.

The total number of elements in the new shape must match the total number of elements in the input tensor.

The supported data types are: int8, int16, int32, int64, float16, bfloat16, float32, float64.

Parameters:
  • input – The input tensor

  • shape – The target shape (can be passed as separate integers or as an iterable, e.g. list or tuple)

Returns:

A tensor with the new shape

Return type:

LocalTensor

Raises:
  • TypeError – If input is not a LocalTensor or shape contains non-integer values

  • RuntimeError – If the total number of elements doesn’t match or shape values are not positive

Examples

Reshape a 1D tensor to 2D:

input = asc2.copy_in(x, [0], [256])
result = input.reshape([16, 16])

Reshape a 2D tensor to 1D:

input = asc2.copy_in(x, [0, 0], [32, 16])
result = input.reshape([512])

This function can also be called as a member function on LocalTensor, as input.reshape(...) instead of reshape(input, ...).