resize() in boost/multi_array.hpp

Hi, I found what I think is a bug in boost/multi_array.hpp. Perhaps some of you can explain what is wrong. Look at the code below. When executed you get the following error: multi_array_ref.hpp:487: failed assertion `std::equal(other.shape(),other.shape()+this->num_dimensions(), this->shape())' This is caused by the line x.resize(extents[n+1][3]); It seems to me that the code is correct and should work properly. Curiously if one adds x[i][j].resize(extents[0][0]); before x.resize(extents[n+1][3]), the error message disappears. I also added another piece of code at the end showing that if one replaces multi_array< multi_array<int,2>, 2> x; by multi_array< vector<int>, 2> y; then the resize seems to work. The code was run on MacOSX with g++. Eric #include "boost/multi_array.hpp" #include <vector> using boost::multi_array; using boost::extents; using std::vector; int main(void) { const int n = 10; multi_array< multi_array<int,2>, 2> x; x.resize(extents[n][3]); for (int i=0;i<n;++i) { for (int j=0;j<3;++j) { x[i][j].resize(extents[i+1][2]); // Size varies with i } } for (int i=0;i<n;++i) { for (int j=0;j<3;++j) { // x[i][j].resize(extents[0][0]); /* failed assertion below disappears if line above is un-commented */ } } x.resize(extents[n+1][3]); /* Failed assertion when executing line above: multi_array_ref.hpp:487: failed assertion `std::equal(other.shape(),other.shape()+this->num_dimensions(), this->shape())' */ // Attempting a similar operation using vector<int> this time multi_array< vector<int>, 2> y; y.resize(extents[n][3]); for (int i=0;i<n;++i) { for (int j=0;j<3;++j) { y[i][j].resize(i+1); } } y.resize(extents[n+1][3]); /* This instruction executes fine */ return 0; }

AMDG Eric Darve wrote:
Hi,
I found what I think is a bug in boost/multi_array.hpp. Perhaps some of you can explain what is wrong. Look at the code below. When executed you get the following error: multi_array_ref.hpp:487: failed assertion `std::equal(other.shape(),other.shape()+this->num_dimensions(), this->shape())'
This is caused by the line x.resize(extents[n+1][3]);
This seems to be by design. Multiarray doesn't have normal assignment semantics. #include "boost/multi_array.hpp" #include <vector> using boost::multi_array; using boost::extents; using std::vector; int main(void) { multi_array<int, 1> x(boost::extents[2]), y; y = x; } In Christ, Steven Watanabe
participants (2)
-
Eric Darve
-
Steven Watanabe