Skip to main content

TensorOpsExt

Trait TensorOpsExt 

Source
pub trait TensorOpsExt {
Show 29 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 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§

Source

fn convert<B: TensorBackend>( &self, to: DType, backend: &mut B, ) -> Result<Tensor>

Convert to a different dtype using the checked conversion lattice.

Source

fn cast<B: TensorBackend>(&self, to: DType, backend: &mut B) -> Result<Tensor>

Cast to a different dtype using explicit lossy projection.

Source

fn add<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>

Elementwise addition with NumPy-style broadcasting.

Source

fn sub<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>

Elementwise subtraction with NumPy-style broadcasting.

Source

fn mul<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>

Elementwise multiplication with NumPy-style broadcasting.

Source

fn div<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>

Elementwise division with NumPy-style broadcasting.

Source

fn pow<B: TensorBackend>(&self, rhs: &Tensor, backend: &mut B) -> Result<Tensor>

Elementwise power with NumPy-style broadcasting.

Source

fn maximum<B: TensorBackend>( &self, rhs: &Tensor, backend: &mut B, ) -> Result<Tensor>

Elementwise maximum with NumPy-style broadcasting.

Source

fn minimum<B: TensorBackend>( &self, rhs: &Tensor, backend: &mut B, ) -> Result<Tensor>

Elementwise minimum with NumPy-style broadcasting.

Source

fn neg<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise negation.

Source

fn abs<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise absolute value.

Source

fn sign<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise sign.

Source

fn conj<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise complex conjugate.

Source

fn exp<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise exponential.

Source

fn log<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise natural logarithm.

Source

fn sin<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise sine.

Source

fn cos<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise cosine.

Source

fn tanh<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise hyperbolic tangent.

Source

fn sqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise square root.

Source

fn rsqrt<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise reciprocal square root.

Source

fn expm1<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise exp(x) - 1.

Source

fn log1p<B: TensorBackend>(&self, backend: &mut B) -> Result<Tensor>

Elementwise log(1 + x).

Source

fn compare<B: TensorBackend>( &self, rhs: &Tensor, dir: CompareDir, backend: &mut B, ) -> Result<Tensor>

Elementwise comparison with NumPy-style broadcasting.

Source

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.

Source

fn clamp<B: TensorBackend>( &self, lower: &Tensor, upper: &Tensor, backend: &mut B, ) -> Result<Tensor>

Clamp values elementwise between lower and upper bounds.

Source

fn matmul<B: TensorBackend>( &self, rhs: &Tensor, backend: &mut B, ) -> Result<Tensor>

Rank-2 matrix multiplication.

Source

fn reshape<B: TensorBackend>( &self, shape: &[usize], backend: &mut B, ) -> Result<Tensor>

Reshape without changing element order.

Source

fn transpose<B: TensorBackend>( &self, perm: &[usize], backend: &mut B, ) -> Result<Tensor>

Permute axes.

Source

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.

Implementors§