pub trait TensorOpsExt {
Show 30 methods
// Required methods
fn convert<B: TensorBackend>(
&self,
to: DType,
backend: &mut B,
) -> Result<Tensor>;
fn cast<B: TensorBackend>(
&self,
to: DType,
backend: &mut B,
) -> Result<Tensor>;
fn add<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn sub<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn mul<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn div<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn rem<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn pow<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn maximum<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn minimum<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn neg<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn abs<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn sign<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn conj<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn exp<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn log<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn sin<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn cos<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn tanh<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn sqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn rsqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn expm1<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn log1p<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>;
fn compare<B: TensorBackend>(
&self,
rhs: &Tensor,
dir: CompareDir,
backend: &mut B,
) -> Result<Tensor>;
fn where_select<B: TensorBackend>(
&self,
on_true: &Tensor,
on_false: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn clamp<B: TensorBackend>(
&self,
lower: &Tensor,
upper: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn matmul<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>;
fn reshape<B: TensorBackend>(
&self,
shape: &[usize],
backend: &mut B,
) -> Result<Tensor>;
fn transpose<B: TensorBackend>(
&self,
perm: &[usize],
backend: &mut B,
) -> Result<Tensor>;
fn reduce_sum<B: TensorBackend>(
&self,
axes: &[usize],
backend: &mut B,
) -> Result<Tensor>;
}Expand description
Backend-explicit concrete tensor operations.
Tensor is owned by tenferro-tensor, so tenferro-runtime exposes these
operations as a crate-root extension trait rather than as inherent methods.
§Public API rationale
This trait is intentionally public: it is the supported non-AD concrete
tensor operation surface for downstream users who want to run operations on
an explicit backend. The old public module/free-function surface was
removed; the private tensor module now contains implementation helpers
only and must not be treated as a compatibility API.
§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{Tensor, TensorOpsExt};
let mut backend = CpuBackend::new();
let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64; 4]).unwrap();
let b = Tensor::from_vec_col_major(vec![2, 2], vec![2.0_f64; 4]).unwrap();
let c = a.matmul(&b, &mut backend).unwrap();
assert_eq!(c.shape(), &[2, 2]);Required Methods§
Sourcefn convert<B: TensorBackend>(
&self,
to: DType,
backend: &mut B,
) -> Result<Tensor>
fn convert<B: TensorBackend>( &self, to: DType, backend: &mut B, ) -> Result<Tensor>
Convert to a different dtype using the checked conversion lattice.
Sourcefn cast<B: TensorBackend>(&self, to: DType, backend: &mut B) -> Result<Tensor>
fn cast<B: TensorBackend>(&self, to: DType, backend: &mut B) -> Result<Tensor>
Cast to a different dtype using explicit lossy projection.
Sourcefn add<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
fn add<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
Elementwise addition with NumPy-style broadcasting.
Sourcefn sub<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
fn sub<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
Elementwise subtraction with NumPy-style broadcasting.
Sourcefn mul<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
fn mul<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
Elementwise multiplication with NumPy-style broadcasting.
Sourcefn div<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
fn div<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
Elementwise division with NumPy-style broadcasting.
Sourcefn rem<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
fn rem<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
Elementwise remainder with NumPy-style broadcasting.
Sourcefn pow<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
fn pow<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>
Elementwise power with NumPy-style broadcasting.
Sourcefn maximum<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>
fn maximum<B: TensorBackend>( &self, rhs: &Tensor, backend: &mut B, ) -> Result<Tensor>
Elementwise maximum with NumPy-style broadcasting.
Sourcefn minimum<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>
fn minimum<B: TensorBackend>( &self, rhs: &Tensor, backend: &mut B, ) -> Result<Tensor>
Elementwise minimum with NumPy-style broadcasting.
Sourcefn neg<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn neg<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise negation.
Sourcefn abs<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn abs<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise absolute value.
Sourcefn sign<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn sign<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise sign.
Sourcefn conj<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn conj<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise complex conjugate.
Sourcefn exp<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn exp<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise exponential.
Sourcefn log<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn log<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise natural logarithm.
Sourcefn sin<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn sin<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise sine.
Sourcefn cos<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn cos<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise cosine.
Sourcefn tanh<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn tanh<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise hyperbolic tangent.
Sourcefn sqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn sqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise square root.
Sourcefn rsqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn rsqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise reciprocal square root.
Sourcefn expm1<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn expm1<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise exp(x) - 1.
Sourcefn log1p<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn log1p<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise log(1 + x).
Sourcefn compare<B: TensorBackend>(
&self,
rhs: &Tensor,
dir: CompareDir,
backend: &mut B,
) -> Result<Tensor>
fn compare<B: TensorBackend>( &self, rhs: &Tensor, dir: CompareDir, backend: &mut B, ) -> Result<Tensor>
Elementwise comparison with NumPy-style broadcasting.
Sourcefn where_select<B: TensorBackend>(
&self,
on_true: &Tensor,
on_false: &Tensor,
backend: &mut B,
) -> Result<Tensor>
fn where_select<B: TensorBackend>( &self, on_true: &Tensor, on_false: &Tensor, backend: &mut B, ) -> Result<Tensor>
Select values from on_true or on_false using this tensor as condition.
Sourcefn clamp<B: TensorBackend>(
&self,
lower: &Tensor,
upper: &Tensor,
backend: &mut B,
) -> Result<Tensor>
fn clamp<B: TensorBackend>( &self, lower: &Tensor, upper: &Tensor, backend: &mut B, ) -> Result<Tensor>
Clamp values elementwise between lower and upper bounds.
Sourcefn matmul<B: TensorBackend>(
&self,
rhs: &Tensor,
backend: &mut B,
) -> Result<Tensor>
fn matmul<B: TensorBackend>( &self, rhs: &Tensor, backend: &mut B, ) -> Result<Tensor>
Rank-2 matrix multiplication.
Sourcefn reshape<B: TensorBackend>(
&self,
shape: &[usize],
backend: &mut B,
) -> Result<Tensor>
fn reshape<B: TensorBackend>( &self, shape: &[usize], backend: &mut B, ) -> Result<Tensor>
Reshape without changing element order.
Sourcefn transpose<B: TensorBackend>(
&self,
perm: &[usize],
backend: &mut B,
) -> Result<Tensor>
fn transpose<B: TensorBackend>( &self, perm: &[usize], backend: &mut B, ) -> Result<Tensor>
Permute axes.
Sourcefn reduce_sum<B: TensorBackend>(
&self,
axes: &[usize],
backend: &mut B,
) -> Result<Tensor>
fn reduce_sum<B: TensorBackend>( &self, axes: &[usize], backend: &mut B, ) -> Result<Tensor>
Sum over one or more axes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.