pub trait TensorOps: Send + Sync {
Show 15 methods
// Required methods
fn matmul(
&self,
a: &Arc<dyn TensorLike>,
b: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn add(
&self,
a: &Arc<dyn TensorLike>,
b: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn sub(
&self,
a: &Arc<dyn TensorLike>,
b: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn mul(
&self,
a: &Arc<dyn TensorLike>,
b: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn div(
&self,
a: &Arc<dyn TensorLike>,
b: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn softmax(
&self,
tensor: &Arc<dyn TensorLike>,
dim: i32,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn layer_norm(
&self,
input: &Arc<dyn TensorLike>,
weight: &Arc<dyn TensorLike>,
bias: Option<&Arc<dyn TensorLike>>,
eps: f32,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn rms_norm(
&self,
input: &Arc<dyn TensorLike>,
weight: &Arc<dyn TensorLike>,
eps: f32,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn relu(
&self,
tensor: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn gelu(
&self,
tensor: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn silu(
&self,
tensor: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn concat(
&self,
tensors: &[&Arc<dyn TensorLike>],
dim: usize,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn split(
&self,
tensor: &Arc<dyn TensorLike>,
sizes: &[usize],
dim: usize,
) -> Result<Vec<Arc<dyn TensorLike>>, FerrumError>;
fn transpose(
&self,
tensor: &Arc<dyn TensorLike>,
dim0: usize,
dim1: usize,
) -> Result<Arc<dyn TensorLike>, FerrumError>;
fn permute(
&self,
tensor: &Arc<dyn TensorLike>,
dims: &[usize],
) -> Result<Arc<dyn TensorLike>, FerrumError>;
}Expand description
Basic tensor operations
Required Methods§
Sourcefn matmul(
&self,
a: &Arc<dyn TensorLike>,
b: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn matmul( &self, a: &Arc<dyn TensorLike>, b: &Arc<dyn TensorLike>, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Matrix multiplication
Sourcefn add(
&self,
a: &Arc<dyn TensorLike>,
b: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn add( &self, a: &Arc<dyn TensorLike>, b: &Arc<dyn TensorLike>, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Element-wise addition
Sourcefn sub(
&self,
a: &Arc<dyn TensorLike>,
b: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn sub( &self, a: &Arc<dyn TensorLike>, b: &Arc<dyn TensorLike>, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Element-wise subtraction
Sourcefn mul(
&self,
a: &Arc<dyn TensorLike>,
b: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn mul( &self, a: &Arc<dyn TensorLike>, b: &Arc<dyn TensorLike>, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Element-wise multiplication
Sourcefn div(
&self,
a: &Arc<dyn TensorLike>,
b: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn div( &self, a: &Arc<dyn TensorLike>, b: &Arc<dyn TensorLike>, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Element-wise division
Sourcefn softmax(
&self,
tensor: &Arc<dyn TensorLike>,
dim: i32,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn softmax( &self, tensor: &Arc<dyn TensorLike>, dim: i32, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Apply softmax along specified dimension
Sourcefn layer_norm(
&self,
input: &Arc<dyn TensorLike>,
weight: &Arc<dyn TensorLike>,
bias: Option<&Arc<dyn TensorLike>>,
eps: f32,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn layer_norm( &self, input: &Arc<dyn TensorLike>, weight: &Arc<dyn TensorLike>, bias: Option<&Arc<dyn TensorLike>>, eps: f32, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Apply layer normalization
Sourcefn rms_norm(
&self,
input: &Arc<dyn TensorLike>,
weight: &Arc<dyn TensorLike>,
eps: f32,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn rms_norm( &self, input: &Arc<dyn TensorLike>, weight: &Arc<dyn TensorLike>, eps: f32, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Apply RMS normalization
Sourcefn relu(
&self,
tensor: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn relu( &self, tensor: &Arc<dyn TensorLike>, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Apply ReLU activation
Sourcefn gelu(
&self,
tensor: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn gelu( &self, tensor: &Arc<dyn TensorLike>, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Apply GELU activation
Sourcefn silu(
&self,
tensor: &Arc<dyn TensorLike>,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn silu( &self, tensor: &Arc<dyn TensorLike>, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Apply SiLU (Swish) activation
Sourcefn concat(
&self,
tensors: &[&Arc<dyn TensorLike>],
dim: usize,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn concat( &self, tensors: &[&Arc<dyn TensorLike>], dim: usize, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Concatenate tensors along specified dimension
Sourcefn split(
&self,
tensor: &Arc<dyn TensorLike>,
sizes: &[usize],
dim: usize,
) -> Result<Vec<Arc<dyn TensorLike>>, FerrumError>
fn split( &self, tensor: &Arc<dyn TensorLike>, sizes: &[usize], dim: usize, ) -> Result<Vec<Arc<dyn TensorLike>>, FerrumError>
Split tensor along specified dimension
Sourcefn transpose(
&self,
tensor: &Arc<dyn TensorLike>,
dim0: usize,
dim1: usize,
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn transpose( &self, tensor: &Arc<dyn TensorLike>, dim0: usize, dim1: usize, ) -> Result<Arc<dyn TensorLike>, FerrumError>
Transpose tensor dimensions
Sourcefn permute(
&self,
tensor: &Arc<dyn TensorLike>,
dims: &[usize],
) -> Result<Arc<dyn TensorLike>, FerrumError>
fn permute( &self, tensor: &Arc<dyn TensorLike>, dims: &[usize], ) -> Result<Arc<dyn TensorLike>, FerrumError>
Permute tensor dimensions