splint returns incorrect results (Trac #1393) #1918

Closed
scipy-gitbot opened this Issue Apr 25, 2013 · 6 comments

3 participants

@scipy-gitbot

Original ticket http://projects.scipy.org/scipy/ticket/1393 on 2011-02-24 by trac user Dave Hirschfeld, assigned to unknown.

This was originally reported on the list -
http://article.gmane.org/gmane.comp.python.scientific.user/28000

A self-contained example is given below and attached in case the line-endings get mangled...

def test_splint():
    from scipy.interpolate import splev, splint, splrep
    from scipy.integrate import quad
    from numpy import allclose
    y = array([ 0.38608245,  0.33937334,  0.30557594,  0.29031793,  0.27597413,
                0.26680583,  0.25012443,  0.24310048,  0.23825924,  0.23260759,
                0.22179233,  0.21821583,  0.2164903 ,  0.21275566,  0.20813042,
                0.20404953,  0.19703265,  0.19649831,  0.19548709,  0.1922062 ,
                0.18623453])
    #
    x = ones(y.size)/4
    x[0] /= 2
    x = x.cumsum()
    tck = splrep(x, y, s=0.0001)
    #
    lhs = splint(0.2, 0.3, tck)
    rhs = quad(lambda v: splev(v, tck, der=0), 0.2, 0.3)[0]
    assert allclose(lhs, rhs, 1e-6, 1e-12), "splint != quad. region = [0.2, 0.3]"
    lhs = splint(0, 0.1, tck)
    rhs = quad(lambda v: splev(v, tck, der=0), 0, 0.1)[0]
    assert allclose(lhs, rhs, 1e-6, 1e-12), "splint != quad. region = [0, 0.1]"
    lhs = splint(0.1, 0.2, tck)
    rhs = quad(lambda v: splev(v, tck, der=0), 0.1, 0.2)[0]
    assert allclose(lhs, rhs, 1e-6, 1e-12), "splint != quad. region = [0.1, 0.2]"
#
@scipy-gitbot

Attachment added by trac user Dave Hirschfeld on 2011-02-24: test_splint.py

@scipy-gitbot

@WarrenWeckesser wrote on 2011-02-24

Wrapped code sample in triple curly brackets.

@scipy-gitbot

@pv wrote on 2011-02-25

splint assumes the function is zero outside the data interval.

This is probably not a documentation issue only, as the zero assumption is not what is typically wanted.

@scipy-gitbot

Milestone changed to Unscheduled by @rgommers on 2011-08-27

@andreas-h

I think there shouldn't be done anything else here. With the added note in the docstring,splint works as advertised. While this might not be what users want sometimes, it seems this is impossible to fix within the frame of the current FITPACK implementation.

@pv
SciPy member
pv commented Feb 18, 2014

Agreed, I don't think this is easily fixed in any other way.

We'll do it in a better way without breaking backward compat, when the new B-spline stuff gets done.

@pv pv closed this Feb 18, 2014
@pv pv added this to the 0.14.0 milestone Feb 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment