numpy f2py question

G

George Trojan

I have a problem with numpy's vectorize class and f2py wrapped old
FORTRAN code. I found that the function _get_nargs() in
site-packages/numpy/lib/function_base.py tries to find the number of
arguments for a function from an error message generated when the
function is invoked with no arguments. However, with numpy 1.3.0 the
error message is different that the code expects. Is there any known
solution? I don';t know where the message is coming from, a cursory
check of numpy files did not yield any hits. A ctypes issue?
I did find an unanswered seven weeks old related posting
http://article.gmane.org/gmane.comp.python.numeric.general/32168/match=f2py+number+arguments
though I don't think this is gfortran related. Mine is 4.1.2.

George
 
S

sturlamolden

I have a problem with numpy's vectorize class and f2py wrapped old
FORTRAN code. I found that the function _get_nargs() in
site-packages/numpy/lib/function_base.py tries to find the number of
arguments for a function from an error message generated when the
function is invoked with no arguments. However, with numpy 1.3.0 the
error message is different that the code expects. Is there any known
solution? I don';t know where the message is coming from, a cursory
check of numpy files did not yield any hits. A ctypes issue?
I did find an  unanswered seven weeks old related postinghttp://article..gmane.org/gmane.comp.python.numeric.general/32168/matc...
though I don't think this is gfortran related. Mine is 4.1.2.

The wrappers generated by f2py just calls PyArg_ParseTupleAndKeywords
and return NULL if it fails. The error message from
PyArg_ParseTupleAndKeywords does not fit the regex used by _get_nargs:

re.compile(r'.*? takes exactly (?P<exargs>\d+) argument(s|) \((?
P<gargs>\d+) given\)')

It should have said

re.compile(r'.*? takes (exactly|at least) (?P<exargs>\d+) argument(s|)
\((?P<gargs>\d+) given\)')

It is not just an f2py issue. It affects any function that uses
keyword arguments. I'll file this as a bug on NumPy trac.

S.M.
 
G

George Trojan

sturlamolden said:
The wrappers generated by f2py just calls PyArg_ParseTupleAndKeywords
and return NULL if it fails. The error message from
PyArg_ParseTupleAndKeywords does not fit the regex used by _get_nargs:

re.compile(r'.*? takes exactly (?P<exargs>\d+) argument(s|) \((?
P<gargs>\d+) given\)')

It should have said

re.compile(r'.*? takes (exactly|at least) (?P<exargs>\d+) argument(s|)
\((?P<gargs>\d+) given\)')

It is not just an f2py issue. It affects any function that uses
keyword arguments. I'll file this as a bug on NumPy trac.

S.M.
That's not enough. f2py generated library ftest.so providing wrapper
around Fortran function

integer function f2(a, b)
integer, intent(in) :: a, b

run from

try:
ftest.f2()
except Exception, e:
print e

produces traceback
Required argument 'a' (pos 1) not found
so the proposed fix will miss this case.

I tracked the issue to changes (from 2.5.2 to 2.6.2) of Python/getargs.c
code. Still not sure what the proper fix should be.

George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top