Skip to content

Commit ec99ff5

Browse files
authored
Merge pull request #24 from EconForge/albop/interp
Albop/interp
2 parents b2ff9a6 + 58877c2 commit ec99ff5

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

interpolation/multilinear/mlinterp.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,21 @@ def {funname}(*args):
158158
return source
159159

160160
elif it.eval == 'cartesian':
161-
if it.d != 2:
162-
return None
163-
source = f"""
161+
if it.d==1:
162+
source = f"""
163+
from numpy import zeros
164+
def {funname}(*args):
165+
grid = {grid_s}
166+
C = args[{it.d}]
167+
points_x = args[2]
168+
N = points_x.shape[0]
169+
res = zeros(N)
170+
for n in range(N):
171+
res[n] = mlinterp(grid, C, (points_x[n],))
172+
return res
173+
"""
174+
elif it.d==2:
175+
source = f"""
164176
from numpy import zeros
165177
def {funname}(*args):
166178
grid = {grid_s}
@@ -175,6 +187,8 @@ def {funname}(*args):
175187
res[n,m] = mlinterp(grid, C, (points_x[n], points_y[m]))
176188
return res
177189
"""
190+
else:
191+
return None
178192
return source
179193

180194

@@ -186,6 +200,8 @@ def interp(*args):
186200
aa = args[0].types
187201

188202
it = detect_types(aa)
203+
if it.d==1 and it.eval=='point':
204+
it = itt(it.d, it.values, 'cartesian')
189205
source = make_mlinterp(it,'__mlinterp')
190206
import ast
191207
tree = ast.parse(source)

0 commit comments

Comments
 (0)