Skip to content

BUG: validate contraction axes in tensordot (#30521)#30700

Merged
charris merged 1 commit intonumpy:maintenance/2.4.xfrom
charris:backport-30534
Jan 21, 2026
Merged

BUG: validate contraction axes in tensordot (#30521)#30700
charris merged 1 commit intonumpy:maintenance/2.4.xfrom
charris:backport-30534

Conversation

@charris
Copy link
Member

@charris charris commented Jan 21, 2026

Backport of #30534.

tensordot performs a tensor contraction where each axis corresponds to a distinct summation index. Duplicate contraction axes (e.g. axes=([1, 1], [0, 0])) are mathematically invalid but currently fail later during an internal transpose, raising ValueError: axes don't match array. This PR adds early validation to reject duplicate axes explicitly, aligning the behavior with the definition of tensor contraction and other NumPy axis-handling APIs.

Current behavior:
Supplying duplicate contraction axes (e.g. axes=([1, 1], [0, 0])) causes tensordot to fail later during an internal transpose, raising ValueError: axes don't match array.

Expected behavior:
Duplicate contraction axes should be rejected explicitly, since tensor contraction requires distinct summation axes, and a clear input-validation error should be raised before any internal reshaping or transposition.

@charris charris added this to the 2.4.2 release milestone Jan 21, 2026
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Jan 21, 2026
@charris charris merged commit ea8a596 into numpy:maintenance/2.4.x Jan 21, 2026
76 of 77 checks passed
@charris charris deleted the backport-30534 branch January 21, 2026 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants