Questions tagged [f2py]

F2PY is a tool that provides an interface between the Python and Fortran programming languages.

F2PY is a tool that provides an interface between the and programming languages. F2PY is part of .

491 questions
3
votes
2 answers

How do I concatenate a NULL character to a character array in Fortran to call a c function?

I have the following test function: #include #include void print_string(char *text); void print_string(char *text) { printf("---\n%s\n---\n", text); } And the following module which encapsulates the call with a Fortran…
M.E.
  • 4,955
  • 4
  • 49
  • 128
3
votes
2 answers

F2PY wrap procedure that uses derived types only internally

It is stated in a lot of places that F2PY does not "support derived types", however, it is unclear to me whether this means that either derived types may not be used as parameters to procedures wrapped by F2PY derived types may not even be used…
Christoph90
  • 579
  • 3
  • 12
3
votes
1 answer

How do I build a Python extension module with CMake?

I'm trying to build a Python extension module with CMake and f2py. The module builds just fine, but setuptools can't find it. My build directory looks like…
jhaiduce
  • 408
  • 4
  • 13
3
votes
1 answer

Why does a Fortran function compiled with f2py return zero when I change the name of the result variable?

When I call the following function, it returns 1 as expected: integer function my_func() result(myresult) myresult = 1 end function my_func But when I modify the name of the return value to start with the letter "r" then the function returns 0.…
Paul Wintz
  • 2,542
  • 1
  • 19
  • 33
3
votes
1 answer

Issues running f2py with main .f90 module calling specific .f file? (unknown_subroutine?)

I am trying to use f2py to integrate fortran functions with my main python code. However, when I try to include a specific '.f' file, f2py raises an error (but works fine with other '.f' files). I have created the following minimum working example…
AnAsal
  • 61
  • 7
3
votes
2 answers

Does compiled Fortran library using f2py depend on numpy afterwards?

I have a Fortran 95 code that I want to compile to a Python library using f2py. In a matter of fact I've already done it, and it works beautifully. Does the resulting .pyd (.so) depend on numpy after compilation? Could it be used without numpy…
3
votes
0 answers

How does NumPy use ufunc buffers to speed up sum calculation?

NumPy uses buffers for ufuncs: Internally, buffers are used for misaligned data, swapped data, and data that has to be converted from one data type to another. The size of internal buffers is settable on a per-thread basis. Apparently this buffer…
Matt Hancock
  • 3,870
  • 4
  • 30
  • 44
3
votes
1 answer

Makefile for f2py in python3

In order to build extension modules using f2py in python2, I have been using a Makefile similar to: default: fortran_lib.so %.so:: %.f90 f2py -c -m $* $< For completeness, here is also a dummy fortran_lib.f90 file subroutine…
leopold.talirz
  • 640
  • 7
  • 19
3
votes
1 answer

Inconsistent result when using Fortran function on numpy array with F2PY

I am trying to understand how F2PY works. To do so, I wrote a simple Fortran function which takes an array as input and returns the sum of the elements of the array. I wrote three different versions of the same functions, which I expect to hold the…
valerio
  • 677
  • 4
  • 12
  • 25
3
votes
4 answers

How to pass array of strings to Fortran subroutine using f2py

After some digging online and trial-error, I am still wondering how to passing arrays of strings from Python to Fortran by f2py. I have the Fortran subroutine in string.f90 as: SUBROUTINE FOO(A) CHARACTER*5,dimension(10),intent(inout):: A …
Ting Lei
  • 91
  • 9
3
votes
1 answer

Pass boolean array without copying with `f2py`?

How should Fortran variables be typed if I intend to pass them a boolean, NumPy array with f2py? I have tried both integer*1 and logical*1, but these both indicate that the array is copied. For example, if I compile the file, foo.f95,…
Matt Hancock
  • 3,870
  • 4
  • 30
  • 44
3
votes
0 answers

f2py array dependence on an imported parameter

I'm trying to wrap a sizeable Fortran library in Python. I can modify the source code, but obviously want to modify as little as possible. There are a number of fixed-size arrays defined in the code, with lower and/or upper indices specified by…
Jareth Holt
  • 321
  • 1
  • 10
3
votes
3 answers

f2py: input not fortran contiguous

I wrapped some fortran code with f2py. Here's the fortran code: MODULE iteration implicit none contains SUBROUTINE iterate(alpha, beta, e, es, rank, omega, smearing, prec, max_step) REAL(kind=8), INTENT(in) :: omega, smearing, prec INTEGER…
atbug
  • 818
  • 6
  • 26
3
votes
0 answers

f2py bug or missing library?

I am using f2py to implement some fortran 77 routines. Specifically, I want to implement the column-wise autoscale function for a 2D array. SUBROUTINE AUTOSCALE(E,NR,NC,EA,N,M,MX,SX,SSX) INTEGER NR,NC,N,M,I,J REAL*8…
polgia0
  • 347
  • 1
  • 3
  • 14
3
votes
1 answer

Undefined symbol when importing f2py module, using Python 3

I am trying to compile a minimal Fortran90 subroutine with f2py, to use with Python 3. It is working when I use Python 2.7, but when to import it in a Python 3 file, I get an error message. I need it to work in Python 3. My Fortran…
user1985157