[SciPy-user] strange error in integrate.romb

Gael Varoquaux gael.varoquaux at normalesup.org
Wed Dec 13 15:42:57 CST 2006


Hi, 

I don't really understand how integrate.romb is supposed to work.

First of all its docstring is not really clear:

""" Uses Romberg integration to integrate y(x) using N samples along the
given axis which are assumed equally spaced with distance dx. The
number of samples must be 1 + a non-negative power of two: N=2**k + 1 
"""

Reading this it is not clear that y is supposed to be a vector, and not a
function.

Second if I run it on a really simple test case, I get an error, and it
seems the error is due to a trivial bug in the code:

In [13]: x = arange(0,2**10+1)

In [14]: integrate.romb(x)
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most
recent call last)

/home/varoquau/<ipython console> 

/usr/lib/python2.4/site-packages/scipy/integrate/quadrature.py in romb(y,
dx, axis, show)
    256     for i in range(2,k+1):
    257         start >>= 1
--> 258         slice_R = tupleset(slice_R, slice(start,stop,step))
    259         step >>= 1
    260         R[(i,1)] = 0.5*(R[(i-1,1)] +
h*add.reduce(y[slice_R],axis))

TypeError: tupleset() takes exactly 3 arguments (2 given)

In [15]:

And indeed if you check out the code for tupleset, you find this :

def tupleset(t, i, value):
    l = list(t)
    l[i] = value
    return tuple(l)

It looks to me there has been some refactoring and the integrate.romb has
been left out.

Cheers,

Gaël


More information about the SciPy-user mailing list