Skip to content

Normalize positional PyTorch FFT dimensions - #4973

Merged
FlorianPfaff merged 2 commits into
mainfrom
agent/fix-pytorch-fft-positional-dims
Aug 3, 2026
Merged

Normalize positional PyTorch FFT dimensions#4973
FlorianPfaff merged 2 commits into
mainfrom
agent/fix-pytorch-fft-positional-dims

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Bug

The PyTorch FFT compatibility wrappers normalized NumPy-style dimension values only when dim, axis, or axes was supplied by keyword. When the equivalent argument was passed positionally, the wrapper forwarded NumPy scalar or array values directly to Torch.

This made otherwise valid calls fail, for example:

  • rfft(values, None, np.array(0))
  • fftshift(values, np.array([0]))
  • fftn(values, None, np.array([0]))

Torch rejects those positional NumPy values even though the corresponding NumPy FFT calls accept them. Positional empty dimensions also bypassed the wrapper's existing no-op handling for FFT shifts.

Fix

  • record the positional index of the Torch dim argument for each wrapper;
  • normalize positional and keyword dimensions through the same scalar/sequence helpers;
  • inspect the effective positional-or-keyword dimension when applying empty-axis no-op behavior;
  • preserve shape normalization, aliases, Boolean-length validation, and ordinary Python integer behavior.

The fix covers rfft, irfft, fftshift, ifftshift, fftn, and ifftn.

Validation

  • reproduced the pre-fix Torch TypeError for positional NumPy scalar and array dimensions;
  • isolated patched harness passed for all six wrappers against NumPy reference results;
  • covered positional np.array(0), np.int64(0), NumPy axis arrays, sequences containing NumPy scalar arrays, and empty positional axes;
  • syntax compilation passed for the modified wrapper module;
  • branch is 2 commits ahead and 0 behind main, with exactly two changed files.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 25.61s
✅ JSON prettier 7 0 0 0 0.66s
✅ JSON v8r 7 0 0 6.54s
✅ MARKDOWN markdownlint 68 0 0 0 1.4s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.55s
✅ PYTHON black 1810 56 0 0 85.68s
✅ PYTHON isort 1810 88 0 0 2.23s
✅ REPOSITORY betterleaks yes no no 2.86s
✅ REPOSITORY checkov yes no no 48.96s
✅ REPOSITORY gitleaks yes no no 15.33s
✅ REPOSITORY git_diff yes no no 0.22s
✅ REPOSITORY secretlint yes no no 71.14s
✅ REPOSITORY syft yes no no 5.89s
✅ REPOSITORY trivy-sbom yes no no 5.79s
✅ REPOSITORY trufflehog yes no no 30.02s
✅ YAML prettier 11 0 0 0 0.6s
✅ YAML v8r 11 0 0 11.48s
✅ YAML yamllint 11 0 0 0.36s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@9.6.0 --custom-flavor-setup --custom-flavor-linters PYTHON_BLACK,PYTHON_ISORT,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_GITLEAKS,REPOSITORY_BETTERLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@FlorianPfaff
FlorianPfaff marked this pull request as ready for review August 3, 2026 08:44
@FlorianPfaff
FlorianPfaff merged commit b09d778 into main Aug 3, 2026
26 checks passed
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.

1 participant