[f2py] Optional callback arguments difficulty
Pearu Peterson
pearu at cens.ioc.ee
Thu Aug 7 16:41:02 EEST 2008
On Thu, August 7, 2008 4:11 pm, Mika, David P (GE, Research) wrote:
> I'm not sure if this went through yesterday--I just joined f2py-users
> today.
>
> I am having trouble with callback arguments that are rendered optional.
> I have included a bare-bones example by making a simple modification to
> the canonical callback example by simply not calling the external
> function in the .f routine and adding "optional f" to the .pyf file.
> The error I get is also shown.
I am not sure how/whether f2py should handle optional callback arguments.
Basically, a Fortran subroutine needs a function pointer as
an argument but when user does not specify the callback
function then it is not clear what function the Fortran subroutine
should recieve --- it must recieve something.
You should somehow specify the default callback function.
There is no simple solution to this problem, so, I wonder
if you actually would not need such a feature? If you really needed,
then could you provide a more realistic examples (containing the default
implementation of the callback function) and I am sure that we can
make the example work.
Pearu
>
> Thanks in advance,
> Dave
>
>
>
> callback_optional.f
> --------------------------------------
> C FILE: CALLBACK.F
> SUBROUTINE FOO(FUN,R)
> EXTERNAL FUN
> INTEGER I
> REAL*8 R
> Cf2py intent(out) r
> R = 0D0
> DO I=-5,5
> R = R + I
> ENDDO
> END
> C END OF FILE CALLBACK.F
>
> --------------------------------------
> bash-3.2$ cat callback2_optional.pyf
> ! -*- f90 -*-
> python module __user__routines
> interface
> function fun(i) result (r)
> integer :: i
> real*8 :: r
> end function fun
> end interface
> end python module __user__routines
>
> python module callback2_optional
> interface
> subroutine foo(f,r)
> use __user__routines, f=>fun
> external f
> optional f
> real*8 intent(out) :: r
> end subroutine foo
> end interface
> end python module callback2_optional
>
> ------------------------------------------
>
>>>> import callback2_optional
>>>> print callback2_optional.foo.__doc__
> foo - Function signature:
> r = foo([f,f_extra_args])
> Optional arguments:
> f : call-back function => fun
> f_extra_args := () input tuple
> Return objects:
> r : float
> Call-back functions:
> def fun(i): return r
> Required arguments:
> i : input int
> Return objects:
> r : float
>
>>>> print callback2_optional.foo()
> Call-back argument must be
> function|instance|instance.__call__|f2py-function but got NoneType.
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> callback2_optional.error: failed in processing argument list for
> call-back f.
>>>>
>
>
>
> _______________________________________________
> f2py-users mailing list
> f2py-users at cens.ioc.ee
> http://cens.ioc.ee/mailman/listinfo/f2py-users
>
More information about the f2py-users
mailing list