EconForge / interpolation.py

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

guvectorized wrapping of eval_linear() appears broken #86

Closed tomduck closed 3 years ago

tomduck commented 3 years ago

The following test code demonstrates a simple guvectorize-decorated wrapper around eval_linear(). It works with with python 3.8, numba 0.51.2, and interpolation 2.1.6.

#! /usr/bin/env python3

import numpy as np
from numba import guvectorize, f8

from interpolation.splines import eval_linear

# The function to interpolate
xs = np.linspace(0, 10, 101)
values = np.sin(xs)

# The points to interpolate
points = np.array([[v] for v in range(11)], dtype=np.float64)

# The output array
out = np.zeros(11, dtype=np.float64)

# Wrap eval_linear() in a guvectorized function
@guvectorize([(f8[:], f8[:], f8[:, :], f8[:])],
             '(i),(i),(j,k)->(j)', nopython=True)
def wrapper(xs, values, points, out):
    """Calls eval_linear()."""
    eval_linear((xs,), values, points, out)

wrapper(xs, values, points, out)

print(out)

Upgrading interpolation to a more recent version results in the following error upon execution:

Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function _eval_linear at 0x7fd6fc9ee5e0>) found for signature:

 >>> _eval_linear(UniTuple(array(float64, 1d, A) x 1), array(float64, 1d, A), array(float64, 2d, A), array(float64, 1d, A))
.
.
.

The error message is very long. Please let me know if you would like me to copy the whole thing in. I believe that the problem may originate from the handling of ints/literals in __eval_spline().

Upgrading numba does not fix this.

Thanks for your efforts on this excellent package. :)

Cheers, Tom

albop commented 3 years ago

Sorry, for the slow response. This is a limitation in the eval_splines dispatch logic. I"ll fix it very soon.

tomduck commented 3 years ago

Thanks, Pablo. I appreciate your work on this excellent package. Cheers, Tom.