EconForge / interpolation.py

BSD 2-Clause "Simplified" License
123 stars 35 forks source link

eval_cubic fails when array to interpolate on is non-writable #82

Closed albop closed 3 years ago

albop commented 3 years ago
from interpolation.splines import eval_cubic

vals = np.random.random((7,7,2))
grid = ((-0.053333333333333344, 0.053333333333333344, 5), (5.0, 15.0, 5))

# this works
points = np.array([[0., 9.35497829]])
x = eval_cubic(grid, vals, points)

# 
pp = points.copy()
pp.flags.writeable = False
x = eval_cubic(grid, vals, pp)

The latest fails with error

Traceback (most recent call last):                                                                                                           
  File "tt.py", line 14, in <module>                                                                                                                                                                                                                                                      
    x = eval_cubic(grid, vals, pp)                                                                                                           
  File "/home/pablo/.cache/pypoetry/virtualenvs/dolo-kQ5NCRS9-py3.8/lib/python3.8/site-packages/numba/core/dispatcher.py", line 415, in _compile_for_args
    error_rewrite(e, 'typing')                                                                                                                                                                                                                                                            
  File "/home/pablo/.cache/pypoetry/virtualenvs/dolo-kQ5NCRS9-py3.8/lib/python3.8/site-packages/numba/core/dispatcher.py", line 358, in error_rewrite
    reraise(type(e), e, None)
  File "/home/pablo/.cache/pypoetry/virtualenvs/dolo-kQ5NCRS9-py3.8/lib/python3.8/site-packages/numba/core/utils.py", line 80, in reraise
    raise value.with_traceback(tb)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function _eval_cubic at 0x7f46bd063c10>) found for signature:

 >>> _eval_cubic(UniTuple(Tuple(float64, float64, int64) x 2), array(float64, 3d, C), readonly array(float64, 2d, C))

It is plausible that the dispatch in interpolation.py does not correcly identify readonly arrays as a subclass of array.