einsum_frule

Function einsum_frule 

Source
pub fn einsum_frule<T: Scalar + HasAlgebra>(
    _subscripts: &str,
    _primals: &[&Tensor<T>],
    _tangents: &[Option<&Tensor<T>>],
) -> Result<Tensor<T>>
Expand description

Forward-mode rule (frule) for einsum without building a global tape.

Computes the pushforward (Jacobian-vector product) for an einsum operation. Inputs without tangent should use None.

Named after Julia’s ChainRules.jl convention. This API is intended for language interop and manual AD.

§Examples

use tenferro_einsum::einsum_frule;
use tenferro_tensor::{MemoryOrder, Tensor};
use tenferro_device::LogicalMemorySpace;

let col = MemoryOrder::ColumnMajor;
let mem = LogicalMemorySpace::MainMemory;
let a = Tensor::<f64>::ones(&[2, 3], mem, col);
let b = Tensor::<f64>::ones(&[3, 4], mem, col);
let da = Tensor::<f64>::ones(&[2, 3], mem, col);

let dc = einsum_frule("ij,jk->ik", &[&a, &b], &[Some(&da), None]).unwrap();