pub trait TenrsoExecutor<T>{
Show 42 methods
// Required methods
fn einsum(
&mut self,
spec: &str,
inputs: &[TensorHandle<T>],
hints: &ExecHints,
) -> Result<TensorHandle<T>>;
fn elem_op(
&mut self,
op: ElemOp,
x: &TensorHandle<T>,
) -> Result<TensorHandle<T>>;
fn binary_op(
&mut self,
op: BinaryOp,
x: &TensorHandle<T>,
y: &TensorHandle<T>,
) -> Result<TensorHandle<T>>;
fn reduce(
&mut self,
op: ReduceOp,
x: &TensorHandle<T>,
axes: &[Axis],
) -> Result<TensorHandle<T>>;
fn clip(
&mut self,
x: &TensorHandle<T>,
min_val: T,
max_val: T,
) -> Result<TensorHandle<T>>;
fn softmax(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
) -> Result<TensorHandle<T>>;
fn log_softmax(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
) -> Result<TensorHandle<T>>;
fn transpose(
&mut self,
x: &TensorHandle<T>,
axes: &[Axis],
) -> Result<TensorHandle<T>>;
fn reshape(
&mut self,
x: &TensorHandle<T>,
new_shape: &[usize],
) -> Result<TensorHandle<T>>;
fn concatenate(
&mut self,
tensors: &[TensorHandle<T>],
axis: Axis,
) -> Result<TensorHandle<T>>;
fn split(
&mut self,
x: &TensorHandle<T>,
num_splits: usize,
axis: Axis,
) -> Result<Vec<TensorHandle<T>>>;
fn layer_norm(
&mut self,
x: &TensorHandle<T>,
eps: T,
) -> Result<TensorHandle<T>>;
fn batch_norm(
&mut self,
x: &TensorHandle<T>,
eps: T,
) -> Result<TensorHandle<T>>;
fn where_op(
&mut self,
condition: &TensorHandle<T>,
x: &TensorHandle<T>,
y: &TensorHandle<T>,
) -> Result<TensorHandle<T>>;
fn masked_select(
&mut self,
x: &TensorHandle<T>,
mask: &TensorHandle<T>,
) -> Result<TensorHandle<T>>;
fn modulo(
&mut self,
x: &TensorHandle<T>,
divisor: T,
) -> Result<TensorHandle<T>>;
fn remainder(
&mut self,
x: &TensorHandle<T>,
divisor: T,
) -> Result<TensorHandle<T>>;
fn max_pool_1d(
&mut self,
x: &TensorHandle<T>,
kernel_size: usize,
stride: usize,
) -> Result<TensorHandle<T>>;
fn avg_pool_1d(
&mut self,
x: &TensorHandle<T>,
kernel_size: usize,
stride: usize,
) -> Result<TensorHandle<T>>;
fn max_pool_2d(
&mut self,
x: &TensorHandle<T>,
kernel_size: (usize, usize),
stride: (usize, usize),
) -> Result<TensorHandle<T>>;
fn avg_pool_2d(
&mut self,
x: &TensorHandle<T>,
kernel_size: (usize, usize),
stride: (usize, usize),
) -> Result<TensorHandle<T>>;
fn conv1d(
&mut self,
x: &TensorHandle<T>,
kernel: &TensorHandle<T>,
bias: Option<&TensorHandle<T>>,
stride: usize,
padding: (usize, usize),
) -> Result<TensorHandle<T>>;
fn conv2d(
&mut self,
x: &TensorHandle<T>,
kernel: &TensorHandle<T>,
bias: Option<&TensorHandle<T>>,
stride: (usize, usize),
padding: (usize, usize, usize, usize),
) -> Result<TensorHandle<T>>;
fn conv3d(
&mut self,
x: &TensorHandle<T>,
kernel: &TensorHandle<T>,
bias: Option<&TensorHandle<T>>,
stride: (usize, usize, usize),
padding: (usize, usize, usize, usize, usize, usize),
) -> Result<TensorHandle<T>>;
fn gather(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
indices: &TensorHandle<T>,
) -> Result<TensorHandle<T>>;
fn scatter(
&mut self,
shape: &[usize],
axis: Axis,
indices: &TensorHandle<T>,
values: &TensorHandle<T>,
) -> Result<TensorHandle<T>>;
fn determinant(&mut self, x: &TensorHandle<T>) -> Result<TensorHandle<T>>;
fn matrix_inverse(&mut self, x: &TensorHandle<T>) -> Result<TensorHandle<T>>;
fn solve(
&mut self,
a: &TensorHandle<T>,
b: &TensorHandle<T>,
) -> Result<TensorHandle<T>>;
fn advanced_gather(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
indices: &TensorHandle<T>,
allow_negative: bool,
) -> Result<TensorHandle<T>>;
fn advanced_scatter(
&mut self,
shape: &[usize],
axis: Axis,
indices: &TensorHandle<T>,
values: &TensorHandle<T>,
mode: ScatterMode,
) -> Result<TensorHandle<T>>;
fn fancy_index_mask(
&mut self,
x: &TensorHandle<T>,
mask: &TensorHandle<T>,
) -> Result<TensorHandle<T>>;
fn tile(
&mut self,
x: &TensorHandle<T>,
reps: &[usize],
) -> Result<TensorHandle<T>>;
fn pad(
&mut self,
x: &TensorHandle<T>,
pad_width: &[(usize, usize)],
constant_value: T,
) -> Result<TensorHandle<T>>;
fn flip(
&mut self,
x: &TensorHandle<T>,
axes: &[Axis],
) -> Result<TensorHandle<T>>;
fn squeeze(
&mut self,
x: &TensorHandle<T>,
axes: Option<&[Axis]>,
) -> Result<TensorHandle<T>>;
fn unsqueeze(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
) -> Result<TensorHandle<T>>;
fn stack(
&mut self,
tensors: &[TensorHandle<T>],
axis: Axis,
) -> Result<TensorHandle<T>>;
fn repeat(
&mut self,
x: &TensorHandle<T>,
repeats: usize,
axis: Axis,
) -> Result<TensorHandle<T>>;
fn roll(
&mut self,
x: &TensorHandle<T>,
shift: isize,
axis: Axis,
) -> Result<TensorHandle<T>>;
fn argmax(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
) -> Result<TensorHandle<T>>;
fn argmin(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
) -> Result<TensorHandle<T>>;
}Expand description
Main executor trait for tensor operations
Required Methods§
Sourcefn einsum(
&mut self,
spec: &str,
inputs: &[TensorHandle<T>],
hints: &ExecHints,
) -> Result<TensorHandle<T>>
fn einsum( &mut self, spec: &str, inputs: &[TensorHandle<T>], hints: &ExecHints, ) -> Result<TensorHandle<T>>
Execute an einsum contraction
Sourcefn elem_op(
&mut self,
op: ElemOp,
x: &TensorHandle<T>,
) -> Result<TensorHandle<T>>
fn elem_op( &mut self, op: ElemOp, x: &TensorHandle<T>, ) -> Result<TensorHandle<T>>
Apply unary element-wise operation
Sourcefn binary_op(
&mut self,
op: BinaryOp,
x: &TensorHandle<T>,
y: &TensorHandle<T>,
) -> Result<TensorHandle<T>>
fn binary_op( &mut self, op: BinaryOp, x: &TensorHandle<T>, y: &TensorHandle<T>, ) -> Result<TensorHandle<T>>
Apply binary element-wise operation
Sourcefn reduce(
&mut self,
op: ReduceOp,
x: &TensorHandle<T>,
axes: &[Axis],
) -> Result<TensorHandle<T>>
fn reduce( &mut self, op: ReduceOp, x: &TensorHandle<T>, axes: &[Axis], ) -> Result<TensorHandle<T>>
Apply reduction operation
Sourcefn clip(
&mut self,
x: &TensorHandle<T>,
min_val: T,
max_val: T,
) -> Result<TensorHandle<T>>
fn clip( &mut self, x: &TensorHandle<T>, min_val: T, max_val: T, ) -> Result<TensorHandle<T>>
Clip tensor values to be within [min_val, max_val]
Sourcefn softmax(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
) -> Result<TensorHandle<T>>
fn softmax( &mut self, x: &TensorHandle<T>, axis: Axis, ) -> Result<TensorHandle<T>>
Softmax operation along specified axis Computes: exp(x) / sum(exp(x), axis) Uses numerically stable implementation: exp(x - max(x))
Sourcefn log_softmax(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
) -> Result<TensorHandle<T>>
fn log_softmax( &mut self, x: &TensorHandle<T>, axis: Axis, ) -> Result<TensorHandle<T>>
Log-softmax operation along specified axis (numerically stable) Computes: x - log(sum(exp(x), axis))
Sourcefn transpose(
&mut self,
x: &TensorHandle<T>,
axes: &[Axis],
) -> Result<TensorHandle<T>>
fn transpose( &mut self, x: &TensorHandle<T>, axes: &[Axis], ) -> Result<TensorHandle<T>>
Transpose/permute tensor axes Reorders the dimensions according to the provided axes permutation
Sourcefn reshape(
&mut self,
x: &TensorHandle<T>,
new_shape: &[usize],
) -> Result<TensorHandle<T>>
fn reshape( &mut self, x: &TensorHandle<T>, new_shape: &[usize], ) -> Result<TensorHandle<T>>
Reshape tensor to new shape Total number of elements must remain constant
Sourcefn concatenate(
&mut self,
tensors: &[TensorHandle<T>],
axis: Axis,
) -> Result<TensorHandle<T>>
fn concatenate( &mut self, tensors: &[TensorHandle<T>], axis: Axis, ) -> Result<TensorHandle<T>>
Concatenate tensors along specified axis
Sourcefn split(
&mut self,
x: &TensorHandle<T>,
num_splits: usize,
axis: Axis,
) -> Result<Vec<TensorHandle<T>>>
fn split( &mut self, x: &TensorHandle<T>, num_splits: usize, axis: Axis, ) -> Result<Vec<TensorHandle<T>>>
Split tensor along specified axis into chunks
Sourcefn layer_norm(&mut self, x: &TensorHandle<T>, eps: T) -> Result<TensorHandle<T>>
fn layer_norm(&mut self, x: &TensorHandle<T>, eps: T) -> Result<TensorHandle<T>>
Layer normalization (fused operation) Normalizes over the last dimension: (x - mean) / sqrt(var + eps)
Sourcefn batch_norm(&mut self, x: &TensorHandle<T>, eps: T) -> Result<TensorHandle<T>>
fn batch_norm(&mut self, x: &TensorHandle<T>, eps: T) -> Result<TensorHandle<T>>
Batch normalization (fused operation) Normalizes over the batch dimension (first axis)
Sourcefn where_op(
&mut self,
condition: &TensorHandle<T>,
x: &TensorHandle<T>,
y: &TensorHandle<T>,
) -> Result<TensorHandle<T>>
fn where_op( &mut self, condition: &TensorHandle<T>, x: &TensorHandle<T>, y: &TensorHandle<T>, ) -> Result<TensorHandle<T>>
Conditional selection: where(condition, x, y) Returns x where condition is true (>0), y otherwise All tensors must have the same shape
Sourcefn masked_select(
&mut self,
x: &TensorHandle<T>,
mask: &TensorHandle<T>,
) -> Result<TensorHandle<T>>
fn masked_select( &mut self, x: &TensorHandle<T>, mask: &TensorHandle<T>, ) -> Result<TensorHandle<T>>
Masked selection: select values from x where mask is true (>0) Returns a 1D tensor containing selected values
Sourcefn modulo(&mut self, x: &TensorHandle<T>, divisor: T) -> Result<TensorHandle<T>>
fn modulo(&mut self, x: &TensorHandle<T>, divisor: T) -> Result<TensorHandle<T>>
Element-wise modulo operation: x % divisor
Sourcefn remainder(
&mut self,
x: &TensorHandle<T>,
divisor: T,
) -> Result<TensorHandle<T>>
fn remainder( &mut self, x: &TensorHandle<T>, divisor: T, ) -> Result<TensorHandle<T>>
Element-wise remainder operation (same as modulo for positive numbers)
Sourcefn max_pool_1d(
&mut self,
x: &TensorHandle<T>,
kernel_size: usize,
stride: usize,
) -> Result<TensorHandle<T>>
fn max_pool_1d( &mut self, x: &TensorHandle<T>, kernel_size: usize, stride: usize, ) -> Result<TensorHandle<T>>
Max pooling operation (1D) Applies max pooling with specified kernel size and stride
Sourcefn avg_pool_1d(
&mut self,
x: &TensorHandle<T>,
kernel_size: usize,
stride: usize,
) -> Result<TensorHandle<T>>
fn avg_pool_1d( &mut self, x: &TensorHandle<T>, kernel_size: usize, stride: usize, ) -> Result<TensorHandle<T>>
Average pooling operation (1D) Applies average pooling with specified kernel size and stride
Sourcefn max_pool_2d(
&mut self,
x: &TensorHandle<T>,
kernel_size: (usize, usize),
stride: (usize, usize),
) -> Result<TensorHandle<T>>
fn max_pool_2d( &mut self, x: &TensorHandle<T>, kernel_size: (usize, usize), stride: (usize, usize), ) -> Result<TensorHandle<T>>
Max pooling operation (2D) Applies max pooling with specified kernel size and stride
Sourcefn avg_pool_2d(
&mut self,
x: &TensorHandle<T>,
kernel_size: (usize, usize),
stride: (usize, usize),
) -> Result<TensorHandle<T>>
fn avg_pool_2d( &mut self, x: &TensorHandle<T>, kernel_size: (usize, usize), stride: (usize, usize), ) -> Result<TensorHandle<T>>
Average pooling operation (2D) Applies average pooling with specified kernel size and stride
Sourcefn conv1d(
&mut self,
x: &TensorHandle<T>,
kernel: &TensorHandle<T>,
bias: Option<&TensorHandle<T>>,
stride: usize,
padding: (usize, usize),
) -> Result<TensorHandle<T>>
fn conv1d( &mut self, x: &TensorHandle<T>, kernel: &TensorHandle<T>, bias: Option<&TensorHandle<T>>, stride: usize, padding: (usize, usize), ) -> Result<TensorHandle<T>>
1D Convolution operation Applies 1D convolution: output[i] = sum_j(input[i+j] * kernel[j])
§Arguments
x- Input tensor of shape [batch, in_channels, length]kernel- Convolution kernel of shape [out_channels, in_channels, kernel_size]bias- Optional bias of shape [out_channels]stride- Stride for the convolutionpadding- Padding to apply (left, right)
Sourcefn conv2d(
&mut self,
x: &TensorHandle<T>,
kernel: &TensorHandle<T>,
bias: Option<&TensorHandle<T>>,
stride: (usize, usize),
padding: (usize, usize, usize, usize),
) -> Result<TensorHandle<T>>
fn conv2d( &mut self, x: &TensorHandle<T>, kernel: &TensorHandle<T>, bias: Option<&TensorHandle<T>>, stride: (usize, usize), padding: (usize, usize, usize, usize), ) -> Result<TensorHandle<T>>
2D Convolution operation Applies 2D convolution for image processing
§Arguments
x- Input tensor of shape [batch, in_channels, height, width]kernel- Convolution kernel of shape [out_channels, in_channels, kernel_h, kernel_w]bias- Optional bias of shape [out_channels]stride- Stride for the convolution (stride_h, stride_w)padding- Padding to apply (pad_h_top, pad_h_bottom, pad_w_left, pad_w_right)
Sourcefn conv3d(
&mut self,
x: &TensorHandle<T>,
kernel: &TensorHandle<T>,
bias: Option<&TensorHandle<T>>,
stride: (usize, usize, usize),
padding: (usize, usize, usize, usize, usize, usize),
) -> Result<TensorHandle<T>>
fn conv3d( &mut self, x: &TensorHandle<T>, kernel: &TensorHandle<T>, bias: Option<&TensorHandle<T>>, stride: (usize, usize, usize), padding: (usize, usize, usize, usize, usize, usize), ) -> Result<TensorHandle<T>>
3D Convolution operation Applies 3D convolution for volumetric data (video, medical imaging, etc.)
§Arguments
x- Input tensor of shape [batch, in_channels, depth, height, width]kernel- Convolution kernel of shape [out_channels, in_channels, kernel_d, kernel_h, kernel_w]bias- Optional bias of shape [out_channels]stride- Stride for the convolution (stride_d, stride_h, stride_w)padding- Padding to apply (pad_d_front, pad_d_back, pad_h_top, pad_h_bottom, pad_w_left, pad_w_right)
Sourcefn gather(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
indices: &TensorHandle<T>,
) -> Result<TensorHandle<T>>
fn gather( &mut self, x: &TensorHandle<T>, axis: Axis, indices: &TensorHandle<T>, ) -> Result<TensorHandle<T>>
Gather operation - selects values along an axis using indices
§Arguments
x- Input tensoraxis- Axis along which to gatherindices- Integer indices to gather (as Float tensor, will be cast to usize)
Sourcefn scatter(
&mut self,
shape: &[usize],
axis: Axis,
indices: &TensorHandle<T>,
values: &TensorHandle<T>,
) -> Result<TensorHandle<T>>
fn scatter( &mut self, shape: &[usize], axis: Axis, indices: &TensorHandle<T>, values: &TensorHandle<T>, ) -> Result<TensorHandle<T>>
Scatter operation - writes values to an output tensor using indices
§Arguments
shape- Shape of the output tensoraxis- Axis along which to scatterindices- Integer indices where to write (as Float tensor, will be cast to usize)values- Values to write at the indices
Sourcefn determinant(&mut self, x: &TensorHandle<T>) -> Result<TensorHandle<T>>
fn determinant(&mut self, x: &TensorHandle<T>) -> Result<TensorHandle<T>>
Sourcefn matrix_inverse(&mut self, x: &TensorHandle<T>) -> Result<TensorHandle<T>>
fn matrix_inverse(&mut self, x: &TensorHandle<T>) -> Result<TensorHandle<T>>
Sourcefn solve(
&mut self,
a: &TensorHandle<T>,
b: &TensorHandle<T>,
) -> Result<TensorHandle<T>>
fn solve( &mut self, a: &TensorHandle<T>, b: &TensorHandle<T>, ) -> Result<TensorHandle<T>>
Sourcefn advanced_gather(
&mut self,
x: &TensorHandle<T>,
axis: Axis,
indices: &TensorHandle<T>,
allow_negative: bool,
) -> Result<TensorHandle<T>>
fn advanced_gather( &mut self, x: &TensorHandle<T>, axis: Axis, indices: &TensorHandle<T>, allow_negative: bool, ) -> Result<TensorHandle<T>>
Advanced gather operation with negative indices support
Gathers values from x along the specified axis using indices.
§Arguments
x- Input tensoraxis- Axis along which to gatherindices- Integer indices (as Float tensor)allow_negative- Whether to allow Python-style negative indices
§Returns
Tensor with gathered values
Sourcefn advanced_scatter(
&mut self,
shape: &[usize],
axis: Axis,
indices: &TensorHandle<T>,
values: &TensorHandle<T>,
mode: ScatterMode,
) -> Result<TensorHandle<T>>
fn advanced_scatter( &mut self, shape: &[usize], axis: Axis, indices: &TensorHandle<T>, values: &TensorHandle<T>, mode: ScatterMode, ) -> Result<TensorHandle<T>>
Advanced scatter operation with accumulation modes
Scatters values into an output tensor along the specified axis using indices.
§Arguments
shape- Shape of the output tensoraxis- Axis along which to scatterindices- Integer indices where to writevalues- Values to scattermode- Scatter mode (Replace, Add, Max, Min)
§Returns
Output tensor with scattered values