gpt4 book ai didi

c++ - 用于 python 列表的 SWIG typemap to double *

转载 作者:太空宇宙 更新时间:2023-11-04 04:52:44 26 4
gpt4 key购买 nike

如何在 swig 中使用 typemap 转换 python 列表。例如:

lst = [1.0,2.0,3.3] (Python list)

传递给

void print_arg(double *lst){} (c/c++ function)

我如何为此编写 swig 接口(interface)文件。

最佳答案

执行此操作的一种方法是使用 SWIG、carrays 和 cpointer

示例代码是:

SWIG 界面

%include "carrays.i"
%array_class(double, doubleArray);

Python模块

LEVEL = 3
thre = [1, 100, 10000]
a = example.doubleArray(LEVEL)
for i in xrange(LEVEL):
a[i] = thre[i]

gd=example.GradedDouble(LEVEL,a)

以上是我的工作示例...根据您的目的相应地更改代码...

关于c++ - 用于 python 列表的 SWIG typemap to double *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13523574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com