Skip to content

Conversation

@jlonge4
Copy link

@jlonge4 jlonge4 commented Jan 21, 2026

Issue #, if available:
N/A
Description of changes:

Adds support for core Einstein summation patterns and verification utilities.

Added

  • Core Patterns: Matrix multiplication, dot products, transposes, and outer products.

Verification:

  • nkipy_einsum.py
  • pytest kernels/einsum.py

Limitations

  • Trace: Logic added but blocked by missing iota_dimension support in the HLO backend.
  • Bilinear: Currently disabled and untested.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

jlonge4 and others added 18 commits January 17, 2026 22:30
Implements Einstein summation notation (einsum) for NKIPy, supporting:
- Matrix multiplication and batch operations (ij,jk->ik, bij,bjk->bik)
- Transpose and dimension permutation (ij->ji, ijk->kji)
- Reductions and trace operations (ij->, ii->)
- Outer products (i,j->ij)
- Broadcasting patterns (ij,j->ij)
- Complex tensor contractions (ijk,jkl->il)
- N-ary operations (i,ij,j->)

Implementation decomposes einsum patterns into HLO primitives:
- dot_general for contractions
- transpose for dimension reordering
- reduce for summations
- broadcast/multiply for outer products

Includes comprehensive tests covering all major einsum patterns
and examples demonstrating real-world usage including simplified
attention mechanisms.
This script tests various einsum operations using NumPy and NKIPy. It includes matrix multiplication, batch matrix multiplication, dot product, outer product, and more, verifying results against NumPy outputs.
@jlonge4 jlonge4 changed the title Feature/einsum feat: Add einsum ops Jan 21, 2026
@jlonge4 jlonge4 marked this pull request as ready for review January 21, 2026 22:28
@jlonge4 jlonge4 requested a review from a team January 21, 2026 22:28
@vgene vgene self-assigned this Jan 26, 2026
@vgene
Copy link
Contributor

vgene commented Jan 29, 2026

Thanks for submitting this PR! The einsum support is actually a long wanted feature!

We are reviewing this now and will have feedback by EOW.

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.

2 participants