You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Callback Arguments section of the f2py docs here contains a non-working example.
If we follow the docs and compile the callback.f file using f2py -c -m callback callback.f, the following happens when we try to reproduce the python session:
The expected result was 110. Changing the Fortran file to declare FUN as a REAL*8 argument does the trick (but I don't understand exactly why this is needed and it's not mentioned in the docs)
C FILE: CALLBACK.FSUBROUTINEFOO(FUN,R)
EXTERNAL FUN
INTEGER I
REAL*8 R
REAL*8 FUN
Cf2py intent(out) r
R =0D0DO I=-5,5
R = R + FUN(I)
ENDDOENDC END OF FILE CALLBACK.F
Compile again using f2py -c -m callback callback.f and we get
I'm guessing an explanation of this should be added in the docs. I'm working on updating them but I need help to explain this behaviour. Any input is appreciated!
This looks like a bug in the example. With no explicit declaration of the type for FUN, and no IMPLICIT NONE statement to turn off the old Fortran type conventions, the type of FUN will be REAL (i.e. single precision floating point, also often written REAL*4). f2py, however, apparently assumes FUN will return a double precision value (REAL*8). So your change looks correct.
The example used to work in the past when using g77. Since nowadays nobody uses g77, the example should be fixed for gfortran, that is, declare FUN to be REAL*8. Warren explained the 0.0 result.
For the docs, to avoid this kinds of bugs, recommend using IMPLICIT NONE.
The Callback Arguments section of the f2py docs here contains a non-working example.
If we follow the docs and compile the
callback.f
file usingf2py -c -m callback callback.f
, the following happens when we try to reproduce the python session:The expected result was 110. Changing the Fortran file to declare FUN as a REAL*8 argument does the trick (but I don't understand exactly why this is needed and it's not mentioned in the docs)
Compile again using
f2py -c -m callback callback.f
and we getI'm guessing an explanation of this should be added in the docs. I'm working on updating them but I need help to explain this behaviour. Any input is appreciated!
The text was updated successfully, but these errors were encountered: