Skip to content

fix: resolve 16 audited issues across saiunit core, math, and brainunit packaging#125

Merged
chaoming0625 merged 1 commit into
mainfrom
worktree-audit-fixes
Jun 11, 2026
Merged

fix: resolve 16 audited issues across saiunit core, math, and brainunit packaging#125
chaoming0625 merged 1 commit into
mainfrom
worktree-audit-fixes

Conversation

@chaoming0625

Copy link
Copy Markdown
Collaborator

Summary

Full audit of saiunit + brainunit surfaced 16 actionable findings; this PR fixes all of them with regression tests.

Bug fixes

  • deg2rad/radians: no longer double-convert Quantities carrying scaled angle units (degree, arcminute); plain dimensionless inputs are unchanged
  • Quantity.bool: added, following the mantissa's NumPy/JAX semantics — previously bool() fell back to __len__, so bool(Quantity([0.0])) was True; 0-d len() now raises a clear TypeError
  • CustomArray backend crashes: ptp (method removed in NumPy 2.0), choose (numpy C method rejects kwargs), argpartition (JAX rejects kind/order), byteswap (JAX rejects inplace); corrected misleading resize docstring
  • math.asarray: dispatches on the input's backend instead of forcing the session default — numpy input stays numpy
  • check_dims/check_units: unfilled default values are now validated too (previously bypassed checking); rewrote stale Brian2-era check_units docstring to state exact-unit matching
  • Exact factors: kmh, knot, kcal_per_h factors were decimal-truncated; now computed exactly

Unit-semantics recategorization

  • correlate/cov propagate units (result unit = u1·u2), matching their mathematical meaning; unit_to_scale path kept for compatibility
  • angle is scale-invariant and now accepts unit-ful inputs
  • ldexp keeps x's unit; the exponent stays dimensionless-only

Additions

  • math.trapezoid with unit propagation (y_unit * spacing_unit)
  • Constants: speed_of_light, planck, hbar, gravitational_constant, standard_gravity, stefan_boltzmann (CODATA 2018/exact SI values, cross-checked against scipy)

Cleanups

  • saiunit.__all__: removed duplicate liter/litre entries and static autograd/sparse entries (already appended by the lazy-loading machinery)
  • brainunit: exported lax submodule; removed dead packaging lines in make_brainunit_setup.py and pyproject.toml.template

Test plan

  • 54 new regression tests covering every fix
  • pytest saiunit/ — 3949 passed, 0 failed, 183 skipped
  • mypy saiunit/ — exit 0

🤖 Generated with Claude Code

…it packaging

Bug fixes:
- deg2rad/radians: no longer double-convert Quantities carrying scaled
  angle units (degree, arcminute); plain dimensionless inputs unchanged
- Quantity: add __bool__ following mantissa semantics (previously fell
  back to __len__, giving wrong truthiness); clearer 0-d __len__ error
- CustomArray: fix ptp (removed in NumPy 2.0), choose (numpy rejects
  kwargs), argpartition (JAX rejects kind/order), byteswap (JAX rejects
  inplace); correct resize docstring
- math.asarray: dispatch on the input's backend instead of forcing the
  default (numpy input stays numpy)
- check_dims/check_units: validate unfilled default values; rewrite
  stale check_units docstring (exact-unit matching, not dimension)
- Exact conversion factors for kmh, knot, kcal_per_h (were truncated)

Unit-semantics recategorization:
- correlate/cov: propagate units (result unit = u1 * u2)
- angle: scale-invariant, accepts unit-ful inputs
- ldexp: keeps x's unit; exponent must stay dimensionless

Additions:
- math.trapezoid with unit propagation (y_unit * spacing_unit)
- constants: speed_of_light, planck, hbar, gravitational_constant,
  standard_gravity, stefan_boltzmann

Cleanups:
- saiunit.__all__: remove duplicate liter/litre entries and static
  autograd/sparse entries (appended by lazy-loading machinery)
- brainunit: export lax submodule; drop dead packaging lines

All changes covered by new regression tests; pytest 3949 passed, mypy clean.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry @chaoming0625, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@chaoming0625 chaoming0625 merged commit 0916de2 into main Jun 11, 2026
8 checks passed
@chaoming0625 chaoming0625 deleted the worktree-audit-fixes branch June 11, 2026 08:36
@chaoming0625 chaoming0625 mentioned this pull request Jun 11, 2026
chaoming0625 added a commit that referenced this pull request Jun 11, 2026
Bump version to 0.4.0 and add the 0.4.0 changelog entry.

Version 0.4.0 is a library-wide correctness and robustness release,
resolving 150+ audited bugs across the core Quantity/Unit/Dimension
types and the math, lax, linalg, fft, sparse, and autograd subpackages
(PRs #106-#125). The public API is unchanged; 0.4.0 is a drop-in
upgrade from 0.3.x.

Co-authored-by: Chaoming Wang <wcm.brainsim@gmail.com>
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