No positional arguments for f2py callback
See original GitHub issueI am trying to override SLICOT’s calls to LAPACK XERBLA in order to raise a Slycot specific exception: https://github.com/python-control/Slycot/pull/127
Unfortunately I am having issues with passing required positional arguments to the callback function.
The SLICOT routines call XERBLA(SRNAME, INFO)
, which should call the user provided Python function raise_xerbla(srname, info)
. But that function complains about not enough provided positional arguments. In fact, the argument list is empty.
Any tips what is wrong here?
>>> numpy.__version__
'1.18.4'
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Error when using callback function with f2py - Stack Overflow
I'm trying to pass a python function to a f2py generated function. I can not figure out how to do this when the...
Read more >Accepting any number of arguments to a function
To accept any number of positional arguments we're going to need to use the * operator when defining this function.
Read more >The modules are equally robust F2PY automatically generates ...
This is usually not a problem if one follows theF2PY guidelines and ... the others are taken as positionalarguments in the same order...
Read more >Using F2PY bindings in Python — NumPy v1.25.dev0 Manual
Such PyCapsule objects can be used as callback arguments for F2PY generated ... Usually there is no need to worry about how the...
Read more >Intro to Python programming - Simula Research Laboratory
What if the user fails to provide two command-line arguments? Python aborts execution with an ... do that without loop and point-wise callback,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi,
sure! As you may have seen, we went another route without the callback. However it’s maybe worth fixing if this is a bug in f2py.
The attribute error means, you didn’t import the development version of Slycot with the xerbla_raises function and the sb10fd wrapper present, but likely an installed Slycot 0.3.5.
Here is a minimal example without involving Slycot at all: https://github.com/bnavigator/f2py-minimal-cb
Hi @melissawm, sorry for the late response. Thank you very much for looking into this. As mentioned before, be already went another route without calling the callback.
I can imagine that it would be great to have the functionality initially described, though.
If I understand correctly, the solution you describe requires the additition of the callback signature to all Fortran routines calling the intermediate routine. So overriding an existing generic Fortran routine with one using a Python callback is not possible without adjusting the code for the complete library. Would it be possible to extend f2py so that it traverses routine signatures and injects the dependency automatically? Bonus: What about Fortran objects, which are compiled and used by .pyf referenced routines but are not in the interface themselves?