tensorly icon indicating copy to clipboard operation
tensorly copied to clipboard

Einsum Kronecker product generates invalid labels with fourteen matrices

Open austinchennn opened this issue 3 weeks ago • 0 comments

Problem

With the einsum tensor-algebra backend, tl.tenalg.kronecker raises an invalid-subscript error for14matrices, even if the final result is only2x4. The same public call succeeds with the core implementation.

import tensorly as tl

matrices = [tl.tensor([[1.]]) for _ in range(14)]
matrices[0] = tl.tensor([[1., 2.], [3., 4.]])
matrices[-1] = tl.tensor([[.5, 1.5]])
with tl.tenalg.backend_context("einsum"):
    print(tl.tenalg.kronecker(matrices))

Currentmain6a0c16d raises ValueError: invalid subscript '{' in einstein sum subscripts string, subscripts must be letters. Expected, as returned by core:

[[0.5 1.5 1.0 3.0]
 [1.5 4.5 2.0 6.0]]

The equation builder starts at ASCII a and continues past z into punctuation. Use the standard lowercase/uppercase ASCII letter pool for its labels. This is a label-generation repair, not removal of the numerical backend's dimension or total einsum-symbol limits.

One compact regression with a literal expected result fails on the original einsum implementation (1failed/1passing control). Patched tensor-algebra suite:360passed in each NumPy/PyTorchCPU × core/einsum run,16warnings per run. BlackPython check and diff check pass; notebook formatting was skipped by Black because Jupyter extras are not installed. Fullrepo,documentation,GPU and remaining numerical backends were not run.

No overlapping kronecker/einsum or operand-count issue/PR found in all-state searches. AI assistance:Codex investigated,implemented and ran the local checks with the account owner's authorization. Scope feedback is welcome.

Implementation and acceptance

Implementation PR: #712.

  • [x] Reproduce the 14-factor failure on the original einsum implementation, with a passing core control.
  • [x] Use valid lowercase/uppercase ASCII labels and retain the existing contraction and output order.
  • [x] Verify the literal expected result and run all 360 tensor-algebra tests in each NumPy/PyTorch CPU × core/einsum combination.
  • [ ] Obtain maintainer approval to run upstream workflows and complete required CI.
  • [ ] Obtain review and merge. The PR is submitted; this issue is not yet merged or closed.

austinchennn avatar Nov 13 '26 16:11 austinchennn