使用 SWIG 的几个 numpy 数组

发布于 2024-08-29 11:45:51 字数 385 浏览 2 评论 0原文

我正在使用 SWIG 将 numpy 数组从 Python 传递到 C++ 代码:

%include "numpy.i"
%init %{
import_array();
%}

%apply (float* INPLACE_ARRAY1, int DIM1) {(float* data, int n)};

class Class 
{
  public: 
  void test(float* data, int n)
  {
    //...
  }
};

在 Python 中:

c = Class()
a = zeros(5)
c.test(a)

这可行,但如何将多个 numpy 数组传递给同一个函数?

I am using SWIG to pass numpy arrays from Python to C++ code:

%include "numpy.i"
%init %{
import_array();
%}

%apply (float* INPLACE_ARRAY1, int DIM1) {(float* data, int n)};

class Class 
{
  public: 
  void test(float* data, int n)
  {
    //...
  }
};

and in Python:

c = Class()
a = zeros(5)
c.test(a)

This works, but how can I pass multiple numpy arrays to the same function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转角预定愛 2024-09-05 11:45:51

我从同事那里找到了答案:

%apply (float* INPLACE_ARRAY1, int DIM1) {(float* data1, int n1), (float* data2, int n2)};

class Class 
{
  public: 
  void test(float* data1, int n1, float* data2, int n2)
  {
    //...
  }
};

现在两个 numpy 数组被传递给 Class::test。

I found out the answer from a collegue of mine:

%apply (float* INPLACE_ARRAY1, int DIM1) {(float* data1, int n1), (float* data2, int n2)};

class Class 
{
  public: 
  void test(float* data1, int n1, float* data2, int n2)
  {
    //...
  }
};

Now two numpy arrays are passed to Class::test.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文