Skip to content

Add einsum output-shape inference - #112

Open
MesTTo wants to merge 2 commits into
trueagi-io:mainfrom
MesTTo:pr/linalg-einsum-infer
Open

Add einsum output-shape inference#112
MesTTo wants to merge 2 commits into
trueagi-io:mainfrom
MesTTo:pr/linalg-einsum-infer

Conversation

@MesTTo

@MesTTo MesTTo commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Adds einsum::infer_output_shapes, which computes the output shapes of an explicit lhs->rhs einsum spec from the input shapes, without running the contraction.

It follows the same contract as einsum: every input subscript labels one input axis, repeated labels must agree on their dimension, and each output subscript must be bound by some input. It returns InvalidSpec on an input-arity mismatch or a dimension mismatch, reusing the existing error type.

Purely additive (no changes to existing code or formatting).

The tests cover both paths:

  • output shape of ab,bc->ac over [2,3] and [3,4] is [2,4]
  • a conflicting shared dimension reports InvalidSpec::DimensionMismatch

Validation:

  • CARGO_HOME=/home/user/Dev/.cargo-isolated RUSTFLAGS='-C target-cpu=native -Awarnings' cargo +nightly test -p linalg infer_output_shapes
  • git diff --check

…shapes

The dims-resolution loop in infer_output_shapes was a near-verbatim copy of the
one in compile, differing only in reading dimensions from a shape slice instead
of NDIndex. Factor it into resolve_slot_dims, parameterized over how an input's
rank and dimensions are read, and call it from both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant