GithubHelp home page GithubHelp logo

interpolation.py's Introduction

interpolation.py's People

Contributors

albop avatar awagoner avatar cc7768 avatar gboehl avatar jagman88 avatar mv77 avatar oyamad avatar sglyon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

interpolation.py's Issues

Error on package import

My problem looks similar to #25.

I'm using Python 2.7.15

>>> from interpolation import interp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\interpolation\__init__.py", line 1, in <module>
    from .multilinear.mlinterp import interp, mlinterp
  File "C:\Python27\lib\site-packages\interpolation\multilinear\mlinterp.py", line 38
    def mlininterp(grid: Tuple, c: Array, u: Tuple)->float:

My pip list:

backports.functools-lru-cache (1.5)
cycler (0.10.0)
Cython (0.28.5)
enum34 (1.1.6)
fstrings (0.1.0)
funcsigs (1.0.2)
gitdb2 (2.0.4)
GitPython (2.1.11)
interpolation (0.2.1)
kiwisolver (1.0.1)
llvmlite (0.25.0)
matplotlib (2.2.2)
numba (0.40.0)
numexpr (2.6.5)
numpy (1.14.5)
pandas (0.23.4)
pip (9.0.3)
pyparsing (2.2.0)
python-dateutil (2.7.3)
pytz (2018.4)
scipy (1.1.0)
setuptools (39.0.1)
singledispatch (3.4.0.3)
six (1.11.0)
smmap2 (2.0.4)
tables (3.4.4)
tabulate (0.8.2)

Question: Key differences between scipy interpn

especially, what happens outside of the regular grid, can I switch extrapolation off and define a fill value == 0 ?

Sorry. that this is no real issue. Happy to migrate it to stackoverflow or so

Need for silent screen output

Installing with with pip install https://github.com/EconForge/interpolation.py works on Ubuntu but a call to LinearSpline or other functions returns extensive and unwanted screen output, for instance:

[20 20]
[20 20]
[20 20]
[20 20]
[20 20]
[20 20]
[20 20]
[20 20]
(20, 20)
(20, 20)
(20, 20)
(20, 20)
(20, 20)
(20, 20)
(20, 20)
(20, 20)
Setting
Setting
Setting
Setting
Setting
Setting
Setting
Setting
[20 20]
[20 20]
[20 20]
[20 20]
[20 20]
[20 20]
[20 20]
[20 20]
(20, 20)
(20, 20)
(20, 20)
(20, 20)
(20, 20)
(20, 20)
(20, 20)
(20, 20)

Would it be possible to turn it off in next version ?
Thanks,
Joris

Extrapolation with class interface

Is it correct, that you cannot chose extrapolation scheme for the LinearSpline and the other "class interfaces"? Is it a planned feature to make "interpolants" where you can also specify extrapolation behavior?

Stability issues

Currently trying to switch np.interp to interp, and running into some stability issues - sometimes it works but sometimes I run into this error and my code won't work

screen shot 2018-10-02 at 12 05 29 pm

ENH: add computation of derivatives to smolyak.

Let's denote the smolyak grid by s, the values on this grid by x, and by T(s,x)(p) the values interpolated on points p.
Currently, we can compute the derivative of p->T(s,x)(p). It would be nice to compute also the derivatives of x->T(s,x)(p).
The convention should actually be independent from the interpolation method.
In the particular case of smolyak, refering to the coefficients by c, it would be useful too to compute derivatives of c->T(s,c)(p).

One fix found for an error in fungen.py

I needed to replace

from numba.types.containers import Tuple, UniTuple

by

from numba.types import Tuple, UniTuple

in fungen.py. My setup is Python 3.6.9, and numba 0.49.

No Module eval_cubic_cuda

Line 50 of interpolation.py/misc/speed_comparison_cuda.py:

from interpolation.splines.eval_cubic_cuda import vec_eval_cubic_spline_3 as original

There is no module named eval_cubic_cuda

Systematic performance measures

We should know how our implementation performs, w.r.t.:

  • matlab's GriddedInterpolant
  • compecon's routines
  • Julia's grid.jl
  • scipy's routines

better jitted interface to multilinear interpolation

Currently there are two wrapper functions for multilinear interpolation on regular grids. They are implemented in splines/multilinear_numba.py but could be seriously improved, while reusing the same low-level functions multilinear_interpolation_xd and vec_multilinear_interpolation_xd

