f2py

Using f2py on a Fortran code linked to PETSc

穿精又带淫゛_ 提交于 2019-12-12 04:28:26
问题 My question is related to this post: Including a compiled module in module that is wrapped with f2py (Minimum working example)? in which the poster was trying to compile a Fortran code (Test.f90) with f2py and link that to a pre-compiled library (or in my case, object, myex44f.o). The answer enabled me to compile the Fortran code and generated the python module. My problem is different from the above posters problem in that my object is linked to PETSc. When I try to import my f2py-generated

How to obtain how much time is spent in f2py wrappers

半腔热情 提交于 2019-12-12 04:16:13
问题 I am currently writing a time consuming python program and decided to rewrite part of the program in fortran. However, the performance is still not good. For profiling purpose, I want to know how much time is spent in f2py wrappers and how much time is actual spent in fortran subroutines. Is there a convenient way to achieve this? 回答1: At last I found out -DF2PY_REPORT_ATEXIT option can report wrapper performance. 来源: https://stackoverflow.com/questions/35968682/how-to-obtain-how-much-time-is

Setting the fortran compiler in f2py

我只是一个虾纸丫 提交于 2019-12-12 03:35:44
问题 I am trying to run the f2py example to create the compiled extension module¶: # import os # os.environ["CC"] = "gcc" # os.environ["CXX"] = "g++" # Using post-0.2.2 scipy_distutils to display fortran compilers from scipy_distutils.fcompiler import new_fcompiler compiler = new_fcompiler() # or new_fcompiler(compiler='intel') compiler.dump_properties() #Generate add.f wrapper from numpy import f2py with open("add.f") as sourcefile: sourcecode = sourcefile.read() print 'Fortran code' print

Why does f2py not include all arguments?

自古美人都是妖i 提交于 2019-12-11 13:57:07
问题 I am attempting to build a python wrap for some fortran code I have using f2py and am experiencing a very odd problem. I am using Python 3.4.3 32 bit, gfortran 4.8.1, and numpy 1.9.2 on Windows 8. f2py compiles the fortran code so I can call it from python. The code has multiple subroutines. Some of them work, but two do not. The important difference seems to be subroutine declaration spanning multiple lines. The working subroutines are declared on a single line. The ones that fail span

Capturing library f2py call stdout from ipython

青春壹個敷衍的年華 提交于 2019-12-11 05:58:17
问题 I'm using Jupyter notebook with a Python 3 kernel. If I run: import scipy.optimize scipy.optimize.minimize( lambda _: 1, 0, method='COBYLA', options={'iprint': 1, 'disp': True, 'maxiter': 2}) I expect to get diagnostic optimization info printed to the ipython notebook. However, this prints to console. I suspect this is the case because the optimization routine is implemented in Fortran, and is interfaced in scipy through f2py. The COBYLA Fortran file does the actual printing. How can I pipe

Strange accuracy difference between ipython and ipython notebook then using fortran module with f2py

試著忘記壹切 提交于 2019-12-11 02:15:19
问题 I'm encountering a strange accuracy difference between ipython and the ipython notebook when using a fortran module compiled with f2py. My fortran module is: subroutine tt(string,fmt,n_num,out) implicit none INTEGER,INTENT(IN)::n_num CHARACTER(LEN=*),INTENT(IN)::string CHARACTER(LEN=*),INTENT(IN)::fmt DOUBLE PRECISION,INTENT(OUT)::out(n_num) read(string,fmt) out end subroutine tt Compiling with: f2py -c -m andre tt.f90 In ipython i get: In [1]: import numpy as np In [2]: import andre In [3]:

Share Fortran 90 module data with F2PY between many extension modules

这一生的挚爱 提交于 2019-12-10 10:16:45
问题 I want to share data which is located in a Fortran 90 module between many self compiled F2PY extension modules. The documentation of F2PY says that this is not possible due to to how Python imports shared libraries in general. F2PY generates wrappers to common blocks defined in a routine signature block. Common blocks are visible by all Fortran codes linked with the current extension module, but not to other extension modules (this restriction is due to how Python imports shared libraries). [

Subroutine argument not passed correctly from Python to Fortran

£可爱£侵袭症+ 提交于 2019-12-10 10:07:06
问题 I am using f2py to compile a numerical module for use by a Python script. I have reduced my code to the minimal example below: fd.f: module fd ! Double precision real kind integer, parameter :: dp = selected_real_kind(15) contains subroutine lprsmf(th) implicit none real(dp) th write(*,*) 'th - fd',th end subroutine lprsmf end module fd itimes.f: subroutine itimes(th) use fd implicit none real(dp) th write(*,*) 'th - it',th call lprsmf(th) end subroutine itimes reprun.py: import it th = 200

How do I compile a Fortran library for use with Python? (f2py may not be an option)

允我心安 提交于 2019-12-10 04:26:39
问题 I'm trying to compile a fortran90 library (specifically this one) in order to call it from python (3.4.0). Generally in this case I would write a wrapper for f2py and call it a day, but the library itself makes use of derived types, which seems to be making f2py fail. The full stderr is pasted here, but the relevent line is getctype: No C-type found in "{'typename': 'optim_type', 'typespec': 'type'}", assuming void. The other option, based on the numpy documentation is to use ctypes, which

what's the overhead of passing python callback functions to Fortran subroutines?

纵饮孤独 提交于 2019-12-10 03:21:12
问题 I just wrapped a Fortran 90 subroutine to python using F2PY. The subtlety here is that the Fortran subroutine aslo takes a python call-back function as one of its arguments: SUBROUTINE f90foo(pyfunc, a) real(kind=8),intent(in) :: a !f2py intent(callback) pyfunc external pyfunc !f2py real*8 y,x !f2py y = pyfunc(x) !*** debug begins*** print *, 'Start Loop' do i=1,1000 p = pyfunc(a) end do total = etime(elapsed) print *, 'End: total=', total, ' user=', elapsed(1), ' system=', elapsed(2) stop !*