TensorKernel

Trait TensorKernel 

Source
pub trait TensorKernel: Clone {
    type Index: IndexLike;

    // Required methods
    fn contract(tensors: &[&Self], allowed: AllowedPairs<'_>) -> Result<Self>;
    fn factorize(
        &self,
        left_inds: &[Self::Index],
        options: &FactorizeOptions,
    ) -> Result<FactorizeResult<Self>>;
    fn axpby(&self, a: DynScalar, other: &Self, b: DynScalar) -> Result<Self>;
    fn scale(&self, a: DynScalar) -> Result<Self>;
    fn inner_product(&self, other: &Self) -> Result<DynScalar>;
}
Expand description

Numeric tensor-kernel boundary for contraction/factorization operations.

§Examples

use ad_tensors_rs::{AllowedPairs, DynScalar, FactorizeOptions, FactorizeResult, Result, TensorKernel};

#[derive(Clone)]
struct DummyKernel;

impl TensorKernel for DummyKernel {
    type Index = u8;

    fn contract(_tensors: &[&Self], _allowed: AllowedPairs<'_>) -> Result<Self> {
        Ok(Self)
    }

    fn factorize(
        &self,
        _left_inds: &[Self::Index],
        _options: &FactorizeOptions,
    ) -> Result<FactorizeResult<Self>> {
        Ok(FactorizeResult { left: Self, right: Self })
    }

    fn axpby(&self, _a: DynScalar, _other: &Self, _b: DynScalar) -> Result<Self> {
        Ok(Self)
    }

    fn scale(&self, _a: DynScalar) -> Result<Self> {
        Ok(Self)
    }

    fn inner_product(&self, _other: &Self) -> Result<DynScalar> {
        Ok(DynScalar::F64(0.0))
    }
}

let x = DummyKernel;
let _ = x.scale(DynScalar::F64(2.0)).unwrap();

Required Associated Types§

Source

type Index: IndexLike

Index label type used by this kernel.

Required Methods§

Source

fn contract(tensors: &[&Self], allowed: AllowedPairs<'_>) -> Result<Self>

Contract a set of tensors under index-pair constraints.

Source

fn factorize( &self, left_inds: &[Self::Index], options: &FactorizeOptions, ) -> Result<FactorizeResult<Self>>

Factorize a tensor into two factors.

Source

fn axpby(&self, a: DynScalar, other: &Self, b: DynScalar) -> Result<Self>

Affine combination a * self + b * other.

Source

fn scale(&self, a: DynScalar) -> Result<Self>

Scalar multiply.

Source

fn inner_product(&self, other: &Self) -> Result<DynScalar>

Inner product result.

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§