Skip to content

Validate hypertoroidal Fourier coefficient counts - #5243

Open
FlorianPfaff wants to merge 2 commits into
mainfrom
agent/validate-hypertoroidal-fourier-coefficients
Open

Validate hypertoroidal Fourier coefficient counts#5243
FlorianPfaff wants to merge 2 commits into
mainfrom
agent/validate-hypertoroidal-fourier-coefficients

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Bug

HypertoroidalFourierFilter.__init__(...) normalized n_coefficients with an isinstance(..., int) special case followed by tuple(int(n) for n in n_coefficients).

That produced several inconsistent or silent reinterpretations:

  • a tuple such as (11.5,) was silently truncated to (11,);
  • True was accepted as a one-coefficient filter because bool is an int subclass;
  • the string "11" was interpreted as a two-dimensional (1, 1) coefficient shape;
  • an empty tuple reached scalar allocation and could be reinterpreted downstream as a one-dimensional coefficient array;
  • a valid NumPy integer scalar such as np.int64(11) failed because it was neither a Python int nor iterable.

These behaviors violate the documented integer coefficient-count contract and can construct a filter with a different dimensionality or resolution than the caller requested.

Fix

Reuse the established _normalize_coefficient_shape(...) contract from HypertoroidalFourierDistribution with require_odd=True before allocating the initial coefficient tensor.

The filter now:

  • accepts Python and NumPy integer scalars;
  • requires a nonempty sequence of positive integers;
  • rejects Boolean, textual, fractional, zero, negative, and even coefficient counts;
  • reports errors against the n_coefficients parameter instead of relying on backend allocation or later distribution validation.

Regression coverage

Add focused constructor tests covering:

  • acceptance of np.int64(11);
  • rejection of values previously reinterpreted silently;
  • rejection of nonpositive and even coefficient counts in scalar and multidimensional forms.

Validation

  • reconstructed the pre-patch source and verified its Git blob SHA exactly matches a198df740e7f05765f29e9753db2bf0fa61bb21a;
  • syntax-compiled the modified implementation and regression module;
  • ran an isolated contract harness reproducing the old reinterpretations and verifying the shared validator's corrected behavior;
  • branch comparison: 2 commits ahead and 0 behind main;
  • final diff is limited to 6 additions / 3 deletions in the constructor and one 39-line regression module.

GitHub Actions is authoritative for the full backend, lint, packaging, documentation, and integration matrix.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 24.44s
✅ JSON prettier 7 0 0 0 0.97s
✅ JSON v8r 7 0 0 4.62s
✅ MARKDOWN markdownlint 68 0 0 0 1.82s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 1.14s
✅ PYTHON black 1866 87 0 0 93.46s
✅ PYTHON isort 1866 140 0 0 2.36s
✅ REPOSITORY betterleaks yes no no 2.79s
✅ REPOSITORY checkov yes no no 53.72s
✅ REPOSITORY gitleaks yes no no 17.38s
✅ REPOSITORY git_diff yes no no 0.19s
✅ REPOSITORY secretlint yes no no 84.06s
✅ REPOSITORY syft yes no no 5.99s
✅ REPOSITORY trivy-sbom yes no no 6.11s
✅ REPOSITORY trufflehog yes no no 32.21s
✅ YAML prettier 11 0 0 0 0.68s
✅ YAML v8r 11 0 0 11.54s
✅ YAML yamllint 11 0 0 0.54s

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 7, 2026 17:57
@FlorianPfaff
FlorianPfaff enabled auto-merge (squash) August 7, 2026 17:58
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