Consider we have subroutine below that gets a real function as its first argument:
I have wrapped this subroutine in python using f2py.
The question is, How can we pass that real function to it in python?
Consider we have subroutine below that gets a real function as its first argument:
Some other notes:
You should declare all the dummy arguments and other variables.
Also, do not use goto
, but use a do
loop.
I donāt know how f2py does it, or if it allows it.
Are you looking to pass a python function as your f
argument? If so, is this a callback issue? See https://numpy.org/devdocs/f2py/python-usage.html#call-back-arguments
Yeah, thanks
I refactored subroutine above as follows:
/tmp/tmp1rr3n3ta/src.linux-x86_64-3.7/sec_bimodule.c:335:56: error: ānofoptargsā undeclared (first use in this function)
if (create_cb_arglist(f_capi,f_xa_capi,#maxnofargs#,#nofoptargs#,&f_nofargs,&f_args_capi,āfailed in processing argument list for call-back f.ā)) {
^
/tmp/tmp1rr3n3ta/src.linux-x86_64-3.7/sec_bimodule.c:356:22: warning: passing argument 1 of āf2py_funcā makes pointer from integer without a cast [-Wint-conversion]
(*f2py_func)(f_cptr,&a,&b,&x_tol,&root);
^
/tmp/tmp1rr3n3ta/src.linux-x86_64-3.7/sec_bimodule.c:356:22: note: expected āfloat *ā but argument is of type āintā
If f
is a python function, you need to inform f2py that this is a intent(callback)
argument in the .pyf file. This means the c pointer to the python function gets correctly assigned when wrapping. Is it possible for you to build a MWE and point me to it? I might be able to help via PR.
I have created a separate callback branch: