multi_array : using double** from 3rd party lib
Hello, I have a 3rd party library which exposes a function that takes a double** data argument. I looked into its source and saw that they use this notation data[i][j] with i and j varying from imin to imax and j from jmin to jmax Now I have a boost::multi_array<double, 7> marray and I have 2 dimensions that are given to me by the user at runtime, between 0 and 6. They may be contiguous or not. and I wish to pass the "subarray" as a double** argument and call their function .It's not possible, is it? I am actually able to override their function that takes in a double** data. Can it work then? regards,
I have a 3rd party library which exposes a function that takes a double** data argument. I looked into its source and saw that they use this notation data[i][j] with i and j varying from imin to imax and j from jmin to jmax
Now I have a boost::multi_array<double, 7> marray ... and I wish to pass the "subarray" as a double** argument and call their function. It's not possible, is it?
I do not think it is directly possible without some work. It sounds like you've got pointers-to-pointers a la [1]. You could probably recreate the double** information you need from the subarray, however, and pass that in.
I am actually able to override their function that takes in a double** data.
Can it work then?
Then it will depend a lot on the underlying implementation. - Rhys [1] http://www.fftw.org/fftw3.3alpha_doc/Dynamic-Arrays-in-C_002dThe-Wrong-Way.h...
and I wish to pass the "subarray" as a double** argument and call their function .It's not possible, is it?
you have to create the array of pointers: double trace(double** arr){ double ret=0; for(unsigned i=0; i!=4; ++i){ ret+=arr[i][i]; } return ret; } int main(){ boost::multi_array<double, 7> a(boost::extents[2][2][2][2][2][4] [4]); a[1][1][1][1][1][0][0]=8; a[1][1][1][1][1][3][3]=3; double** sarr=new double*[4]; for(unsigned i=0; i!=4; ++i){ sarr[i]=(&a[1][1][1][1][1][i][0]); } std::cout<< trace( sarr ) <<std::endl; //outputs 11 return 0; } , but probably you wanted something simpler.
I am actually able to override their function that takes in a double** data.
Can it work then?
If you can "override" (sic) the function that takes the data, can't you just replace by some multi_array<double, 2>, if there is no pointer arithmetic in the function then that it is easy to do. right? Alfredo
participants (3)
-
alfC
-
Hicham Mouline
-
Rhys Ulerich