fix: resolve 16 audited issues across saiunit core, math, and brainunit packaging#125
Merged
Conversation
…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.
Contributor
There was a problem hiding this comment.
Sorry @chaoming0625, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Merged
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Full audit of saiunit + brainunit surfaced 16 actionable findings; this PR fixes all of them with regression tests.
Bug fixes
degree,arcminute); plain dimensionless inputs are unchangedbool()fell back to__len__, sobool(Quantity([0.0]))wasTrue; 0-dlen()now raises a clearTypeErrorptp(method removed in NumPy 2.0),choose(numpy C method rejects kwargs),argpartition(JAX rejectskind/order),byteswap(JAX rejectsinplace); corrected misleadingresizedocstringcheck_unitsdocstring to state exact-unit matchingkmh,knot,kcal_per_hfactors were decimal-truncated; now computed exactlyUnit-semantics recategorization
correlate/covpropagate units (result unit = u1·u2), matching their mathematical meaning;unit_to_scalepath kept for compatibilityangleis scale-invariant and now accepts unit-ful inputsldexpkeepsx's unit; the exponent stays dimensionless-onlyAdditions
math.trapezoidwith unit propagation (y_unit * spacing_unit)speed_of_light,planck,hbar,gravitational_constant,standard_gravity,stefan_boltzmann(CODATA 2018/exact SI values, cross-checked against scipy)Cleanups
saiunit.__all__: removed duplicateliter/litreentries and staticautograd/sparseentries (already appended by the lazy-loading machinery)laxsubmodule; removed dead packaging lines inmake_brainunit_setup.pyandpyproject.toml.templateTest plan
pytest saiunit/— 3949 passed, 0 failed, 183 skippedmypy saiunit/— exit 0🤖 Generated with Claude Code