Boost logo

Boost Users :

From: Eric Darve (darve_at_[hidden])
Date: 2008-06-05 17:09:35


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;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net