Skip to content

Fix hyperhemispherical uniform sampling#1918

Merged
FlorianPfaff merged 1 commit intomainfrom
codex/fix-hyperhemisphere-sampling
Apr 28, 2026
Merged

Fix hyperhemispherical uniform sampling#1918
FlorianPfaff merged 1 commit intomainfrom
codex/fix-hyperhemisphere-sampling

Conversation

@FlorianPfaff
Copy link
Copy Markdown
Owner

@FlorianPfaff FlorianPfaff commented Apr 28, 2026

Summary

  • Fix HyperhemisphericalUniformDistribution.sample to mirror each sampled point based on its own last coordinate.
  • Update the sampler comment to describe the hemisphere projection accurately.
  • Add regression tests for per-row mirroring and the single-sample equator case.

Root cause

HypersphericalUniformDistribution.sample(n) returns samples shaped (n, dim + 1), but the hyperhemisphere sampler checked s[-1, :], which reads the last sampled row instead of the last coordinate of every sample. For n == 1, that could force all coordinates positive instead of only projecting to the upper hemisphere.

Validation

  • $env:PYTHONPATH='src'; $env:PYRECEST_BACKEND='numpy'; python -m pytest -q tests/distributions/test_hyperhemispherical_uniform_distribution.py
  • $env:PYTHONPATH='src'; $env:PYRECEST_BACKEND='numpy'; python -m pytest -q tests/distributions/test_hyperhemispherical_uniform_distribution.py tests/distributions/test_hyperspherical_uniform_distribution.py
  • $env:PYTHONPATH='src'; $env:PYRECEST_BACKEND='pytorch'; python -m pytest -q tests/distributions/test_hyperhemispherical_uniform_distribution.py
  • $env:PYTHONPATH='src'; $env:PYRECEST_BACKEND='jax'; python -m pytest -q tests/distributions/test_hyperhemispherical_uniform_distribution.py
  • python -m black --check src/pyrecest/distributions/hypersphere_subset/hyperhemispherical_uniform_distribution.py tests/distributions/test_hyperhemispherical_uniform_distribution.py
  • python -m ruff check src/pyrecest/distributions/hypersphere_subset/hyperhemispherical_uniform_distribution.py tests/distributions/test_hyperhemispherical_uniform_distribution.py

@github-actions
Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 7.9s
✅ JSON prettier 2 0 0 0 0.32s
✅ JSON v8r 2 0 0 21.43s
✅ MARKDOWN markdownlint 21 0 0 0 1.06s
✅ MARKDOWN markdown-table-formatter 21 0 0 0 0.22s
✅ PYTHON bandit 429 0 0 5.94s
✅ PYTHON black 429 0 0 0 8.6s
✅ PYTHON flake8 429 0 0 3.22s
✅ PYTHON isort 429 2 0 0 0.77s
✅ PYTHON mypy 429 0 0 5.21s
✅ PYTHON pylint 429 0 0 122.4s
✅ PYTHON ruff 429 2 0 0 0.07s
✅ REPOSITORY checkov yes no no 13.09s
✅ REPOSITORY gitleaks yes no no 7.71s
✅ REPOSITORY git_diff yes no no 0.1s
✅ REPOSITORY secretlint yes no no 4.54s
✅ REPOSITORY syft yes no no 4.23s
✅ REPOSITORY trivy-sbom yes no no 5.68s
✅ REPOSITORY trufflehog yes no no 15.0s
✅ YAML prettier 5 0 0 0 0.47s
✅ YAML v8r 5 0 0 28.79s
✅ YAML yamllint 5 0 0 0.48s

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.4.0 --custom-flavor-setup --custom-flavor-linters PYTHON_PYLINT,PYTHON_BLACK,PYTHON_FLAKE8,PYTHON_ISORT,PYTHON_BANDIT,PYTHON_MYPY,PYTHON_RUFF,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_GITLEAKS,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 April 28, 2026 18:19
@FlorianPfaff FlorianPfaff enabled auto-merge (squash) April 28, 2026 18:19
@FlorianPfaff FlorianPfaff merged commit ddae39b into main Apr 28, 2026
19 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