EconForge / interpolation.py

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

Example mlinterp not working #51

Closed dangom closed 5 years ago

dangom commented 5 years ago

I tried to evaluate the example code:

from interpolation import mlinterp

x1 = np.linspace(0,1,100)**2 # non-uniform points for first dimensoin
x2 = (0,1,100) # uniform points for second dimension
grid = (x1,x2)
y = np.array([[np.sqrt(u1**2 + u2**2) for u2 in x2] for u1 in x1])

points = np.random.random((1000,2))

# vectorized call:
mlinterp(grid, y, points)

# non-vectorized call (note third argument must be a tuple of floats of right size)
mlinterp(grid, y, (0.4, 0.2))

But that gives:

TypeError                          Traceback (most recent call last)
<ipython-input-41-1cbb81f46b37> in <module>
     10 
     11 # vectorized call:
---> 12 mlinterp(grid, y, points)
     13 
     14 # non-vectorized call (note third argument must be a tuple of floats of right size)

TypeError: fmap() takes 0 positional arguments but 3 were given

Is the issue only at my end?

Installed interpolation with conda, as suggested in the README. Python 3.7.3 MacOS 10.13.6

albop commented 5 years ago

Hey @dangom. It is the example code which is wrong (I'm fixing it). Everything is based on type dispatch so the specification of the grid must respect the type. In particular, floats and ints are two different types. So it should be x2 = (0.0,1.0,100) instead of x2 = (0,1,100).