change_shape

Function change_shape 

Source
pub fn change_shape<'a, I, R, T, B, D>(
    tensor: TensorBase<Storage<R, T, B>, D>,
    shape: I,
) -> TensorBase<Storage<DataCow<'a, <B as DeviceRawAPI<T>>::Raw>, T, B>, Vec<usize>>
Expand description

Reshapes the given tensor to the specified shape.

This function is not intended to be used by usual users. Please consider using reshape (take reference of tensor) or into_shape (take ownership of tensor) instead.

Row/Column Major Notice

This function behaves differently on default orders (RowMajor and ColMajor) of device.

§Parameters

  • tensor: TensorAny<R, T, B, D>

    • The input tensor to be reshaped.
    • Ownership of input tensor is taken.
  • axes: TryInto AxesIndex<isize>

    • Position in the expanded axes where the new axis (or axes) is placed.
    • Can be a single integer, or a list/tuple of integers.
    • Negative values are supported and indicate counting dimensions from the back.

§Returns

  • TensorCow<'a, T, B, IxD>

    • The reshaped tensor.

    • This function will try to avoid data cloning if possible.

      • If layout-compatible, depending on whether the input tensor is owned or other cases, either a view or owned tensor will be returned.
      • If layout-not-compatible, an owned tensor will be returned, cloning the data.
      • Cow (Clone-on-Write) semantics is used for representing either view or owned tensor.

This function is different to reshape, in that it takes ownership of the input tensor.

This function is also different to into_shape, in that it may return a view, if the input tensor also have the ownership of tensor view, and the layout is compatible.

§See also

Refer to reshape for more details and examples.