I have a large 2D multi_array that I need to reduce to a smaller set of data (also 2D). At runtime I have a vector of the column indices that I want to select and put into the sub-array.
I know that you can create a sub-array from the original array using boost::multi_array_types::index_range, but all of the examples I'm seeing use hardcoded ranges. Is there a way to set the index_range at runtime using a vector of values, or is this just not possible in multi_array?
I'm looking to do something like
vector<int> columnIndex; // contains some values
boost::multi_array_types::index_range range;
for(int idx = 0; idx < columnIndex.size(); ++idx)
range = columnIndex[idx];
I looked into the boost code for boost::multi_array_types::index_range, and found that this is not possible. The class has only three members to store index values - start, finish, and stride. It can't store a more complex set of values.
Since the number of columns that I need is dynamic, I used a vector of sub-arrays (array_view),
vector<boost::multi_array_ref<double, 2>::array_view<2>::type::const_reference
and just added to the vector as needed.