Skip to main content

TensorDot

Trait TensorDot 

Source
pub trait TensorDot: TensorElementwise {
    // Required method
    fn dot_general(
        &mut self,
        lhs: &Tensor,
        rhs: &Tensor,
        config: &DotGeneralConfig,
    ) -> Result<Tensor>;

    // Provided methods
    fn dot_general_read_into(
        &mut self,
        lhs: TensorRead<'_>,
        rhs: TensorRead<'_>,
        config: &DotGeneralConfig,
        out: TensorWrite<'_>,
    ) -> Result<()> { ... }
    fn dot_general_read_into_accum(
        &mut self,
        lhs: TensorRead<'_>,
        rhs: TensorRead<'_>,
        config: &DotGeneralConfig,
        accumulation: DotGeneralAccumulation,
        out: TensorWrite<'_>,
    ) -> Result<()> { ... }
}
Expand description

Dot-general operations.

§Examples

use tenferro_tensor::TensorDot;

fn accepts_dot<B: TensorDot>(_backend: &mut B) {}

Required Methods§

Source

fn dot_general( &mut self, lhs: &Tensor, rhs: &Tensor, config: &DotGeneralConfig, ) -> Result<Tensor>

§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Provided Methods§

Source

fn dot_general_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, config: &DotGeneralConfig, out: TensorWrite<'_>, ) -> Result<()>

Overwrite caller-provided output with dot-general from read inputs.

This is the dot/GEMM spelling of _into: the previous output value is not read. Use TensorDot::dot_general_read_into_accum for explicit read-modify-write accumulation.

§Examples
use tenferro_tensor::{DotGeneralConfig, TensorDot, TensorRead, TensorWrite};

fn dot_into<B: TensorDot>(
    backend: &mut B,
    lhs: TensorRead<'_>,
    rhs: TensorRead<'_>,
    config: &DotGeneralConfig,
    out: TensorWrite<'_>,
) -> tenferro_tensor::Result<()> {
    backend.dot_general_read_into(lhs, rhs, config, out)
}
§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Source

fn dot_general_read_into_accum( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, config: &DotGeneralConfig, accumulation: DotGeneralAccumulation, out: TensorWrite<'_>, ) -> Result<()>

Apply scaled dot-general accumulation into caller-provided output.

This is explicitly read-modify-write when accumulation.beta is nonzero: out = alpha * dot_general(lhs, rhs) + beta * out.

§Examples
use tenferro_tensor::{
    DotGeneralAccumulation, DotGeneralConfig, TensorDot, TensorRead, TensorWrite,
};

fn dot_add_to<B: TensorDot>(
    backend: &mut B,
    lhs: TensorRead<'_>,
    rhs: TensorRead<'_>,
    config: &DotGeneralConfig,
    out: TensorWrite<'_>,
) -> tenferro_tensor::Result<()> {
    let accumulation = DotGeneralAccumulation::add_to(lhs.dtype())?;
    backend.dot_general_read_into_accum(lhs, rhs, config, accumulation, out)
}
§Errors

Returns crate::Error::Validation with a typed ValidationError source for invalid shapes, ranks, axes, dtypes, or output metadata. It returns crate::Error::BackendFailure or crate::Error::BackendSource when backend execution or storage access cannot provide the requested result.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§