C/Python integration

Dec 30, 2013 at 3:11am
I'm trying to compile some C code, which relies on NumPy package, and I'm getting this compile error:

/cuda-convnet-vs-proj/src/util.cu(69): error : identifier "PyArrayObject" is undefined

I installed Anaconda (on Windows), which includes Python 2.7 and Numpy 1.8 package.
util.cu includes header util.cuh, which includes Python.h.

I did some googling, and it appears PyArrayObject should be defined in ndarraytypes.h, however I don't see it there.

Any ideas?
Dec 30, 2013 at 4:38am
PyArrayObject is declared in ndarraytypes.h: https://github.com/numpy/numpy/blob/maintenance/1.8.x/numpy/core/include/numpy/ndarraytypes.h#L690#L701

I don't see ndarraytypes.h included in Python.h. Have you tried including it in your C file?
#include "numpy/ndarraytypes.h"
Last edited on Dec 30, 2013 at 4:38am
Dec 30, 2013 at 6:35am
Yes, that helped, thanks! Now I'm getting a different error:

error : no instance of constructor "Matrix::Matrix" matches the argument list

Here's the offending code:

MatrixV* getMatrixV(PyObject* pyList) {
if (pyList == NULL) {
return NULL;
}
MatrixV* vec = new MatrixV();
for (int i = 0; i < PyList_GET_SIZE(pyList); i++) {
vec->push_back(new Matrix((PyArrayObject*)PyList_GET_ITEM(pyList, i)));
}
return vec;
}

What is the problem here?

Dec 30, 2013 at 8:51pm
First a caveat: I'm a Linux user and know nothing about Visual Studio.

Browsing the cuda-convert source code:
http://code.google.com/p/cuda-convnet/source/browse/trunk/include/common/matrix.h#31
http://code.google.com/p/cuda-convnet/source/browse/trunk/src/common/matrix.cpp#70

It looks like "NUMPY_INTERFACE" was not defined in your build. That is the reason for the error in your first post also. "matrix.h" includes "arrayobject.h" which includes "ndarraytypes.h".

gcc has a command line switch:
-D name "Predefine name as a macro, with definition 1"
which is set in the supplied Makefile (line 12):
http://code.google.com/p/cuda-convnet/source/browse/trunk/Makefile#12

Does VS generate its own make files? If so, is there a way to define NUMPY_INTERFACE?

Alternatively, you can try putting #define NUMPY_INTERFACE at the very top of your C file.

HTH

Edit: grammar
Last edited on Dec 31, 2013 at 12:48am
Jan 6, 2014 at 2:32am
Thanks, #define NUMPY_INTERFACE solved the problem! Sorry about delayed response.

I have a different issue now. I followed all the instructions from this guide:
http://www.asiteof.me/archives/50 and I still get these errors on compile:

1> Creating library .\Win32\Debug\pyconvnet.lib and object .\Win32\Debug\pyconvnet.exp 1>convnet.cu.obj : error LNK2019: unresolved external symbol cublasInit@0 referenced in function "protected: void thiscall ConvNet?::initCuda(void)" (?initCuda@ConvNet?@@IAEXXZ)
1>layer.cu.obj : error LNK2019: unresolved external symbol PyDict_GetItemString? referenced in function "public: thiscall NeuronLayer?::NeuronLayer?(class ConvNet? ,struct object )" (??0NeuronLayer@@QAE@PAVConvNet@@PAU_object@@@Z)






Topic archived. No new replies allowed.