简体   繁体   English

如何使用指针将numpy数组传递给C ++ / SWIG而不依赖于numpy.i?

[英]How do I pass a numpy array to C++/SWIG using pointers without relying on numpy.i?

Is there a way to pass a numpy array into C++/SWIG by just using a pointer to the first element? 有没有办法通过使用指向第一个元素的指针将numpy数组传递给C ++ / SWIG? I have a C++ function that anticipates a 3-by-N matrix, which is expected to be stored in column-major indexed contiguous memory. 我有一个预期3-by-N矩阵的C ++函数,预计将存储在列主索引的连续内存中。 Therefore, the function call takes the following parameters: 因此,函数调用采用以下参数:

( double *mat3Xin, double *mat3Xout, int numTrip)

where numTrip is the N dimension of the matrix (ie number of triplets). 其中numTrip是矩阵的N维(即三元组的数量)。 Since the input and inplace output is the same size, I do not require that to be passed in. Is there a way to easily handle this in SWIG without using swig's renaming inline feature and creating a helper function which accepts the additional parameters swig's numpy interface requires for matrices? 由于输入和输入的输出大小相同,我不需要传入。有没有办法在SWIG中轻松处理它而不使用swig的重命名内联功能并创建一个辅助函数来接受附加参数swig的numpy接口需要矩阵? I'm currently raveling the matrices in a helper function which then calls a renamed version of the original function, however, it is starting to get tedious to convert all the functions in my existing library to this form. 我正在调整辅助函数中的矩阵,然后调用原始函数的重命名版本,但是,将现有库中的所有函数转换为此形式变得乏味。

Thanks, 谢谢,

也许这是不可能的,我坚持使用这些函数的手写界面: http//docs.scipy.org/doc/numpy/reference/swig.interface-file.html#a-common-example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM