Boost logo

Boost Users :

Subject: [Boost-users] [uBLAS] Identity Matrix Constructor vs Resize
From: Ryan (mccorywork_at_[hidden])
Date: 2011-03-14 14:51:37


I have an identity matrix that when initialized with the constructor I don't
get an error. If I do a default construction and then resize the matrix I
get a runtime error. I'm not sure the difference. Could someone enlighten
me?

Ryan

using namespace boost::numeric::ublas;

template<typename matrixT>
matrix_range<matrixT> topleft (matrixT & M) { return subrange(M, 0, 3, 0,
3); }

int main(int, char const* []) {
  vector<double> initial(3);
  initial[0] = 10;
   initial[0] = 100;
  initial[0] = 2;

  //I realize that "matrix<double> P(zero_matrix<double>(9,9));" would do
the same thing as below.
  //This is extracted from a class and the constructor needs to to this.
  matrix<double> P; //This is a class variable
  P.resize(9,9); //This happens in the constructor
  P.clear(); //This happens in the constructor

  //The following runs without errors
  //identity_matrix<double> identity(3);

  //This causes a run time error.
  identity_matrix<double> identity;
  identity.resize(3);

  topleft(P) = initial[0] * identity;

  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