Skip to content

Commit 1935b7c

Browse files
authored
Merge pull request #83 from EconForge/albop/numba_fix
Albop/numba fix
2 parents 9501032 + 1e122bf commit 1935b7c

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

interpolation/splines/eval_splines.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@
3939
dAd[:,i] = Ad[:,i-1]*(4-i)
4040

4141
array_2d = numba.typeof(np.zeros((2,2)))
42+
tt = np.zeros((2,2))
43+
tt.flags.writeable=False
44+
array_2d_readonly = numba.typeof(tt)
4245
array_1d = numba.typeof(np.zeros(2))
43-
46+
del tt
4447

4548
### eval spline (main function)
4649

@@ -105,7 +108,7 @@ def ugly_workaround(grid, C, points, out=None, order=1, diff="None", extrap_mode
105108
extrap_ = (extrap_mode).literal_value
106109
d = len(grid)
107110

108-
vectorized = points == array_2d
111+
vectorized = (points == array_2d) or (points == array_2d_readonly)
109112
allocate = True
110113
vector_valued = (C.ndim==(len(grid)+1))
111114

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
def test_readonly_vec():
3+
4+
import numpy as np
5+
from interpolation.splines.eval_splines import eval_cubic
6+
7+
vals = np.random.random((7,7,2))
8+
grid = ((-0.053333333333333344, 0.053333333333333344, 5), (5.0, 15.0, 5))
9+
10+
# this works
11+
points = np.array([[0., 9.35497829]])
12+
x = eval_cubic(grid, vals, points)
13+
14+
#
15+
pp = points.copy()
16+
pp.flags.writeable = False
17+
x = eval_cubic(grid, vals, pp)
18+
19+
20+
def test_readonly():
21+
22+
import numpy as np
23+
from interpolation.splines.eval_splines import eval_cubic
24+
25+
vals = np.random.random((7,7,2))
26+
grid = ((-0.053333333333333344, 0.053333333333333344, 5), (5.0, 15.0, 5))
27+
28+
# this works
29+
points = np.array([0., 9.35497829])
30+
x = eval_cubic(grid, vals, points)
31+
32+
#
33+
pp = points.copy()
34+
pp.flags.writeable = False
35+
x = eval_cubic(grid, vals, pp)

0 commit comments

Comments
 (0)