Skip to content

fix: preserve dtype precision in twcrps ensemble bounds - #182

Open
ayushibaidya wants to merge 1 commit into
frazane:mainfrom
ayushibaidya:fix/twcrps-ensemble-dtype
Open

ayushibaidya wants to merge 1 commit into
frazane:mainfrom
ayushibaidya:fix/twcrps-ensemble-dtype

Conversation

@ayushibaidya

Copy link
Copy Markdown

Summary

Fixes #163.

  • Replace independent array conversions in uv_weighted_score_chain() with the existing asarray_matching() utility.
  • Prevent unintended float32 to float64 promotion for NumPy inputs.
  • Preserve precision of Python scalar bounds when operating on PyTorch float64 tensors.
  • Add regression tests for NumPy dtype preservation and PyTorch threshold precision.

Root cause

The default threshold transformation previously converted a, b, obs, and fct independently using xp.asarray().

This caused NumPy scalar bounds to introduce unwanted float64 promotion with float32 inputs, while PyTorch could round scalar bounds to float32 when operating on float64 tensors.

Using asarray_matching() aligns scalar bounds with the dtype and device of the existing array inputs.

Validation

  • Reproduced the NumPy dtype promotion and PyTorch threshold precision issues.
  • Added NumPy float32/float64 and PyTorch float64 regression tests.
  • Full NumPy/PyTorch test run: 1,125 passed, 3,456 skipped, 6 warnings.
  • All five pre-commit checks passed.
  • git diff --check passed.

Numba and JAX were not included in the reported full-suite validation.

@github-actions github-actions Bot added the core Core scoring API / numerics label Nov 15, 2026
@frazane
frazane requested a balanced review from Copilot November 16, 2026 07:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

core Core scoring API / numerics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

twcrps_ensemble bounds ignore the input precision

2 participants