f2py

Using F2Py with OpenACC gives import error in Python

自闭症网瘾萝莉.ら 提交于 2020-05-15 11:23:01
问题 I am writing a simple test code to see how I could wrap a fortran code containing openacc regions and call from python. Here's the code. module test use iso_c_binding, only: sp => C_FLOAT, dp => C_DOUBLE, i8 => C_INT implicit none contains subroutine add (a, b, n, c) integer(kind=i8), intent(in) :: n real(kind=dp), intent(in) :: a(n) real(kind=dp), intent(in) :: b(n) real(kind=dp), intent(out) :: c(n) integer(kind=i8) :: i !$acc enter data create(a, b, c) do i = 1, n c(i) = a(i) + b(i) end do

Using F2Py with OpenACC gives import error in Python

我只是一个虾纸丫 提交于 2020-05-15 11:21:10
问题 I am writing a simple test code to see how I could wrap a fortran code containing openacc regions and call from python. Here's the code. module test use iso_c_binding, only: sp => C_FLOAT, dp => C_DOUBLE, i8 => C_INT implicit none contains subroutine add (a, b, n, c) integer(kind=i8), intent(in) :: n real(kind=dp), intent(in) :: a(n) real(kind=dp), intent(in) :: b(n) real(kind=dp), intent(out) :: c(n) integer(kind=i8) :: i !$acc enter data create(a, b, c) do i = 1, n c(i) = a(i) + b(i) end do

Installing numpy before using numpy.distutils.core.setup

匆匆过客 提交于 2020-03-20 12:46:48
问题 I am using numpy.distutils to setup a package (mypackage) that has a frotran module. The problem is that if I do pip install mypackage on an environment that does not have numpy, I get the following error: ModuleNotFoundError: No module named 'numpy' The easy solution is to ask users (if I manage to have any) to pip install numpy before they install my package, but I do not think this is a very elegant solution. I came up with the idea of calling setuptools.setup with only setup_requires=[

f2py linking quadmath libraries? Use ctypes for fortran wrapper instead?

十年热恋 提交于 2020-01-25 08:00:09
问题 Update 11/23/2019: This started out as a question about why I could not get f2py to work for a simple fortran wrapper. My "answer" (below) is to use ctypes instead. Original post: I have spent the last three days trying to use f2py to interface fortran to python. I am working on windows using both cygwin and mingw. This post is about using cygwin, but I'm concerned about conflicts between the two. Here is the source multxy.f90: subroutine multxy(x,y,z) integer, parameter :: flt = selected

Fortran double precision converted to Python float

余生颓废 提交于 2020-01-16 05:04:44
问题 I have the following subroutine in generation.f90 SUBROUTINE generation(t, prob) IMPLICIT NONE INTEGER, INTENT(IN) :: t REAL(8), INTENT(OUT) :: prob INTEGER :: nT2, c Do some stuff with t, nT2 and c prob = nT2/(DBLE(1.0)*c) END SUBROUTINE generation I want to use it in Python, so I wrap it with f2py f2py -c -m generation generation.f90 --fcompiler=gnu95 Then in ipython I do from generation import * a = generation(10000); type(a) and I get float . I checked the C file testmodule.c generated

f2py complication due parameter array dimensions being defined in modules / common blocks

喜你入骨 提交于 2020-01-16 04:46:27
问题 I have the following subroutine in Fortran 90: subroutine foo(bar) use spam ! dimension n is defined in the module spam implicit none real*8 bar(n) .... end subroutine foo Since the array dimension n is defined in module spam , I am getting errors during the compilation of the C wrapper functions (generated by f2py ), like error: ‘n’ undeclared (first use in this function) Because the C wrapper function does not have any reference to spam or n . What should be the solution to this? I am

F2PY cannot find intel fortran compiler on windows 7

北城以北 提交于 2020-01-14 03:29:06
问题 I am struggling to get F2PY working with Intel Fortran on Windows 7. This appears to be a common issue and I have attempted a number of suggestions found in other posts (described below). A bit of information about my system: Windows 7 64-bit Python 2.7.11 via Enthought Canopy 32-bit (up to date as of June 12, 2016) Intel Fortran 14 (Intel\Composer XE 2013 SP1) (32 and 64-bit) After doing a bit of research see here I found that the issue may be related to the c++ runtime so I installed

setup.py for packages that depend on both cython and f2py

浪尽此生 提交于 2020-01-11 23:00:53
问题 I would like to create a setup.py script for a python package with several submodules that depend on both cython and f2py. I have attempted to use setuptools and numpy.distutils, but have so far failed: Using setuptools I am able to compile my cython extensions (and create an installation for the rest of the package) using setuptools. I have, however, been unable to figure out how to use setuptools to generate the f2py extension. After extensive searching, I only found rather old messages

setup.py for packages that depend on both cython and f2py

匆匆过客 提交于 2020-01-11 22:59:12
问题 I would like to create a setup.py script for a python package with several submodules that depend on both cython and f2py. I have attempted to use setuptools and numpy.distutils, but have so far failed: Using setuptools I am able to compile my cython extensions (and create an installation for the rest of the package) using setuptools. I have, however, been unable to figure out how to use setuptools to generate the f2py extension. After extensive searching, I only found rather old messages

Errors when using a Fortran call back function in f2py

那年仲夏 提交于 2020-01-07 05:34:24
问题 I am writing a code in python that exploits a Fortran 90 optimization algorithm. The idea is to have the MAIN routine in python that calls the algorithm in Fortran that calls another python function passing some parameters in order to calculate the value of an objective function (that is, it returns a scalar), like this: [Python) MAIN ⇒ [Fortran] BB_algo ⇒ [Python] FUNCT Such problem should be solved by using the f2py libraries in python. In order to try to make such method work I have