I have a function called DataView that performs the "slicing" (creation of the array_view) as follows:
template <class T>
typename Boost<T>::Array2D::template array_view<2>::type MyArray<T>::DataView(int x_start, int x_finish, int y_start, int y_finish)
{
using range = boost::multi_array_types::index_range;
return _Data[boost::indices[range().start(x_start).finish(x_finish).stride(1)][range().start(y_start).finish(y_finish).stride(1)]];
}
...where _Data is a private member of type Array2D (boost::multi_array) containing the data portion of MyArray. The slicing (view creation) is happening without a problem as follows:
Boost<double>::Array2D::array_view<2>::type array_view = my_array->DataView(x1, x2, y1, y2);
The problem occurs when I want to assign the newly acquired view (array_view) back to the original multi_array (my_array). I have tried to do this by creating this function on the class MyArray:
template <class T>
void MyArray<T>::Data(const typename Boost<T>::Array2D &inData)
{
// find the dimensions of inData
int xdim = static_cast<int>(inData.shape()[0]);
int ydim = static_cast<int>(inData.shape()[1]);
// resize _Data to match the size of inData
_Data.resize(boost::extents[xdim][ydim]);
// assign _Data to the new set of data
_Data = inData;
}
...and calling the function with this line of code...
my_array->Data(array_view);
While the build is successful, my application is producing the following error:
base.hpp:178: Reference boost::detail::multi_array::value_accessor_one<T>::access(boost::type<Reference>, boost::detail::multi_array::value_accessor_one<T>::index, TPtr, const size_type*, const index*, const index*) const [with Reference = double&; TPtr = double*; T = double; boost::detail::multi_array::value_accessor_one<T>::index = long int; boost::detail::multi_array::multi_array_base::size_type = long unsigned int]: Assertion `size_type(idx - index_bases[0]) < extents[0]' failed.
What I really need is a simple example of how I can do one of the following:
- Use my current strategy of creating an array_view from my original multi_array and assigning the new view back to the original array, OR
- Slicing the original multi_array (in place). I've looked for an example of this solution and cannot seem to find it.
Thank you.
This turned out to be something unrelated within my program. I had other variables that were dependent on the dimensions of my array (which had changed due to the reassignment to the view) that I failed to set.