einsum-ndarray 0.1.0

Einstein summation for dynamically shaped ndarray arrays
Documentation
  • Coverage
  • 100%
    63 out of 63 items documented0 out of 13 items with examples
  • Size
  • Source code size: 276.25 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 710.83 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • hey-jj/einsum-ndarray
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hey-jj

einsum-ndarray

einsum-ndarray evaluates Einstein summation expressions on dynamically shaped ndarray arrays. It supports explicit and implicit outputs, repeated-axis diagonals, ellipsis broadcasting, scalar operands, and zero-length axes.

The default planner searches every contraction tree for expressions with up to eight operands. It uses a greedy path for larger expressions. Contracted pairs run through ndarray matrix multiplication. Pairwise products without a contracted label use broadcast multiplication.

Example

use einsum_ndarray::{einsum, EinsumPlan};
use ndarray::array;

let left = array![[1.0, 2.0], [3.0, 4.0]];
let right = array![[5.0, 6.0], [7.0, 8.0]];
let operands = [left.view().into_dyn(), right.view().into_dyn()];

let result = einsum("ij,jk->ik", &operands)?;
assert_eq!(result, array![[19.0, 22.0], [43.0, 50.0]].into_dyn());

let shapes: [&[usize]; 2] = [left.shape(), right.shape()];
let plan = EinsumPlan::new("ij,jk->ik", &shapes)?;
assert_eq!(plan.output_shape(), &[2, 2]);

# Ok::<(), einsum_ndarray::EinsumError>(())

Build an EinsumPlan once when the expression and operand shapes stay fixed. Each execution checks the shapes before it allocates a result.

Errors

Parsing, rank checks, broadcasting checks, path validation, and shape checks return EinsumError. Error variants carry the operand, label, position, or shape data needed to diagnose the input.

Integer additions and multiplications wrap at the type boundary in every build profile. Floating-point and complex values use their ndarray arithmetic.

Matrix multiplication backends

The default feature set uses ndarray's pure-Rust matrix multiplication. Enable blas when another dependency in the final binary selects and links a compatible BLAS provider. The openblas feature enables the same pass-through for builds that select OpenBLAS in their application dependency graph.

Compiler support

The crate supports Rust 1.75 and later.

License

MIT