Skip to content

Replace np.product, removed in numpy 2, so ARD runs again - #37

Merged
huangziwei merged 1 commit into
masterfrom
fix-ard-np-product
Aug 18, 2026
Merged

Replace np.product, removed in numpy 2, so ARD runs again#37
huangziwei merged 1 commit into
masterfrom
fix-ard-np-product

Conversation

@huangziwei

Copy link
Copy Markdown
Collaborator

ARD.update_C_prior asked for the number of coefficients with
np.product(self.dims). numpy removed that alias in 2.0 and jax.numpy went
with it, so every call raised

AttributeError: module 'jax.numpy' has no attribute 'product'

ARD was not producing worse answers, it was producing none. It is exported
from top level and is the first line of the EvidenceOpt docs in the README.

math.prod rather than np.prod: the value is the ncoeff argument to
sparsity_kernel, which uses it as a shape, so it has to be a Python int and
not something that could arrive traced.

Why nobody noticed

ARD had no tests. test_asd.py and test_ald.py exist, test_ard.py did
not, so the only thing standing between a removed numpy alias and a broken
estimator was somebody happening to run it.

ARDFixedPoint is a separate implementation that never touched np.product
and was never broken. Its test is there because the class had no coverage
either, not because this changes anything for it.

Test status

69 passed, nothing failing.

ARD.update_C_prior called np.product to get the number of coefficients. numpy
removed that alias, and jax.numpy with it, so every ARD call raised
AttributeError: ARD was not degraded, it was unusable.

math.prod is the right replacement rather than np.prod: the result is a shape
argument for sparsity_kernel and has to be a Python int, not a traced value.

ARD had no tests, which is why this went unnoticed. Adds RF recovery tests for
ARD and ARDFixedPoint, and ARD to tests/test_evidence.py, where it reproduces
the exact Gaussian marginal to 4 decimal places.
@huangziwei
huangziwei merged commit 167f865 into master Aug 18, 2026
3 checks passed
@huangziwei
huangziwei deleted the fix-ard-np-product branch August 18, 2026 09:54
@huangziwei huangziwei mentioned this pull request Aug 18, 2026
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