Help make boost::multi_array code generic!
I have some code which makes use of boost::multi_array that I would like to make more generic, but I am incapable of groking the error messages. I am hoping some one can shed some light on this. I have a one dimensional array of number which is actually a tensor of variable size. I have a vector (vinfo._sizes) which contains the size of each of the dimensions. In this case, I am using the 3D version. I have another vector (local_subsensors) which contains a specific slice of the 3D view (i.e. reduce the 3D to 2D) that I am seeking or a -1 to mean I want everything in the row/column. I am also given an X/Y variable to return out a specific value from this new 2D matrix. This code works in constructing a view of this type: typedef boost::const_multi_array_ref <double, 3>array_type; array_type::index_gen indices; array_type multi_array (&(vals [0]), vinfo._sizes); if ((local_subsensors [0] == -1) &&(local_subsensors [1] == -1)) { ret_val = (array_type::const_array_view<2>::type (multi_array [indices [range ()][range()][local_subsensors[2]]])) [whichX][whichY]; } else if ((local_subsensors [0] == -1) &&(local_subsensors [2] == -1)) { ret_val = (array_type::const_array_view<2>::type (multi_array [indices [range()][local_subsensors[1]][range()]])) [whichX][whichY]; } else if ((local_subsensors [1] == -1) &&(local_subsensors [2] == -1)) { ret_val = (array_type::const_array_view<2>::type (multi_array [indices [local_subsensors[0]][range ()][range()]])) [whichX][whichY]; } Here's my attempt at making this generic and it does not work. Can someone tell me why? range Dim [3]; for (unsigned int i = 0; i < vinfo._sizes.size(); ++i) if (local_subsensors [i] == -1) Dim [i] =range (); else Dim [i] = range (local_subsensors [i]); slice = multi_array [indices [Dim [0]][Dim [1]][Dim [2]]]; Thanks in advance! Joey
participants (1)
-
Joey Mukherjee