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.
§Errors
Returns tenferro_tensor::Error::UnsupportedDTypeConversion when the
conversion is outside the checked lattice,
tenferro_tensor::Error::Validation with DTypeMismatch or
InvalidArgument for invalid tensor metadata, or
tenferro_tensor::Error::BackendSource when the backend reports a
typed failure.
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.
§Errors
Returns tenferro_tensor::Error::UnsupportedDTypeConversion when the
requested cast is unsupported, tenferro_tensor::Error::Validation
with DTypeMismatch or InvalidArgument for invalid tensor metadata,
or tenferro_tensor::Error::BackendSource for a typed backend
failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with a
ShapeMismatch or
DTypeMismatch payload when operands are incompatible, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with
ShapeMismatch or DTypeMismatch for incompatible operands, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with
ShapeMismatch or DTypeMismatch for incompatible operands, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with ShapeMismatch or
DTypeMismatch for shape/dtype incompatibility,
tenferro_tensor::Error::Extension with a numerical classification
for a detected zero divisor, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with ShapeMismatch or
DTypeMismatch for shape/dtype incompatibility, a numerical
tenferro_tensor::Error::Extension for a detected zero divisor, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with ShapeMismatch or
DTypeMismatch for incompatible metadata, a numerical
tenferro_tensor::Error::Extension for a detected negative integer
exponent, or tenferro_tensor::Error::BackendSource for a typed
backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with
ShapeMismatch or DTypeMismatch for incompatible operands, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with
ShapeMismatch or DTypeMismatch for incompatible operands, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
Sourcefn neg<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn neg<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise negation.
§Errors
Returns tenferro_tensor::Error::Unsupported when the dtype is not
supported by the operation, or tenferro_tensor::Error::BackendSource
for a typed backend failure.
Sourcefn abs<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn abs<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise absolute value.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn sign<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn sign<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise sign.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn conj<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn conj<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise complex conjugate.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn exp<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn exp<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise exponential.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn log<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn log<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise natural logarithm.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn sin<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn sin<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise sine.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn cos<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn cos<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise cosine.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn tanh<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn tanh<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise hyperbolic tangent.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn sqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn sqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise square root.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn rsqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn rsqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise reciprocal square root.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn expm1<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn expm1<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise exp(x) - 1.
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
Sourcefn log1p<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
fn log1p<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>
Elementwise log(1 + x).
§Errors
Returns tenferro_tensor::Error::Unsupported for an unsupported
dtype or tenferro_tensor::Error::BackendSource for a typed backend
failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with ShapeMismatch or
DTypeMismatch for incompatible shape/dtype metadata, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with ShapeMismatch or
DTypeMismatch when the condition and branches are incompatible, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with ShapeMismatch or
DTypeMismatch when bounds are incompatible with the input, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with RankMismatch,
ShapeMismatch, or DTypeMismatch for incompatible matrices, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with
ShapeMismatch, RankMismatch, or InvalidArgument when element
counts or ranks are invalid, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with
InvalidPermutationLength, AxisOutOfBounds, or DuplicateAxis for
an invalid permutation, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.
§Errors
Returns tenferro_tensor::Error::Validation with AxisOutOfBounds
or DuplicateAxis for invalid reductions, or
tenferro_tensor::Error::BackendSource for a typed backend failure.
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.