TypeError when passing 2d numpy array to C++ -
i have two-dimensional data in numpyarray , c++-code want perform action on data. using swig , distutils , numpy.i managed compile python extension "goldstein", provides function unwrap2d. test using
import goldstein data = np.ascontiguousarray(data_temp, dtype='double') mask = np.ascontiguousarray(mask_temp, dtype='uint16') outdata = np.ones_like(data) goldstein.unwrap2d(data,mask,outdata) i typeerror: array cannot safely cast required type. can point me towards how can pass these arrays in right way?
for reference: creating module used interface-file
%define docstring "wrapper c++-code" %enddef %module(docstring=docstring) goldstein %{ #define swig_file_with_init #include "goldstein.h" %} /*include numpy typemaps*/ %include "numpy.i" /*initialize module*/ %init %{ import_array(); %} %rename(unwrap2d) phase_unwrapping_func; /* typemaps arrays*/ %apply (int dim1,int dim2,float* in_array2) {(int xsize,int ysize,float* in)}; %apply (int dim1,int dim2,unsigned short* in_array2) {(int x1,int y1,unsigned short* mask)}; %apply (int dim1,int dim2,float* inplace_array2) {(int x2,int y2,float* out)}; /*wrapper function calling original phase_unwrapping using needed parameters*/ %inline %{ void phase_unwrapping_func(int xsize,int ysize,float* in,int x1,int y1,unsigned short* mask,int x2,int y2,float* out) { phase_unwrapping(xsize, ysize, in, mask, out); } %}
@jaimie right of course. 'float' 'double' 64-bit in numpy, thats why didnt check again, remembered not matter. float in c++ needs 32-bit, in numpy 'float32'. thank you!
Comments
Post a Comment