[Numpy-discussion] vectorize() broken on Python2.6
Tue Oct 6 15:42:22 CDT 2009
f2py generated wrappers cannot be vectorized with numpy1.3.0 and Python2.6.2.
The reason is change to Python's getargs.c. Vectorize, or rather _get_nargs()
defined in lib/function_base.py tries to determine the number of arguments from
error message generated while the interpreter parses function invocation without
any arguments. The messages (in getargs.c) have changed, for example:
Required argument 'a' (pos 1) not found
Since the message no longer contains information how many arguments a function
takes, a fix is not obvious. Is there a solution coming soon?
I posted a message on comp.lang.python few days ago. Sturda Molden generated bug
report http://projects.scipy.org/numpy/ticket/1247. However the change he
suggests does not fix the problem.
I am tempted to apply a temporary workaround for my current needs:
The __init__ method in vectorize would accept an additional argument,
interface=None. That argument would be a Python code stub, prepared manually
(though it could easily be generated by f2py). This stub would be used by
_get_nargs() when the original object does not contain attribute 'func_code'.
integer function f3(a, b, c)
integer, intent(in) :: a, b
integer, optional, intent(in) :: c
if (present(c)) then
f3 = a - b
f3 = a + b
end function f3
def f3_iface(a, b, c=None):
vf3 = numpy.vectorize(ftest.f3, f3_iface)
Are there any drawbacks to this approach?
More information about the NumPy-Discussion