我可以将一维数组传递给python,如下所示.我想知道我是否可以通过使用ctypes,numpy将c ++双指针数组传递给python.
TEST.CPP:
#include <stdio.h>
extern "C" void cfun(const void * indatav, int rowcount, int colcount, void * outdatav);
void cfun(const void * indatav, int rowcount, int colcount, void * outdatav) {
//void cfun(const double * indata, int rowcount, int colcount, double * outdata) {
const double * indata = (double *) indatav;
double * outdata = (double *) outdatav;
int i;
puts("Here we go!");
for (i = 0; i < rowcount * colcount; ++i) {
outdata[i] = indata[i] * …Run Code Online (Sandbox Code Playgroud) 只有numpy才能在cython中调用此函数的最佳方法是什么?我不打算使用ctypes,memcpy,malloc等.
功能1)
#include <stdio.h>
extern "C" void cfun(const void * indatav, int rowcount, int colcount,
void * outdatav);
void cfun(const void * indatav, int rowcount, int colcount, void *
outdatav) {
//void cfun(const double * indata, int rowcount, int colcount,
double * outdata) {
const double * indata = (double *) indatav;
double * outdata = (double *) outdatav;
int i;
puts("Here we go!");
for (i = 0; i < rowcount * colcount; ++i) {
outdata[i] = indata[i] * 4; …Run Code Online (Sandbox Code Playgroud) 我想制作这样的文件,以便在python中使用它.如何从fortran源创建共享库?
我测试过如下代码.
gfortran -c mod.f90
#gfortran -c sub1.f90
gfortran -c func.f90
gfortran -shared -fPIC -o func.so func.f90 mod.o
Run Code Online (Sandbox Code Playgroud)
但是我无法在python中导入它.我在fortran源代码中使用了模块文件.我从python导入了fortran源代码.我不确定我做对了.
[===>14:47:59]f1:python
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import func
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initfunc)
func.f90
-----------------------------------------
program func
use mod_test
switch1 = .true.
switch2 = .false.
x = 1.2
!call test(x, …Run Code Online (Sandbox Code Playgroud) 我可以在fortran模块中声明intent变量吗?我想制作可以称为其他子程序的通用模块
module fmod
real b
integer n, i
integer, dimension(6), intent(inout) :: indata1
real, dimension(7,8), intent(inout) :: indata2
end module fmod
subroutine temp_f(indata1, indata2)
use fmod
do i=1,8
print *, indata4(i)
end do
end
Run Code Online (Sandbox Code Playgroud)