casting
Operations which operate on the shape or dtype of symbolic tensor.
shape_of
shape_of(owned v: Symbol) -> Symbol
Gets the shape of an existing tensor as a rank-1 symbolic tensor.
Args:
- v (
Symbol
): The symbolic tensor whose shape is returned.
Returns:
A symbolic rank-1 tensor representing the input's shape.
cast
cast(owned v: Symbol, owned dtype: ElementType) -> Symbol
Casts a symbolic tensor to a different dtype.
Args:
- v (
Symbol
): The input tensor to cast. - dtype (
ElementType
): The target dtype to which the tensor is cast.
Returns:
A new symbolic tensor with the same shape as the input and the specified dtype.
squeeze
squeeze(owned v: Symbol, owned axis: Int) -> Symbol
Removes a size-1 dimension from a symbolic tensor.
Args:
- v (
Symbol
): The input symbolic tensor to squeeze. - axis (
Int
): The dimension to remove from the input's shape. If negative, indexes from the end of the tensor, eg.squeeze(v, -1)
will squeeze the last dimension.
Returns:
A symbolic tensor with the same number of elements as the input tensor, and whose rank is 1 less than the rank of the input tensor.
unsqueeze
unsqueeze(owned v: Symbol, owned axis: Int) -> Symbol
Inserts a size-1 dimension into a symbolic tensor.
Args:
- v (
Symbol
): The input symbolic tensor to unsqueeze. - axis (
Int
): The index at which to insert a new dimension into the input's shape. Dimensions with that index or higher will be shifted back. If negative, it indexes relative 1 plus the rank of the tensor, in other wordsunsqueeze(v, -1)
will add the new dimension at the end,unsqueeze(v, -2)
will insert the dimension immediately before the last dimension, etc.
Returns:
A symbolic tensor with the same muber of elements as the input tensor, whose rank is 1 larger than the rank of the input tensor. The result's shape at the axis
dimension will be a static dimension of size 1.
reshape
reshape(v: Symbol, shape: Symbol, out_dims: List[Dim]) -> Symbol
Reshapes a symbolic tensor to a specified shape.
The number and order of the elements in the tensor is unchanged.
In other words, if you were to iterate over elements in the tensor
by major dimension to minor dimension, the iteration order would stay
the same.
If a value of -1 is present in the shape, that dimension will become
a dynamic dimension collecting all unspecified dimensions.
Its length will be the number of elements in the original tensor
divided by the product of elements of the reshape.
Args:
- v (
Symbol
): The input symbolic tensor to reshape. - shape (
Symbol
): The shape to reshape to as a symbolic rank-1 tensor. The input must have integer dtype, and must either be all non-negative elements or allows a single element of -1. - out_dims (
List[Dim]
): A type hint for the tensor's symbolic shape in the graph.
Returns:
A symbolic tensor with the same elements as the original tensor in a new shape. Its symbolic shape will be the same as out_dims
.
reshape(v: Symbol, shape: SymbolTuple) -> Symbol
Reshapes a symbolic tensor to a specified shape.
The number and order of the elements in the tensor is unchanged.
In other words, if you were to iterate over elements in the tensor
by major dimension to minor dimension, the iteration order would stay
the same.
If a value of -1 is present in the shape, that dimension will become
a dynamic dimension collecting all unspecified dimensions.
Its length will be the number of elements in the original tensor
divided by the product of elements of the reshape.
Args:
- v (
Symbol
): The input symbolic tensor to reshape. - shape (
SymbolTuple
): A list of rank-0 symbolic tensors to reshape to. The inputs must have integer dtype, and must either be all non-negative elements or allows a single element of -1.
Returns:
A symbolic tensor with the same elements as the original tensor in a new shape. It will have rank equal to the length of shape
, but every symbolic dimension of the result will be dynamic size.
reshape(v: Symbol, shape: Symbol) -> Symbol
Reshapes a symbolic tensor to a specified shape.
The number and order of the elements in the tensor is unchanged.
In other words, if you were to iterate over elements in the tensor
by major dimension to minor dimension, the iteration order would stay
the same.
If a value of -1 is present in the shape, that dimension will become
a dynamic dimension collecting all unspecified dimensions.
Its length will be the number of elements in the original tensor
divided by the product of elements of the reshape.
Args:
- v (
Symbol
): The input symbolic tensor to reshape. - shape (
Symbol
): The shape to reshape to as a symbolic rank-1 tensor. The input must have integer dtype, and must either be all non-negative elements or allows a single element of -1.
Returns:
A symbolic tensor with the same elements as the original tensor in a new shape. It will have rank equal to the static size of shape
, but every symbolic dimension of the result will be dynamic size.
reshape_like
reshape_like(v: Symbol, like: Symbol) -> Symbol
Reshapes a symbolic tensor to the same shape as another tensor.
The number and order of the elements in the tensor is unchanged.
In other words, if you were to iterate over elements in the tensor
by major dimension to minor dimension, the iteration order would stay
the same.
Args:
- v (
Symbol
): The input symbolic tensor to reshape. - like (
Symbol
): A symbolic tensor whose shape should be used as the reshape.
Returns:
A symbolic tensor with the same elements as the original tensor in a new shape. The shape of the new tensor will be the same as the shape of the like
tensor.
transpose
transpose(owned input: Symbol, owned x: Int, owned y: Int) -> Symbol
Transposes two dimensions of a symbolic tensor.
Args:
- input (
Symbol
): The input symbolic tensor to transpose. - x (
Int
): One of the two dimensions to transpose. If negative, indexes from the end of the tensor, eg.transpose(v, -1, -2)
will transpose the last two dimensions. - y (
Int
): The other dimension to transpose. May also be negative to index from the end of the tensor.
Returns:
A new symbolic tensor with the two specified dimensions transposed. It will have the same elements and dtype, but the order of the elements will be different according to the transposition.
transpose_matrix
transpose_matrix(owned matrix: Symbol) -> Symbol
Transposes the last two dimensions of a symbolic tensor.
Args:
- matrix (
Symbol
): The symbolic tensor to transpose.
Returns:
A new symbolic tensor with its last two dimensions transposed. It will have the same elements and dtype, but the order of the elements will be different according to the transposition.