[Scipy-tickets] [SciPy] #1519: "quad" and "quadrature" behave differently when args is a single variable
SciPy Trac
scipy-tickets@scipy....
Thu Sep 15 04:57:57 CDT 2011
#1519: "quad" and "quadrature" behave differently when args is a single variable
--------------------------------------+-------------------------------------
Reporter: azrael | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: scipy.integrate | Version: 0.7.2
Keywords: syntax, quad, quadrature |
--------------------------------------+-------------------------------------
As far as I understand
[http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.quad.html
quad] and
[http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.quadrature.html
quadrature] should be interchangeable, atleast syntax-wise. Strangely it
does seem they are not:
{{{
from scipy.integrate import quad as q
#from scipy.integrate import quadrature as q
def myfunc(x, y):
return x + y
def integr1(y):
return q(myfunc, 0, 1, args=(y))[0]
def integr2(y):
return q(myfunc, 0, 1, args=(y,))[0]
print integr1(10), integr2(10)
}}}
will produce the right result, while switching to quadrature in the first
line will lead to
{{{
Traceback (most recent call last):
File "./test.py", line 38, in <module>
print integr2(10)
File "./test.py", line 36, in integr2
return q(myfunc, 0, 1, args=(y))[0]
File "/usr/lib/python2.6/dist-packages/scipy/integrate/quadrature.py",
line 136, in quadrature
newval = fixed_quad(vfunc, a, b, (), n)[0]
File "/usr/lib/python2.6/dist-packages/scipy/integrate/quadrature.py",
line 48, in fixed_quad
return (b-a)/2.0*sum(w*func(y,*args),0), None
File "/usr/lib/python2.6/dist-packages/scipy/integrate/quadrature.py",
line 77, in vfunc
return func(x, *args)
TypeError: myfunc() argument after * must be a sequence, not int
}}}
This was found because the wrongly used tuple in integr1() was the first
attempt of using the quadratures.
1. Shouldn't both integrators accept the same syntax? Even if that means
the acceptance for a single variable instead of a one-element-tuple in
"quad" would be removed ...
2. Could the error message be made more clear? It should say, args is not
a tuple. Or if the quadratures are supposed to accept any sequence, maybe
the documentation should also mention that any will work.
--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1519>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
More information about the Scipy-tickets
mailing list