python - Issue creating a Numpy NDArray from PyArray_SimpleNewFromData -
i try python wrapper bind c++ functions , types python. issue when try convert custom matrix type numpy ndarray. convincing solution use pyarray_simplenewfromdata
.
to test behaviour, didn't manage wanted tried implement simple test:
pyobject* converttopython(...) { uint8_t test[10] = {12, 15, 82, 254, 10, 32, 0, 8, 127, 54}; int32_t ndims = 1; npy_intp dims[1]; dims[0] = 10; int32_t typenum = (int32_t)npy_ubyte; pyobject* python_object = pyarray_simplenewfromdata(ndims, dims, typenum, (void*)test); py_xincref(python_object); return python_object; }
and got in python these results:
type(test) = <type 'numpy.ndarray'> test.ndim = 1 test.dtype = uint8 test.shape = (10,)
but values inside array are:
test.values = [ 1 0 0 0 0 0 0 0 80 8]
i cannot figure out, doing wrong ? , not experienced doing python wrapper appreciable !
i try array has been allocated malloc, , perhaps settings flag named owndata
in order avoid memory leak.
at least garbage data can explained if instance of numpy.ndarray
not copy data stores pointer supplied array. after functions returns, pointer stack allocated array points memory may change time stack changed.
Comments
Post a Comment