Boost logo

Ublas :

Subject: [ublas] manipulating matrix columns / rows
From: David Mebane (mebane_at_[hidden])
Date: 2010-12-23 14:24:50


Hello,

I have just started (trying to) work with ublas, and have hit a wall. I
have written the following test code:

#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_of_vector.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/matrix_expression.hpp>
#include <boost/numeric/ublas/vector_expression.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/storage.hpp>

int main()
{

  using namespace boost::numeric::ublas;

  typedef generalized_vector_of_vector<double, row_major,
vector<vector<double > > > gvv_t;

  gvv_t a;
  typedef gvv_t::iterator1 gvi1_t;
  typedef gvv_t::iterator2 gvi2_t;

  a.resize(10,10);

  int i=0;
  for (gvi1_t it1=a.begin1(); it1 != a.end1(); ++it1) {
    for (gvi2_t it2=it1.begin(); it2 != it1.end(); ++it2) {
      *it2 = (double) i;
      ++i;
    }
  }
  matrix_column<gvv_t> av(a,0);

  std::cout << a << std::endl << av << std::endl;

  for (matrix_column<gvv_t>::iterator av_it=av.begin(); av_it != av.end();
++av_it)
  *av_it = 1.0;

  vector<double> v(10), w(10);
  typedef vector<double>::iterator vi_t;
  for (vi_t v_it=v.begin(), w_it=w.begin();
       w_it != w.end();
       ++v_it, ++w_it) {
    *v_it = 0.0;
    *w_it = 1.0;
  }

  v += 2*w;
  std::cout << v << std::endl;

  // av += v;
  //std::cout << a << std::endl << av << std::endl;

  return 0;

}

Using gcc 4.4.1, this compiles without error or warning, but upon execution
(in debug mode), it prints the first output, then throws an exception:

Check failed in file /usr/include/boost/numeric/ublas/vector.hpp at line
464:
&(*this) () == &it ()
terminate called after throwing an instance of
'boost::numeric::ublas::external_logic'
  what(): external logic
Aborted

When I comment out the loop over the matrix_column object and uncomment the
two final lines in the above, I similarly compile successfully, but upon
execution get the first two outputs and then:

Check failed in file /usr/include/boost/numeric/ublas/vector.hpp at line
363:
&(*this) () == &it ()
terminate called after throwing an instance of
'boost::numeric::ublas::external_logic'
  what(): external logic
Aborted

I've checked the referenced lines in vector.hpp, but I'm afraid that doesn't
help me much.

Also, is there a searchable archive for this list anywhere?

I appreciate the help, and seasons' greetings.
-David