-
-
Notifications
You must be signed in to change notification settings - Fork 859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scipy: Fix recursive functions #4822
Conversation
Non recursive functions declare all their locals as static, ones marked "recursive" need them to be proper local variables. Not sure if non recursive funcs need static locals, let's try making all locals non-static first.
Looks like I get Pyodide fatal errors on this PR, for example:
End of the output:
|
The problem is that if you say |
Still the same issue as #4822 (comment) in the last iteration of the PR. Quicky looking it seems like Here is a snippet that reproduces the issue in this PR (simplified from import numpy as np
from numpy import cos, sin, pi
from numpy.testing import (assert_equal, assert_almost_equal, assert_allclose,
assert_, suppress_warnings)
from scipy.integrate import qmc_quad
from scipy import stats, special
def func(x):
return stats.multivariate_normal.pdf(x.T, mean, cov)
n_points=2**8
n_estimates=8
signs=np.ones(2)
ndim = 2
mean = np.zeros(ndim)
cov = np.eye(ndim)
rng = np.random.default_rng(2879434385674690281)
qrng = stats.qmc.Sobol(ndim, seed=rng)
a = np.zeros(ndim)
b = np.ones(ndim) * signs
print('before qmc_quad', flush=True)
res = qmc_quad(func, a, b, n_points=n_points,
n_estimates=n_estimates, qrng=qrng)
print('after qmc_quad', flush=True)
ref = stats.multivariate_normal.cdf(b, mean, cov, lower_limit=a)
print('before stdtdrit', flush=True)
atol = special.stdtrit(n_estimates-1, 0.995) * res.standard_error # 99% CI
print('after stdtdrit', flush=True)
assert_allclose(res.integral, ref, atol=atol)
assert np.prod(signs)*res.integral > 0
rng = np.random.default_rng(2879434385674690281)
qrng = stats.qmc.Sobol(ndim, seed=rng)
print('before qmc_quad', flush=True)
logres = qmc_quad(lambda *args: np.log(func(*args)), a, b,
n_points=n_points, n_estimates=n_estimates,
log=True, qrng=qrng)
print('after qmc_quad', flush=True)
assert_allclose(np.exp(logres.integral), res.integral, rtol=1e-14)
assert np.imag(logres.integral) == (np.pi if np.prod(signs) < 0 else 0)
assert_allclose(np.exp(logres.standard_error),
res.standard_error, rtol=1e-14, atol=1e-16) I get this kind of info
|
Thanks for the reproduction @lesteve. |
Okay I think I got it. |
The dblquad test does not seem to pass with your latest fixes 😅 ... For example, node build log:
There is this warning as well just before that is likely relevant:
|
Hmm still doesn't work. It's just a matter of futzing with it at this point I think, some of the commits make the dblquad test pass so I definitely have the right approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for handling fortran issues @hoodmane! Let me port the f2c fixes to pyodide/pyodide-build
.
FYI looks like this fixed quite a number of issues in the Scipy test suite, see lesteve/scipy-tests-pyodide#37. In particular:
|
Ports pyodide/pyodide#4822 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Non recursive functions declare all their locals as static, ones marked "recursive" need them to be proper local variables. The Fortran files each contain exactly one function. If the one function is recursive, we label the source file with a comment. Then when processing the C file, if it contains the recursive marker comment, we remove the `static` modifiers from the variables. At this point, we really ought to consider modifying f2c itself...
Non recursive functions declare all their locals as static, ones marked "recursive" need them to be proper local variables. Not sure if non recursive funcs need static locals, let's try making all locals non-static first. If this doesn't work, we can locate functions marked recursive and only modify them.
Fixes #4818.
@lesteve can you check the status of the scipy tests here?