Skip to main content

TypedTensorSessionOpsExt

Trait TypedTensorSessionOpsExt 

Source
pub trait TypedTensorSessionOpsExt<T: TensorScalar> {
Show 28 methods // Required methods fn add( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn mul( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn exp(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn reduce_sum( &self, axes: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn sub( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn div( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn rem( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn pow( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn maximum( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn minimum( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn neg(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn abs(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn sign(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn conj(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn log(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn expm1(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn log1p(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn sin(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn cos(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn tanh(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn sqrt(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn rsqrt(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>; fn compare( &self, rhs: &TypedTensor<T>, dir: CompareDir, session: &mut dyn BackendSession, ) -> Result<TypedTensor<bool>>; fn clamp( &self, lower: &TypedTensor<T>, upper: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn matmul( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn reshape( &self, shape: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn transpose( &self, perm: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>; fn broadcast_in_dim( &self, shape: &[usize], dims: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>;
}

Required Methods§

Source

fn add( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Elementwise addition with NumPy-style broadcasting inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
let b = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![3.0, 4.0]).unwrap();
let sum = backend.with_backend_session(|session| a.add(&b, session)).unwrap();
assert_eq!(sum.host_data().unwrap(), &[4.0, 6.0]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch for incompatible operands, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn mul( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Elementwise multiplication with NumPy-style broadcasting inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec_col_major(vec![1], vec![2.0]).unwrap();
let b = TypedTensor::<f64>::from_vec_col_major(vec![4], vec![3.0; 4]).unwrap();
let product = backend.with_backend_session(|session| a.mul(&b, session)).unwrap();
assert_eq!(product.host_data().unwrap(), &[6.0; 4]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch for incompatible operands, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn exp(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise exponential inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![0.0, 1.0]).unwrap();
let y = backend.with_backend_session(|session| x.exp(session)).unwrap();
let y = y.host_data().unwrap();
assert!((y[0] - 1.0).abs() < 1.0e-12);
assert!((y[1] - std::f64::consts::E).abs() < 1.0e-12);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn reduce_sum( &self, axes: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Sum over one or more axes inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2, 3], vec![1.0; 6]).unwrap();
let sums = backend.with_backend_session(|session| x.reduce_sum(&[1], session)).unwrap();
assert_eq!(sums.host_data().unwrap(), &[3.0, 3.0]);
§Errors

Returns [tenferro_tensor::Error::Validation] with AxisOutOfBounds for an axis outside the input rank or DuplicateAxis when axes repeats an axis, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn sub( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Elementwise subtraction with NumPy-style broadcasting inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![2.0, 4.0]).unwrap();
let b = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 8.0]).unwrap();
let y = backend.with_backend_session(|session| a.sub(&b, session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[1.0, -4.0]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch for incompatible operands, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn div( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Elementwise division with NumPy-style broadcasting inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![4.0, 8.0]).unwrap();
let b = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![2.0, 4.0]).unwrap();
let y = backend.with_backend_session(|session| a.div(&b, session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[2.0, 2.0]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch for incompatible shapes, a numerical [tenferro_tensor::Error::Extension] for a detected zero divisor, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn rem( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Elementwise remainder with NumPy-style broadcasting inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![5.0, 7.0]).unwrap();
let b = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![2.0, 4.0]).unwrap();
let y = backend.with_backend_session(|session| a.rem(&b, session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[1.0, 3.0]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch for incompatible shapes, a numerical [tenferro_tensor::Error::Extension] for a detected zero divisor, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn pow( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Elementwise power with NumPy-style broadcasting inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![2.0, 3.0]).unwrap();
let b = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![3.0, 2.0]).unwrap();
let y = backend.with_backend_session(|session| a.pow(&b, session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[8.0, 9.0]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch for incompatible shapes, a numerical [tenferro_tensor::Error::Extension] for a detected negative integer exponent, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn maximum( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Elementwise maximum with NumPy-style broadcasting inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![2.0, 4.0]).unwrap();
let b = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 8.0]).unwrap();
let y = backend.with_backend_session(|session| a.maximum(&b, session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[2.0, 8.0]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch for incompatible operands, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn minimum( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Elementwise minimum with NumPy-style broadcasting inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![2.0, 4.0]).unwrap();
let b = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 8.0]).unwrap();
let y = backend.with_backend_session(|session| a.minimum(&b, session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[1.0, 4.0]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch for incompatible operands, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn neg(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise negation inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, -2.0]).unwrap();
let y = backend.with_backend_session(|session| x.neg(session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[-1.0, 2.0]);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn abs(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise absolute value inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![-1.0, 2.0]).unwrap();
let y = backend.with_backend_session(|session| x.abs(session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[1.0, 2.0]);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn sign(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise sign inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, -2.0]).unwrap();
let y = backend.with_backend_session(|session| x.sign(session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[1.0, -1.0]);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn conj(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise complex conjugate inside a session.

For real dtypes the conjugate is the identity.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, -2.0]).unwrap();
let y = backend.with_backend_session(|session| x.conj(session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[1.0, -2.0]);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn log(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise natural logarithm inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, std::f64::consts::E]).unwrap();
let y = backend.with_backend_session(|session| x.log(session)).unwrap();
let y = y.host_data().unwrap();
assert!(y[0].abs() < 1.0e-12);
assert!((y[1] - 1.0).abs() < 1.0e-12);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn expm1(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise exp(x) - 1 inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![0.0, 1.0]).unwrap();
let y = backend.with_backend_session(|session| x.expm1(session)).unwrap();
let y = y.host_data().unwrap();
assert!(y[0].abs() < 1.0e-12);
assert!((y[1] - (std::f64::consts::E - 1.0)).abs() < 1.0e-12);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn log1p(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise log(1 + x) inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![0.0, std::f64::consts::E - 1.0]).unwrap();
let y = backend.with_backend_session(|session| x.log1p(session)).unwrap();
let y = y.host_data().unwrap();
assert!(y[0].abs() < 1.0e-12);
assert!((y[1] - 1.0).abs() < 1.0e-12);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn sin(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise sine inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![0.0, std::f64::consts::FRAC_PI_2]).unwrap();
let y = backend.with_backend_session(|session| x.sin(session)).unwrap();
let y = y.host_data().unwrap();
assert!(y[0].abs() < 1.0e-12);
assert!((y[1] - 1.0).abs() < 1.0e-12);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn cos(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise cosine inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![0.0, std::f64::consts::PI]).unwrap();
let y = backend.with_backend_session(|session| x.cos(session)).unwrap();
let y = y.host_data().unwrap();
assert!((y[0] - 1.0).abs() < 1.0e-12);
assert!((y[1] + 1.0).abs() < 1.0e-12);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn tanh(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise hyperbolic tangent inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![0.0, 1.0]).unwrap();
let y = backend.with_backend_session(|session| x.tanh(session)).unwrap();
let y = y.host_data().unwrap();
assert!(y[0].abs() < 1.0e-12);
assert!((y[1] - 0.7615941559557649).abs() < 1.0e-12);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn sqrt(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise square root inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![4.0, 9.0]).unwrap();
let y = backend.with_backend_session(|session| x.sqrt(session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[2.0, 3.0]);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn rsqrt(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>

Elementwise reciprocal square root inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![4.0, 1.0]).unwrap();
let y = backend.with_backend_session(|session| x.rsqrt(session)).unwrap();
let y = y.host_data().unwrap();
assert!((y[0] - 0.5).abs() < 1.0e-12);
assert!((y[1] - 1.0).abs() < 1.0e-12);
§Errors

Returns [tenferro_tensor::Error::Unsupported] for an unsupported dtype or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn compare( &self, rhs: &TypedTensor<T>, dir: CompareDir, session: &mut dyn BackendSession, ) -> Result<TypedTensor<bool>>

Elementwise comparison with NumPy-style broadcasting inside a session.

The result is a bool typed tensor.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{CompareDir, TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![2.0, 4.0]).unwrap();
let b = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 8.0]).unwrap();
let y = backend.with_backend_session(|session| a.compare(&b, CompareDir::Gt, session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[true, false]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch::IncompatibleShapes when broadcasting the operands is impossible, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn clamp( &self, lower: &TypedTensor<T>, upper: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Clamp values elementwise between lower and upper bounds inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![-2.0, 4.0]).unwrap();
let lower = TypedTensor::<f64>::from_vec_col_major(vec![], vec![0.0]).unwrap();
let upper = TypedTensor::<f64>::from_vec_col_major(vec![], vec![3.0]).unwrap();
let y = backend.with_backend_session(|session| x.clamp(&lower, &upper, session)).unwrap();
assert_eq!(y.host_data().unwrap(), &[0.0, 3.0]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch::IncompatibleShapes when a bound cannot broadcast to the input, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn matmul( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Rank-2 matrix multiplication inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec_col_major(vec![2, 3], vec![1.0; 6]).unwrap();
let b = TypedTensor::<f64>::from_vec_col_major(vec![3, 2], vec![1.0; 6]).unwrap();
let c = backend.with_backend_session(|session| a.matmul(&b, session)).unwrap();
assert_eq!(c.shape(), &[2, 2]);
§Errors

Returns [tenferro_tensor::Error::Validation] with RankMismatch when either operand is not rank two or ShapeMismatch::ContractedDimensions when the inner dimensions differ, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn reshape( &self, shape: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Reshape through the backend structural operation inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2, 3], vec![1.0; 6]).unwrap();
let y = backend.with_backend_session(|session| x.reshape(&[3, 2], session)).unwrap();
assert_eq!(y.shape(), &[3, 2]);
§Errors

Returns [tenferro_tensor::Error::Validation] with ShapeMismatch::ReshapeElementCount when the element counts differ, IntegerOverflow when shape arithmetic overflows, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn transpose( &self, perm: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Permute axes through the backend structural operation inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let x = TypedTensor::<f64>::from_vec_col_major(vec![2, 3], vec![1.0; 6]).unwrap();
let y = backend.with_backend_session(|session| x.transpose(&[1, 0], session)).unwrap();
assert_eq!(y.shape(), &[3, 2]);
§Errors

Returns [tenferro_tensor::Error::Validation] with InvalidPermutationLength when perm has the wrong length, AxisOutOfBounds for an invalid axis, or DuplicateAxis for a repeated axis, or [tenferro_tensor::Error::BackendSource] for a typed backend failure.

Source

fn broadcast_in_dim( &self, shape: &[usize], dims: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>

Broadcast into a larger shape inside a session.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_runtime::{TypedTensor, TypedTensorSessionOpsExt};
use tenferro_tensor::BackendSessionHost;

let mut backend = CpuBackend::new();
let row = TypedTensor::<f64>::from_vec_col_major(vec![3], vec![1.0, 2.0, 3.0]).unwrap();
let matrix = backend.with_backend_session(|session| row.broadcast_in_dim(&[2, 3], &[1], session)).unwrap();
assert_eq!(matrix.shape(), &[2, 3]);
§Errors

Returns [tenferro_tensor::Error::Validation] with RankMismatch when dims does not match the input rank, AxisOutOfBounds or DuplicateAxis for an invalid mapping, or ShapeMismatch::IncompatibleShapes when known dimensions cannot broadcast. [tenferro_tensor::Error::BackendSource] reports a typed backend failure.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§