numpy f2py question

Discussion in 'Python' started by George Trojan, Oct 2, 2009.

  1. 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
    George Trojan, Oct 2, 2009
    #1
    1. Advertising

  2. George Trojan

    sturlamolden Guest

    On 2 Okt, 22:41, George Trojan <> wrote:
    > 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.
    sturlamolden, Oct 3, 2009
    #2
    1. Advertising

  3. George Trojan

    sturlamolden Guest

  4. sturlamolden wrote:
    > On 2 Okt, 22:41, George Trojan <> wrote:
    >> 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.
    >
    >
    >
    >
    >
    >

    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
    George Trojan, Oct 5, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. M. Faust
    Replies:
    6
    Views:
    507
    Robert Kern
    Sep 28, 2004
  2. Andrea Gavana

    Numpy-f2py troubles

    Andrea Gavana, Oct 17, 2006, in forum: Python
    Replies:
    1
    Views:
    620
  3. Guest

    Re: [f2py] f2py problem

    Guest, May 15, 2007, in forum: Python
    Replies:
    0
    Views:
    581
    Guest
    May 15, 2007
  4. Replies:
    2
    Views:
    486
    Robert Kern
    Nov 13, 2007
  5. Blubaugh, David A.

    F2PY ?? Has anyone worked with the F2PY generator?

    Blubaugh, David A., Sep 8, 2008, in forum: Python
    Replies:
    0
    Views:
    260
    Blubaugh, David A.
    Sep 8, 2008
Loading...

Share This Page