Mojo function
slice
slice(input: Symbol, slices: List[SymbolicSlice], out_dims: List[Dim], location: Optional[_SourceLocation] = Optional(#kgen.none)) -> Symbol
Slices a symbolic tensor along each dimension.
Args:
- input (
Symbol
): The symbolic tensor to slice. - slices (
List[SymbolicSlice]
): Per-dimension slice specifiers. If smaller than the input rank, trivial slices (ie. ones which select the whole range) will be added to the end for the remaining dimensions. - out_dims (
List[Dim]
): The expected output dimensions returned by slicing. These will be assert at graph execution time to be correct. - location (
Optional[_SourceLocation]
): An optional location for a more specific error message.
Returns:
A new symbolic tensor representing the result of slicing the input along each dimension using each slice in slices
respectively. The output will have the same rank as the input, but fewer values depending on the slices. If static_shape
is present it will be used as the output tensor's shape, otherwise each dimension will be dynamic size.
slice(input: Symbol, *slices: Slice, *, out_dims: List[Dim] = List(), location: Optional[_SourceLocation] = Optional(#kgen.none)) -> Symbol
Slices a symbolic tensor with Int
ranges.
Args:
- input (
Symbol
): The symbolic tensor to slice. - *slices (
Slice
): Slices across the tensor's dimensions. If fewer thaninput.rank()
slices are provided, the remaining dimensions will be trivially sliced. - out_dims (
List[Dim]
): The expected output dimensions returned by slicing. These will be assert at graph execution time to be correct. - location (
Optional[_SourceLocation]
): An optional location for a more specific error message.
Returns:
A new symbolic tensor representing the result of slicing the input along its dimension according to slices
. The output will have the same rank as the input, but fewer values depending on the slice values.
Raises:
An exception if out_dims is empty and can't be calculated at graph build time.
slice(input: Symbol, slices: VariadicListMem[Slice, origin], out_dims: List[Dim] = List(), location: Optional[_SourceLocation] = Optional(#kgen.none)) -> Symbol
Slices a symbolic tensor with Int
ranges.
Will raise an exception if out_dim is not set and can't be calculated at graph build time.
Args:
- input (
Symbol
): The symbolic tensor to slice. - slices (
VariadicListMem[Slice, origin]
): Slices across the tensor's dimensions. If fewer thaninput.rank()
slices are provided, the remaining dimensions will be trivially sliced. - out_dims (
List[Dim]
): The expected output dimensions returned by slicing. These will be assert at graph execution time to be correct. - location (
Optional[_SourceLocation]
): An optional location for a more specific error message.
Returns:
A new symbolic tensor representing the result of slicing the input along its dimension according to slices
. The output will have the same rank as the input, but fewer values depending on the slice values.
Raises:
An exception if out_dims is empty and can't be calculated at graph build time.
slice(input: Symbol, idx: Symbol, axis: Int = 0, keep_dims: Bool = 0) -> Symbol
Slices out a n-1
-d plane from the input symbolic tensor.
Args:
- input (
Symbol
): The symbolic tensor to slice. - idx (
Symbol
): The index to select along the given axis. - axis (
Int
): The axis to select using the index. - keep_dims (
Bool
): If True, returns a tensor of the same rank as the input.
Returns:
A new symbolic tensor representing the result of selecting every value having the specified index
in the specified axis
. If keep_dims
is False
, The result will have rank n-1
where n
is the rank of the input tensor, with the axis
dimension removed.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!