GithubHelp home page GithubHelp logo

Comments (4)

albop avatar albop commented on July 28, 2024

Hi @fmwatson,

That bug is not very easy to fix, but there is a simple workaround. You need to specify a value for all arguments of eval_spline. The following code works:

import numpy as np

from interpolation.splines import UCGrid, filter_cubic, eval_spline

vals = np.random.rand(5)
grid = UCGrid((0., 1., 5))  
coef = filter_cubic(grid, vals)   
x = np.array([0.22])

eval_spline(grid, coef, x, out=None, order=3, diff="None", extrap_mode="linear")

Reason arguments are passed as strings is to make them behave as litterals (i.e. a different function gets compiled for each value of them).
With current version of numba, I haven't found a way to do that properly with named arguments. Not properly in the sense that it doesn't work for default values.

from interpolation.py.

fmwatson avatar fmwatson commented on July 28, 2024

Thanks @albop - that works for me now, and it is indeed a simple workaround (sorry if this is documented elsewhere!)

I wondered if this would also fix what seemed like a similar issue I'm having trying to use eval_cubic/eval_spline in a prange loop, but I still get an error in this case:
LoweringError: Failed in nopython mode pipeline (step: native lowering) scalar type Tuple(float64, float64, int64) given for non scalar argument #3

with example code

import numpy as np
import numba as nb
from interpolation.splines import UCGrid, filter_cubic, eval_spline

@nb.jit(nopython=True, parallel=True)
def run_in_pfor(vals, grid, coef, x):
    for i in nb.prange(6):
           _= eval_spline(grid, coef, x, out=None, order=3, diff="None", extrap_mode="linear")

vals = np.random.rand(5)
grid = UCGrid((0., 1., 5))  
coef = filter_cubic(grid, vals)   
x = np.array([0.22])
run_in_pfor(vals, grid, coef, x)

It looks like this was probably unrelated though (I think the error message has changed at least!) - so probably needs its own thread.

from interpolation.py.

albop avatar albop commented on July 28, 2024

Humm that's a new one.
My guess is it is some limitation of numba parfor but I'm not sure which one (maybe tuple in parallel for loops).

The following code raises the same error:

import numpy as np
import numba as nb
from numba import prange

@nb.jit
def my_fun(vals, grid, coef, x):
    return vals[0] + coef[0] + x[0] + grid[0][0]

@nb.jit(nopython=True, parallel=True)
def run_in_pfor(vals, grid, coef, x):
    t = 0.0
    for h in prange(6):
        res = my_fun(vals, grid, coef, x)
        t += res
    return t

vals = np.random.rand(5)
grid = ((0., 1., 5),)  
coef = vals.copy()
x = np.array([0.22])
run_in_pfor(vals, grid, coef, x)

This indeed deserves its own thread, probably in numba though.

from interpolation.py.

albop avatar albop commented on July 28, 2024

I'm closing the issue here as there isn't much I can do about it.

from interpolation.py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.