This document is relevant for: Inf2
, Trn1
, Trn1n
nki.tensor#
- class nki.tensor[source]#
A tensor object represents a multidimensional, homogeneous array of fixed-size items
Methods
Assert that the tensor has the given shape.
Copy of the tensor, cast to a specified type.
Broadcast tensor to a new shape based on numpy broadcast rules.
Gives a new shape to a tensor by adding a dimension of size 1 at the specified position.
Gives a new shape to an array without changing its data.
Return a new view of the tensor, reinterpret to a specified type.
Attributes
Get the data type of the tensor.
Get the number of dimensions of the tensor.
Get the shape of the tensor.
- assert_shape(shape)[source]#
Assert that the tensor has the given shape.
- Parameters:
shape – The expected shape.
- Returns:
The tensor.
- astype(dtype)[source]#
Copy of the tensor, cast to a specified type.
- Parameters:
dtype – The target dtype
- Returns:
the tensor with new type. Copy ALWAYS occur
- broadcast_to(shape)[source]#
Broadcast tensor to a new shape based on numpy broadcast rules. The tensor object must be a tile or can be implicitly converted to a tile. A tensor can be implicitly converted to a tile iff the partition dimension is the highest dimension.
- Parameters:
shape – The new shape
- Returns:
Return a new view of the tensor, no copy will occur
- property dtype#
Get the data type of the tensor.
- Returns:
The data type of the tensor.
- expand_dims(axis)[source]#
Gives a new shape to a tensor by adding a dimension of size 1 at the specified position.
- Parameters:
axis – the position of the new dimension.
- Returns:
Return a new tensor with expanded shape
- property ndim#
Get the number of dimensions of the tensor.
- reshape(shape)[source]#
Gives a new shape to an array without changing its data.
- Parameters:
shape – The new shape
- Returns:
Return a new view of the tensor, no copy will occur
- property shape#
Get the shape of the tensor.
- Returns:
The shape of the tensor.
This document is relevant for: Inf2
, Trn1
, Trn1n