-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Quadratic interpolate.interpo1d() function does not work with read-only array input #9331
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
Comments
Cython memoryviews seem to have issues with read-only numpy arrays. Here's a repro without scipy:
While arguably this is an implementation detail (typed memoryviews) leaking out of |
I think there's some discussion on the cython github: It looks like this patch is already merged in? I'm still going through what exactly is that we need to do though. Using a const keyword maybe? |
I tried the following, which seems to work:
|
Then it's the matter of bumping up the Cython version to 0.28.x Would you be interested in sending a PR?
|
I think the trick is to add the const keyword to various functions in _bspl.pyx file where the array is passed in as not modifiable. I started doing that for things like "double[::1]" and turn that into "const double[::1]". I did have problem doing "const double_or_complex[:,::1]" though. Where would the test go? |
Tests are in scipy/interpolate/tests : test_bsplines.py for b-splines, test_interpolate.py for interp1d and PPoly (const memoryviews are best added simultaneously to b-splines and PPoly). |
cython/cython#1772 mentions const memoryviews and fused types. So it might be that we'd want to wait until this is ironed out in cython (which has happened previously). |
I think I can get my use case to work when I add a couple of const to the declaration in _bspl.pyx (ignoring the fused type problem for double_or_complex problem for now). It certainly does not cover all the cases where this can happen in scipy though. I think for some of those functions the proposed workaround does not work. For instance, you have double_or_complex as writable and readable in the same function signature in _norm_eq_lsq, so we would probably hit the corner case where cython would fail. I can look into adding a few tests. Do you still want a pull request on that? |
This attempts to fix issue #9331 where the read-only array would raise an exception. It does not address all possible input arguments, due to the lack of fused type support for const in cython.
The interpolate.interpo1d() function with kind='quadratic' does not work with read-only array input. If kind is not given (default) or if the array is not read-only, the function would work properly. For instance:
Reproducing code example:
Error message:
Scipy/Numpy/Python version information:
The text was updated successfully, but these errors were encountered: