Skip to content

TYP: einsum shape-typing - #32588

Merged
charris merged 1 commit into
numpy:mainfrom
jorenham:typing/einsum/shape-typing
Sep 11, 2026
Merged

charris merged 1 commit into
numpy:mainfrom
jorenham:typing/einsum/shape-typing

Conversation

@jorenham

Copy link
Copy Markdown
Member

At first I thought it would be impossible to shape-type numpy.einsum, because it's not possible to statically parse the einsum string using Python's type system. However, I had AI do a survey to see if there are certain einsum strings that are used often. And as it turns out, we can cover ~41% of the np.einsum calls using a subset of the 112 most frequently used einsum strings. These are then grouped by output rank, and for each group an overload is added. So this way, einsum is shape-typed for ~41% of the use cases :).


Researched and pair-programmed with AI.

@jorenham jorenham added this to the 2.6.0 Release milestone Sep 10, 2026
@charris
charris merged commit 63c2c32 into numpy:main Sep 11, 2026
16 checks passed
@charris

charris commented Sep 11, 2026

Copy link
Copy Markdown
Member

Thanks Joren. Interesting approach.

@anabelle2001

Copy link
Copy Markdown

cool! I'd never have thought of this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants