Visitar URL original
Preserve empty tensor shapes in unfolding by ktz03 · Pull Request #710 · tensorly/tensorly · GitHub
Skip to content

Preserve empty tensor shapes in unfolding - #710

Open
ktz03 wants to merge 1 commit into
tensorly:mainfrom
ktz03:fix/empty-unfold-shapes-709-20261113
Open

ktz03 wants to merge 1 commit into
tensorly:mainfrom
ktz03:fix/empty-unfold-shapes-709-20261113

Conversation

@ktz03

@ktz03 ktz03 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #709.

Unfolding an empty tensor can fail when a retained dimension is zero: reshaping (0, 3, 4) to (0, -1) cannot infer the second dimension, although its original shape determines (0, 12). Empty skipped batch/channel dimensions cause the same problem in partial unfolding and vectorization.

Compute the collapsed dimension from the original, unskipped axes when a known static zero makes inference ambiguous. Keep the existing inference path for other inputs, including unknown dimensions, and preserve axis ordering. The partial vectorization alias inherits the repair; folding and full vectorization are unchanged.

Validation on Windows, Python 3.12.14 / NumPy 2.3.5 / SciPy 1.16.3:

  • Full NumPy suite with coverage: 1035 passed, 12 skipped, 1 existing non-strict XPASS, with 35 warnings from original tests. This includes all 34 added regression/control cases.
  • The same suite on the unmodified base produces 18 failures, all in new cases; all original test outcomes are unchanged.
  • PyTorch 2.8.0 CPU: the affected core module and independent empty/positive shape and value controls pass. These overlap the NumPy cases and are not additional full-suite tests.
  • Black 26.10.0 checks both changed files. A separate frozen-source review found no must-fix issues.

The unknown-dimension tests check shape dispatch; they do not execute a TensorFlow graph. Other backend/version/OS/device matrices, documentation and package builds were not run locally.

@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.89%. Comparing base (b2bf9ed) to head (c0efdf8).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #710      +/-   ##
==========================================
+ Coverage   92.81%   92.89%   +0.07%     
==========================================
  Files         133      133              
  Lines        8863     8947      +84     
==========================================
+ Hits         8226     8311      +85     
+ Misses        637      636       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

Empty tensors fail to unfold when a retained dimension is zero

1 participant