We could have one jitted, inplace function mlininterp(a,b,n,y,u,out) (name is a place holder) where:

  • a, b, n are 1d vectors or tuple of length d (number of dimensions) denoting a cartesian grid (a and b are lower and upper bounds, n number of nodes in each direction
  • y is a d dimensional arrays with the scalar values to be interpolated at each node of the grid. Or if y has d+1 dimensions, then one interpolates vectors instead (y[...,:] is the vector value at one grid point)
  • u is 2d array, where each line has the coordinates of a point at which to interpolate
  • out is a 1d-array if y is d-dimensional or 2d if y is (d+1)-dimensional and contains the output.

With this inplace function, it is possible to deduce from the dimensions of y and out only which is the value of d and whether the y represents scalar or vector values.

I wonder what is the best way to write the allocating version mlininterp(a,b,n,y,u) in order to detect whether values are scalars or vectors. One could expect a,b,n to be tuples, in which case their type would contain the dimension of the problem. One could have two function names (which is cheating). One could have a different signature like mlinterp(grid,y,u) where grid would be a tuple of tuples like ( (0.0,1.0,10), (-1.0, 1.0, 50) ). Not all options are mutually exclusive.

@jstac: what do you think ?

no eval_ms for linear interpolation and empty exo_grid

Hi- is there a reason that the dispatch multimethods in decision_rule.py do not include some functions for Linear interpolation with an empty exo_grid. ? Apologies if this is a stupid question.

Under # Empty x Cartesian x Linear, there are some functions defined but not eval_ms or eval_is, which seem to be needed for impulse response analysis. (And indeed are defined beneath for Empty x Cartesian x Cubic).

As a result if one does try to find irfs for a model that has used time iteration and linear interpolation, the following error message occurs:

Could not find signature for eval_ms: <DecisionRule, EmptyGrid, UniformCartesianGrid, Linear, ndarray, ndarray>

WIP: CUDA performances

Currently, the experiments with CUDA yield terrible performances on AWS/g2.
It may be because, calculations are made on 64 bits by default.
To do :

  • test 32 bits calculations
  • test 64 bits on a card which supports it natively (e.g. gtx titan)
  • try guvectorize(...target='gpu')

Support Complex numbers

import numpy as np

from interpolation.splines import UCGrid, CGrid, nodes

f = lambda x,y: 1j*np.sin(np.sqrt(x2+y2+0.00001))/np.sqrt(x2+y2+0.00001)
grid = UCGrid((-1.0, 1.0, 10), (-1.0, 1.0, 10))
gp = nodes(grid) # 100x2 matrix
values = f(gp[:,0], gp[:,1]).reshape((10,10))

from interpolation.splines import eval_linear
This one works ok
point = np.array([0.1,0.45]) # 1d array
val = eval_linear(grid, values, point) # float

This one does not
points = np.random.random((10000,2))
eval_linear(grid, values, points) # 10000 vector

Here the error

TypingError Traceback (most recent call last)
in
13
14 points = np.random.random((10000,2))
---> 15 eval_linear(grid, values, points) # 10000 vector

/DSTORE/BRICIA/jbernal_PhD/testenv/lib/python3.6/site-packages/numba/core/dispatcher.py in _compile_for_args(self, *args, **kws)
413 e.patch_message(msg)
414
--> 415 error_rewrite(e, 'typing')
416 except errors.UnsupportedError as e:
417 # Something unsupported is present in the user code, add help info

/DSTORE/BRICIA/jbernal_PhD/testenv/lib/python3.6/site-packages/numba/core/dispatcher.py in error_rewrite(e, issue_type)
356 raise e
357 else:
--> 358 reraise(type(e), e, None)
359
360 argtypes = []

/DSTORE/BRICIA/jbernal_PhD/testenv/lib/python3.6/site-packages/numba/core/utils.py in reraise(tp, value, tb)
78 value = tp()
79 if value.traceback is not tb:
---> 80 raise value.with_traceback(tb)
81 raise value
82

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

_eval_linear(UniTuple(Tuple(float64, float64, int64) x 2), array(complex128, 2d, C), array(float64, 2d, C))

There are 8 candidate implementations:

  • Of which 2 did not match due to:
    Overload in function '__eval_linear': File: interpolation/splines/eval_splines.py: Line 88.
    With argument(s): '(UniTuple(Tuple(float64, float64, int64) x 2), array(complex128, 2d, C), array(float64, 2d, C))':
    Rejected as the implementation raised a specific error:
    TypingError: Failed in nopython mode pipeline (step: nopython frontend)
    No implementation of function Function() found for signature:

    setitem(array(float64, 1d, C), int64, complex128)

There are 16 candidate implementations:
- Of which 16 did not match due to:
Overload of function 'setitem': File: : Line N/A.
With argument(s): '(array(float64, 1d, C), int64, complex128)':
No match.

During: typing of setitem at (44)

File "", line 44:

raised from /DSTORE/BRICIA/jbernal_PhD/testenv/lib/python3.6/site-packages/numba/core/typeinfer.py:1071

  • Of which 2 did not match due to:
    Overload in function '__eval_linear': File: interpolation/splines/eval_splines.py: Line 104.
    With argument(s): '(UniTuple(Tuple(float64, float64, int64) x 2), array(complex128, 2d, C), array(float64, 2d, C))':
    Rejected as the implementation raised a specific error:
    TypeError: __eval_linear() missing 1 required positional argument: 'extrap_mode'
    raised from /DSTORE/BRICIA/jbernal_PhD/testenv/lib/python3.6/site-packages/numba/core/typing/templates.py:710
  • Of which 2 did not match due to:
    Overload in function '__eval_linear': File: interpolation/splines/eval_splines.py: Line 130.
    With argument(s): '(UniTuple(Tuple(float64, float64, int64) x 2), array(complex128, 2d, C), array(float64, 2d, C))':
    Rejected as the implementation raised a specific error:
    TypeError: __eval_linear() missing 2 required positional arguments: 'out' and 'extrap_mode'
    raised from /DSTORE/BRICIA/jbernal_PhD/testenv/lib/python3.6/site-packages/numba/core/typing/templates.py:710
  • Of which 2 did not match due to:
    Overload in function '__eval_linear': File: interpolation/splines/eval_splines.py: Line 154.
    With argument(s): '(UniTuple(Tuple(float64, float64, int64) x 2), array(complex128, 2d, C), array(float64, 2d, C))':
    Rejected as the implementation raised a specific error:
    TypeError: __eval_linear() missing 1 required positional argument: 'out'
    raised from /DSTORE/BRICIA/jbernal_PhD/testenv/lib/python3.6/site-packages/numba/core/typing/templates.py:710

During: resolving callee type: Function(<function _eval_linear at 0x7f3d26ef6488>)
During: typing of call at /DSTORE/BRICIA/jbernal_PhD/testenv/lib/python3.6/site-packages/interpolation/splines/eval_splines.py (172)

File "../../testenv/lib/python3.6/site-packages/interpolation/splines/eval_splines.py", line 172:
def eval_linear(*args):

"""Do I get a docstring ?"""
return _eval_linear(*args)
^

What should be imported by `from interpolation import *`?

Currently only the scipy's like interfaces interp and mlinterp part of the root scope. The other apis, like eval_linear or eval_spline are accessible through the submodules. The question is whether other functions or objects should be part of the root scope.

restore computation of derivatives to splines

Main problem is to find a good API. I was thinking of something like:

eval_cubic(grid, C, points, Val[k]) # would differentiate up to order k and group the results by total order

eval_cubic(grid, C, points, ((V[0], V[0]), (V[2], V[0]), (V[0], V[2]) ) # would return the zero order and second order with respoect to each dimension. This is a bit to verbose.

It would be nice to do instead Orders[(0,0), (2,0), (0,2)] but I suspect it is not possible unless one can treat the numbers as literals.

Shall we keep a setup.py file ?

We have moved to using a pyroject.toml file, together with poetry. This centralizes all package information (no requirements.txt, setup.py, setup.cfg, ...).
If one doesn't want to use the poetry tools for development, it is still possible to install the package in a regular way by doing pip install .. This works as long as poetry is installed: according to the new standard pep517, pip will defer package building to poetry and it won't make any apparent difference. So all is needed is pip install poetry before pip install .
Only reason I see for a setup.py file is the will to replicate development installation (as in pip install -e .). There are two options:

  1. add a setup.py file, which we don't use for deployment, to ease the work of potential contributors
  2. explain it's possible to generate a setup.py file for development purposes with the following workflow: pip install dephell (only once) then dephell --from=pyproject.toml --to=setup.py. This generate the setup.py file needed to run pip install -e . and do in-place development. Accordingly we would add setup.py to .gitignore.
    My preference goes to 2 since setup.py files are a thing of the past. @grburgess, since you raised the issue, do you think it's a satisfying solution ?

Installation instructions on the ReadMe

Hi,

This worked for me:

conda install interpolation -c conda-forge

I'm guessing it's possible to install with pip and clone -> python setup.py install?
It'd be helpful to have it in the ReadMe

Thanks for your work!

ENH: use generated decorator from numba

It looks like numba is going to have some support for generated functions (numba/numba#1637)

Right now, we can use the version provided by @jcrist.

Benefits:

  • eval_cubic_splines and all dimension independent routines would be njitted
  • code could be compiled on the fly for any number of dimensions
  • more combinations would be possible without having to generate all of them

generalize filter_cubic

Currently the filter_cubic function has the following restrictions:

  1. only d<=4
  2. ignores terminal conditions (always natural splines)
    3.- does only cubic splines

It would be good to remove some or all of these restrictions. 1. and 2. are probably easy.

Returning a function for a non-grid domain (replacement for Scipy's `LinearNDInterpolation`)

With LinearNDInterpolation it is possible to get an interpolation function on an irregular grid.
For example

from scipy.interpolate import LinearNDInterpolator
interp_f = LinearNDInterpolator(points=[[1., 1.], [2.5, 2.], [2., 0.8]], 
                              values=[2., 10., 11.])
interp_f(2., 1.1)
#Gives: array(9.73076923)

Is there such functionality in interpolation.py, whether with one or multiple dimensions?

I saw that interpolation.interphandles non regular points, but the example only shows it returning points, not a function:

from interpolation import interp
x = np.linspace(0,1,100)**2 # non-uniform points
y = np.linspace(0,1,100)    # values
# interpolate at one point:
interp(x, y, 0.5)

BUG: build problem with conda.

Trying to bulid conda packages yields some error linked to the njit(cache=true) option:

RuntimeError: cannot cache function 'solve_deriv_interp_1d': no locator available for file '/home/travis/miniconda/envs/test-environment/lib/python3.5/site-packages/interpolation-0.1.6-py3.5.egg/interpolation/splines/filter_cubic.py'

Not sure where it comes from and I haven't been able to produce a smaller self contained example.

Should report error for CubicSplines when dim>4

I am using this package to do a 6-D interpolation using CubicSplines, but it didn't tell me that the interpolation for n-D (n>4) is not supported. So I could get a spline function which does not work normally (but can still output numbers without reporting error).

Then I switched to multilinear and it reported that I can't do interpolation higher than 5 dimensions. Thus I got to know where's the problem.

I think you need to add this error report. BTW, I looked at the source code. It seems cumbersome to write functions for each dimension. Do you have any approach to unify it, so that it can work for any dimensions?

(Also, I really need the 6-D cubic interpolation, if you can add it I will appreciate it very much!)

Not possible to use `eval_linear` with interpolation option ("xto.*") within jitted function

Hi and thanks for this very excellent work. This is an extremely useful project!

Big picture: I am numbafying a complete policy function iteration, which I suppose is a rather standard use case for this package. Therefore I am interpolating within a jitted function (via eval_linear).
The return vector has the same dimensionality as the input vector, which is multivariate. While eval_linear with univariate output can be successfully called within a jitted function independently of whether interpolation options are used (such as xto.Linear), this does not work for multivariate output.

Here a simple example based on your quick guide:

import numpy as np
from numba import njit
from interpolation.splines import eval_linear, UCGrid, nodes
from interpolation.splines import extrap_options as xto

f = lambda x,y: np.sin(x**3+y**2+0.00001)/np.sqrt(x**2+y**2+0.00001)
g = lambda x,y: np.sin(x**3+y**2+0.00001)/np.sqrt(x**2+y**2+0.00001)

grid = UCGrid((-1.0, 1.0, 10), (-1.0, 1.0, 10))
gp = nodes(grid)   # 100x2 matrix

mvalues = np.concatenate([
   f(gp[:,0], gp[:,1]).reshape((10,10))[:,:,None],
   g(gp[:,0], gp[:,1]).reshape((10,10))[:,:,None]
],axis=2) # 10x10x2 array

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

@njit
def fun():
    eval_linear(grid, mvalues, points)

@njit
def no_fun():
    eval_linear(grid, mvalues, points, xto.LINEAR)

fun()       # works happily
no_fun()    # does not :'(

Environment is arch linux with:
Python 3.7.4
numba 0.45
numpy 1.17
interpolation.py master branch

I tried to dig into your code but I admit that I got lost in codegen.py. I am happy about hints.

test performances with Pythran

Since we are now generating the interpolation code, it should be easy to make performance comparisons with Pythran or other compilation methods. ccing @serge-sans-paille just in case.

The interpolation code is generated with interpolation.splines.codegen.gen_linear(3, vectorized=True) (or gen_cubic(3, vectorized=True)) for dimension 3. Since the generated code is rather c-like, one would assume that performances would not depend much on the compilation engine, but that is juts the theory...

Syntax Error in mlinterp.py upon import

in interpolation\multilinear\mlinterp.py", line 38 def mlininterp(grid: Tuple, c: Array, u: Tuple)->float: ^ SyntaxError: invalid syntax

Is this a because I am running python3 ?

eval_linear raises numba error on master

Hiya!

First off - thanks for writing this! It's blazing fast - interpolating 17161 points on a regular 2d grid with equally many pixels takes 229ms with scipy and 4.29ms with interpolation! That's a 53x speedup!

The issue below is just in case you are unaware - I have instead installed the current conda version and numba=0.49 and things are working fine.

With the latest master, eval_linear is raising a large error when called as in the readme example here on github. It hints at the out argument not being present, but when included it includes an equally long error that is harder for me to take apart. I would have pasted the entire error here, but I accidentally wiped it after installing the older version. I suggest you just run the following (from Readme.md) and see:

import numpy as np

from interpolation.splines import UCGrid, CGrid, nodes

# we interpolate function
f = lambda x,y: np.sin(np.sqrt(x**2+y**2+0.00001))/np.sqrt(x**2+y**2+0.00001)

# uniform cartesian grid
grid = UCGrid((-1.0, 1.0, 10), (-1.0, 1.0, 10))

# get grid points
gp = nodes(grid)   # 100x2 matrix

# compute values on grid points
values = f(gp[:,0], gp[:,1]).reshape((10,10))

from interpolation.splines import eval_linear
# interpolate at one point
point = np.array([0.1,0.45]) # 1d array
val = eval_linear(grid, values, point)  # float

# interpolate at many points:
points = np.random.random((10000,2))
eval_linear(grid, values, points) # 10000 vector

# output can be preallocated
out = np.zeros(10000)
eval_linear(grid, values, points, out) # 10000 vector

Replacement for scipy's RegularGridInterpolator

Hi,

I'm currently using Scipy's RegularGridInterpolator to interpolate ~20 3 dimensional grids and then pickle the resulting functions for later use. Would this be possible with this package? If so, would the resulting functions be faster than the ones from scipy??

Thank you!

Example mlinterp not working

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

cannot import name 'UCGrid', 'CGGrid', or 'nodes'

Hi there,

following the example on the readme file, the line

from interpolation.splines import UCGrid, CGrid, nodes

results in a failed import. I've tried with the conda version and directly installing it from GitHub with the same result. Any ideas?

Thanks for your time.

`mlinterp` problems with global variables + numba

Seems that mlinterp has problems when being jitted and passed global variables...

screen shot 2018-10-09 at 2 39 20 pm

Interestingly, moving grid = (x1, x2) inside works, where x1 and x2 are global variables

Also had an issue with trying to jit a function inside a function with a class argument...

screen shot 2018-10-09 at 3 06 53 pm

Linear interpolation fails on ints

Hi @albop, catching any trout recently?

The following gives me Exception: Undetected evaluation type. But it works fine if 5 is replaced with 5.0. Please let me know if you have issues reproducing.

from interpolation import interp
a = np.linspace(0, 10, 10)
b = 2 * a
interp(a, b, 5)

Conda and pip versions.

Hi! This package is really great. I am curious if the version on conda and pip are the same. I’m having issues installing both as things seem to be missing.

I would like to fix with a PR, but I’m not used to this poetry System. Is it possible to switch to the standard setup tools?

1d linear interpolation with irregular grid

This could be implemented in a new file splines/linear.py.

Proposed api would be interp(x,y,u) (similar to scipy's version). It would interpolate the function given by y=f(x) at point u. If u is a scalar the output is a scalar. If u is a vector then output is a vector too.

One could extend it to vector valued function: if y is a 2d array, the function to interpolate would be such that f(x[i])=y[i,:]. Consequently the output out would be a vector if u is a scalar (with out.shape[0]==y.shape[1]) and a matrix if u is a vector (with out.shape==(u.shape[0],y.shape[1]))

Maybe it would be a good idea to implement first an inplace version interp(x,y,u,out) that doesn't allocate output.

WIP: try guvectorize

The functions which evaluate at one single point, can be vectorized using guvectorize. This is currently much faster than repeated calls of the evaluation function and almost as efficient as a manually inlined vectorized call.
Also, one can take advantage of the new 'parallel' keyword, to use multiple cpus.
Here are the timings for the usual experiment: 50x50x50 grid. Evaluation on 10^6 points:

Manual vectorization : 0.1056051254272461
GUVectorize : 0.10982108116149902
GUVectorize (parallel): 0.03372311592102051

Advantages:

  • for the same price: scalar evaluation and allocating/non-allocating calls.
    Caveats:
  • ... ? (maybe, gufun signatures involving scalars is unnatural)

Unintended printing of generated code

I remember having seen this using interpolation.py before, but was reminded when I was trying out dolo. Say, when solving a model using time iteration, you'll get something like

>>> dr = time_iteration(model)
Solving WITH complementarities.
------------------------------------------------
| N   |  Error     | Gain     | Time     | nit |
------------------------------------------------
def get_grid(a,b,n,C): return ((a[0],b[0],n[0]),)
We are going to extrapolate in array(float64, 2d, C) mode.
We are going to do inplace, with default extrapolation
def eval_cubic(grid, C, points, out):
    "This is my docstring"

    N = points.shape[0]

    n_vals = C.shape[1]

    #recover grid parameters
    # dim 0: uniform
    a_0 = grid[0][0]
    b_0 = grid[0][1]
    n_0 = grid[0][2]
    δ_0 = (n_0-1.0)/(b_0-a_0)

    for nn in range(N):

        # extract coordinates
        x_0 = points[nn,0]

        # compute indices and barycentric coordinates
        # dimension 0: uniform grid
        u_0 = (x_0 - a_0)*δ_0
        i_0 = int( floor( u_0 ) )
        i_0 = max( min(i_0,n_0-2), 0 )
        λ_0 = u_0-i_0

        # Basis functions
        
        μ_0_0 = λ_0*λ_0*λ_0;  μ_0_1 = λ_0*λ_0;  μ_0_2 = λ_0;  μ_0_3 = 1.0;
        Φ_0_0 = 0.0
        Φ_0_1 = 0.0
        Φ_0_2 = 0.0
        Φ_0_3 = 0.0
        if λ_0 < 0:
            Φ_0_0 = dCd[0,3]*λ_0 + Cd[0,3]
            Φ_0_1 = dCd[1,3]*λ_0 + Cd[1,3]
            Φ_0_2 = dCd[2,3]*λ_0 + Cd[2,3]
            Φ_0_3 = dCd[3,3]*λ_0 + Cd[3,3]
        elif λ_0 > 1:
            Φ_0_0 = (3*Cd[0,0] + 2*Cd[0,1] + Cd[0,2])*(λ_0-1) + (Cd[0,0]+Cd[0,1]+Cd[0,2]+Cd[0,3])
            Φ_0_1 = (3*Cd[1,0] + 2*Cd[1,1] + Cd[1,2])*(λ_0-1) + (Cd[1,0]+Cd[1,1]+Cd[1,2]+Cd[1,3])
            Φ_0_2 = (3*Cd[2,0] + 2*Cd[2,1] + Cd[2,2])*(λ_0-1) + (Cd[2,0]+Cd[2,1]+Cd[2,2]+Cd[2,3])
            Φ_0_3 = (3*Cd[3,0] + 2*Cd[3,1] + Cd[3,2])*(λ_0-1) + (Cd[3,0]+Cd[3,1]+Cd[3,2]+Cd[3,3])
        else:
            Φ_0_0 = (Cd[0,0]*μ_0_0 + Cd[0,1]*μ_0_1 + Cd[0,2]*μ_0_2 + Cd[0,3]*μ_0_3)
            Φ_0_1 = (Cd[1,0]*μ_0_0 + Cd[1,1]*μ_0_1 + Cd[1,2]*μ_0_2 + Cd[1,3]*μ_0_3)
            Φ_0_2 = (Cd[2,0]*μ_0_0 + Cd[2,1]*μ_0_1 + Cd[2,2]*μ_0_2 + Cd[2,3]*μ_0_3)
            Φ_0_3 = (Cd[3,0]*μ_0_0 + Cd[3,1]*μ_0_1 + Cd[3,2]*μ_0_2 + Cd[3,3]*μ_0_3)
        
        for i_x in range(n_vals):
            out[nn,i_x] = Φ_0_0*(C[i_0, i_x]) + Φ_0_1*(C[i_0 + 1, i_x]) + Φ_0_2*(C[i_0 + 2, i_x]) + Φ_0_3*(C[i_0 + 3, i_x])

|   1 |  8.000e-01 |      nan |    0.846 |   5 |
|   2 |  8.027e-02 |    0.100 |    0.048 |   6 |
|   3 |  4.881e-02 |    0.608 |    0.036 |   4 |
|   4 |  3.369e-02 |    0.690 |    0.042 |   5 |
|   5 |  2.470e-02 |    0.733 |    0.033 |   4 |
|   6 |  1.938e-02 |    0.785 |    0.046 |   5 |
|   7 |  1.541e-02 |    0.795 |    0.039 |   5 |
|   8 |  1.223e-02 |    0.794 |    0.035 |   4 |
|   9 |  9.744e-03 |    0.797 |    0.033 |   4 |
|  10 |  7.958e-03 |    0.817 |    0.031 |   4 |
|  11 |  6.347e-03 |    0.798 |    0.034 |   4 |
|  12 |  5.251e-03 |    0.827 |    0.036 |   4 |
|  13 |  5.288e-03 |    1.007 |    0.042 |   5 |
|  14 |  5.270e-03 |    0.997 |    0.036 |   5 |
|  15 |  5.295e-03 |    1.005 |    0.036 |   5 |
|  16 |  5.280e-03 |    0.997 |    0.041 |   5 |
|  17 |  5.154e-03 |    0.976 |    0.048 |   5 |
|  18 |  5.190e-03 |    1.007 |    0.035 |   5 |
|  19 |  5.256e-03 |    1.013 |    0.022 |   3 |
|  20 |  5.356e-03 |    1.019 |    0.028 |   3 |
|  21 |  5.478e-03 |    1.023 |    0.023 |   3 |
|  22 |  5.613e-03 |    1.025 |    0.022 |   3 |
|  23 |  5.752e-03 |    1.025 |    0.024 |   3 |
|  24 |  5.891e-03 |    1.024 |    0.025 |   3 |
|  25 |  6.022e-03 |    1.022 |    0.033 |   4 |
|  26 |  6.143e-03 |    1.020 |    0.029 |   4 |
|  27 |  6.251e-03 |    1.018 |    0.030 |   4 |
|  28 |  6.343e-03 |    1.015 |    0.042 |   4 |
|  29 |  6.420e-03 |    1.012 |    0.031 |   4 |
|  30 |  6.479e-03 |    1.009 |    0.033 |   4 |
|  31 |  6.520e-03 |    1.006 |    0.036 |   4 |
|  32 |  6.542e-03 |    1.003 |    0.040 |   4 |
|  33 |  6.545e-03 |    1.001 |    0.030 |   4 |
|  34 |  6.530e-03 |    0.998 |    0.030 |   4 |
|  35 |  6.495e-03 |    0.995 |    0.030 |   4 |
|  36 |  6.442e-03 |    0.992 |    0.034 |   4 |
|  37 |  6.371e-03 |    0.989 |    0.029 |   4 |
|  38 |  6.283e-03 |    0.986 |    0.035 |   5 |
|  39 |  6.180e-03 |    0.984 |    0.036 |   5 |
|  40 |  6.062e-03 |    0.981 |    0.036 |   5 |
|  41 |  5.930e-03 |    0.978 |    0.043 |   5 |
|  42 |  5.786e-03 |    0.976 |    0.038 |   5 |
|  43 |  5.631e-03 |    0.973 |    0.038 |   5 |
|  44 |  5.465e-03 |    0.971 |    0.028 |   3 |
|  45 |  5.289e-03 |    0.968 |    0.030 |   3 |
|  46 |  5.105e-03 |    0.965 |    0.024 |   3 |
|  47 |  4.915e-03 |    0.963 |    0.024 |   3 |
|  48 |  4.719e-03 |    0.960 |    0.028 |   3 |
|  49 |  4.519e-03 |    0.958 |    0.030 |   3 |
|  50 |  4.317e-03 |    0.955 |    0.029 |   3 |
|  51 |  4.114e-03 |    0.953 |    0.023 |   3 |
|  52 |  3.911e-03 |    0.951 |    0.023 |   3 |
|  53 |  3.710e-03 |    0.949 |    0.023 |   3 |
|  54 |  3.512e-03 |    0.947 |    0.027 |   3 |
|  55 |  3.318e-03 |    0.945 |    0.030 |   3 |
|  56 |  3.128e-03 |    0.943 |    0.031 |   3 |
|  57 |  2.944e-03 |    0.941 |    0.023 |   3 |
|  58 |  2.765e-03 |    0.939 |    0.025 |   3 |
|  59 |  2.593e-03 |    0.938 |    0.031 |   3 |
|  60 |  2.429e-03 |    0.936 |    0.023 |   3 |
|  61 |  2.271e-03 |    0.935 |    0.026 |   3 |
|  62 |  2.121e-03 |    0.934 |    0.024 |   3 |
|  63 |  1.978e-03 |    0.933 |    0.029 |   3 |
|  64 |  1.843e-03 |    0.932 |    0.023 |   3 |
|  65 |  1.715e-03 |    0.931 |    0.029 |   3 |
|  66 |  1.595e-03 |    0.930 |    0.027 |   3 |
|  67 |  1.481e-03 |    0.929 |    0.027 |   3 |
|  68 |  1.375e-03 |    0.928 |    0.026 |   3 |
|  69 |  1.275e-03 |    0.928 |    0.026 |   3 |
|  70 |  1.182e-03 |    0.927 |    0.028 |   3 |
|  71 |  1.095e-03 |    0.926 |    0.024 |   3 |
|  72 |  1.014e-03 |    0.926 |    0.017 |   2 |
|  73 |  9.379e-04 |    0.925 |    0.017 |   2 |
|  74 |  8.674e-04 |    0.925 |    0.017 |   2 |
|  75 |  8.019e-04 |    0.924 |    0.021 |   2 |
|  76 |  7.410e-04 |    0.924 |    0.022 |   2 |
|  77 |  6.845e-04 |    0.924 |    0.017 |   2 |
|  78 |  6.321e-04 |    0.923 |    0.019 |   2 |
|  79 |  5.835e-04 |    0.923 |    0.020 |   2 |
|  80 |  5.386e-04 |    0.923 |    0.025 |   2 |
|  81 |  4.969e-04 |    0.923 |    0.028 |   2 |
|  82 |  4.584e-04 |    0.922 |    0.026 |   2 |
|  83 |  4.228e-04 |    0.922 |    0.018 |   2 |
|  84 |  3.899e-04 |    0.922 |    0.021 |   2 |
|  85 |  3.595e-04 |    0.922 |    0.017 |   2 |
|  86 |  3.314e-04 |    0.922 |    0.018 |   2 |
|  87 |  3.054e-04 |    0.922 |    0.028 |   2 |
|  88 |  2.815e-04 |    0.922 |    0.021 |   2 |
|  89 |  2.594e-04 |    0.921 |    0.017 |   2 |
|  90 |  2.390e-04 |    0.921 |    0.026 |   2 |
|  91 |  2.202e-04 |    0.921 |    0.020 |   2 |
|  92 |  2.029e-04 |    0.921 |    0.017 |   2 |
|  93 |  1.869e-04 |    0.921 |    0.018 |   2 |
|  94 |  1.721e-04 |    0.921 |    0.017 |   2 |
|  95 |  1.585e-04 |    0.921 |    0.017 |   2 |
|  96 |  1.460e-04 |    0.921 |    0.017 |   2 |
|  97 |  1.345e-04 |    0.921 |    0.022 |   2 |
|  98 |  1.238e-04 |    0.921 |    0.017 |   2 |
|  99 |  1.140e-04 |    0.921 |    0.018 |   2 |
| 100 |  1.050e-04 |    0.921 |    0.026 |   2 |
| 101 |  9.666e-05 |    0.921 |    0.022 |   2 |
| 102 |  8.900e-05 |    0.921 |    0.022 |   2 |
| 103 |  8.194e-05 |    0.921 |    0.019 |   2 |
| 104 |  7.544e-05 |    0.921 |    0.029 |   2 |
| 105 |  6.945e-05 |    0.921 |    0.020 |   2 |
| 106 |  6.394e-05 |    0.921 |    0.019 |   2 |
| 107 |  5.886e-05 |    0.921 |    0.019 |   2 |
| 108 |  5.419e-05 |    0.921 |    0.028 |   2 |
| 109 |  4.988e-05 |    0.921 |    0.020 |   2 |
| 110 |  4.592e-05 |    0.921 |    0.018 |   2 |
| 111 |  4.227e-05 |    0.921 |    0.020 |   2 |
| 112 |  3.891e-05 |    0.920 |    0.019 |   2 |
| 113 |  3.581e-05 |    0.920 |    0.018 |   2 |
| 114 |  3.296e-05 |    0.920 |    0.018 |   2 |
| 115 |  3.034e-05 |    0.920 |    0.018 |   2 |
| 116 |  2.793e-05 |    0.920 |    0.018 |   2 |
| 117 |  2.571e-05 |    0.920 |    0.018 |   2 |
| 118 |  2.366e-05 |    0.920 |    0.017 |   2 |
| 119 |  2.178e-05 |    0.920 |    0.017 |   2 |
| 120 |  2.004e-05 |    0.920 |    0.019 |   2 |
| 121 |  1.845e-05 |    0.920 |    0.012 |   1 |
| 122 |  1.698e-05 |    0.920 |    0.011 |   1 |
| 123 |  1.563e-05 |    0.920 |    0.012 |   1 |
| 124 |  1.438e-05 |    0.920 |    0.012 |   1 |
| 125 |  1.324e-05 |    0.920 |    0.010 |   1 |
| 126 |  1.218e-05 |    0.920 |    0.015 |   1 |
| 127 |  1.121e-05 |    0.920 |    0.011 |   1 |
| 128 |  1.032e-05 |    0.920 |    0.011 |   1 |
| 129 |  9.499e-06 |    0.920 |    0.010 |   1 |
| 130 |  8.742e-06 |    0.920 |    0.010 |   1 |
| 131 |  8.046e-06 |    0.920 |    0.011 |   1 |
| 132 |  7.405e-06 |    0.920 |    0.015 |   1 |
| 133 |  6.815e-06 |    0.920 |    0.010 |   1 |
| 134 |  6.272e-06 |    0.920 |    0.011 |   1 |
| 135 |  5.772e-06 |    0.920 |    0.012 |   1 |
| 136 |  5.313e-06 |    0.920 |    0.010 |   1 |
| 137 |  4.889e-06 |    0.920 |    0.010 |   1 |
| 138 |  4.500e-06 |    0.920 |    0.015 |   1 |
| 139 |  4.141e-06 |    0.920 |    0.012 |   1 |
| 140 |  3.811e-06 |    0.920 |    0.012 |   1 |
| 141 |  3.508e-06 |    0.920 |    0.016 |   1 |
| 142 |  3.228e-06 |    0.920 |    0.010 |   1 |
| 143 |  2.971e-06 |    0.920 |    0.011 |   1 |
| 144 |  2.734e-06 |    0.920 |    0.011 |   1 |
| 145 |  2.516e-06 |    0.920 |    0.014 |   1 |
| 146 |  2.316e-06 |    0.920 |    0.012 |   1 |
| 147 |  2.131e-06 |    0.920 |    0.010 |   1 |
| 148 |  1.961e-06 |    0.920 |    0.011 |   1 |
| 149 |  1.805e-06 |    0.920 |    0.010 |   1 |
| 150 |  1.661e-06 |    0.920 |    0.010 |   1 |
| 151 |  1.529e-06 |    0.920 |    0.013 |   1 |
| 152 |  1.407e-06 |    0.920 |    0.010 |   1 |
| 153 |  1.295e-06 |    0.920 |    0.011 |   1 |
| 154 |  1.192e-06 |    0.920 |    0.011 |   1 |
| 155 |  1.097e-06 |    0.920 |    0.011 |   1 |
| 156 |  1.009e-06 |    0.920 |    0.014 |   1 |
| 157 |  9.288e-07 |    0.920 |    0.012 |   1 |
------------------------------------------------
Elapsed: 4.452649354934692 seconds.
------------------------------------------------

in std out. That seems unintended, right?

License

Hi,
I really appreciate your spline code, and used it in one project. Very soon we're going to release the project, just wonder if you can get a license (e.g. MIT license), such that we can claim the code of yours in our code.

Thanks!

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.