SWIG C/C++;python接口
我有以下C文件(ezrange.C): 和SWIG接口文件(ezrange.i): 和安装文件(setup.py): 我汇编如下: swig-pythonezrange.i python3 setup.py build\u ext--就地 当我启动python3时,我得到:SWIG C/C++;python接口,python,c++,c,swig,Python,C++,C,Swig,我有以下C文件(ezrange.C): 和SWIG接口文件(ezrange.i): 和安装文件(setup.py): 我汇编如下: swig-pythonezrange.i python3 setup.py build\u ext--就地 当我启动python3时,我得到: >>> import ezrange >>> ezrange.range(3, 5) [array([ 0., 1., 2.]), array([ 0., 2., 4., 6.,
>>> import ezrange
>>> ezrange.range(3, 5)
[array([ 0., 1., 2.]), array([ 0., 2., 4., 6., 8.])]
>>>
我缺少双返回值(3.14)。如何在python中获得该值
谢谢 我构建了您的代码,但得到了
[3.14,array([0,1,2.])、array([0,2,4,6,8.])]
作为输出。正如预期的那样…输出数组应该附加到正常的输出值上。您使用的是哪个版本的SWIG?我的系统上有一个相当旧的2.0.12。我构建了您的代码,但得到了[3.14,数组([0,1,2.]),数组([0,2,4,6,8.])]
作为输出。正如预期的那样…输出数组应该附加到正常的输出值。您使用的是哪个版本的SWIG?我的系统上有一个相当旧的2.0.12。
double range(double *v1, int n1, double *v2, int n2);
%module ezrange
%{
#define SWIG_FILE_WITH_INIT
#include "ezrange.h"
%}
%include "numpy.i"
%init %{
import_array();
%}
%apply (double* ARGOUT_ARRAY1, int DIM1) {(double* v1, int n1), (double* v2, int n2)}
%include "ezrange.h"
#! /usr/bin/env python
# System imports
from distutils.core import *
from distutils import sysconfig
# Third-party modules - we depend on numpy for everything
import numpy
# Obtain the numpy include directory. This logic works across numpy versions.
try:
numpy_include = numpy.get_include()
except AttributeError:
numpy_include = numpy.get_numpy_include()
# ezrange extension module
_ezrange = Extension("_ezrange",
["ezrange.i","ezrange.c"],
include_dirs = [numpy_include],
)
# ezrange setup
setup( name = "range function",
description = "range takes an integer and returns an n element int array where each element is equal to its index",
author = "Egor Zindy",
version = "1.0",
ext_modules = [_ezrange]
)
>>> import ezrange
>>> ezrange.range(3, 5)
[array([ 0., 1., 2.]), array([ 0., 2., 4., 6., 8.])]
>>>