How i can copy existing PyArrayObject ?
I've read documentation from this link http://docs.scipy.org/doc/numpy/reference/c-api.array.html#creating-arrays
Also I've read this explanations: numpy array C api
PyArray_SimpleNewFromData example
I've tried to use PyArray_CopyInto and PyArray_CopyAnyInto with same result (error).
This is my code:
void from_list(PyObject*i_list) {
int x=1;
temp = retrieve(PyList_GetItem(i_list, x)); //list have 3 elements of type PyArrayObject*
}
void retrieve(PyArrayObject* slice) {
PyArrayObject*temp = CopyArray(slice);
}
PyArrayObject*CopyArray(PyArrayObject*obj) {
PyArrayObject*ret;
int nd = obj->nd;
int type_num = obj->descr->type_num;
unsigned char*data;
npy_intp dims[2];
dims[0] = obj->dimensions[0];
dims[1] = obj->dimensions[1];
data = malloc(dims[0]*dims[1] + 100);
memcpy( data, (unsigned char*)obj->data, dims[0]*dims[1] );
printf("\n ready to do \n");
ret = PyArray_SimpleNewFromData(nd, dims, NPY_CHAR, (void*)data); //python interpreter crashes
printf("\n ready to return \n");
return ret;
}
What i'm doing wrong? Also, please, could you give me a link to implementations of all this function of type PyArraySomething.
Thank you.