Re: [Boost-users] [uBLAS] iterator for matrix?
You may be looking for the matrix storage container which you can access via matrix<...>::data() like this: #include <boost/numeric/ublas/matrix.hpp> using namespace std; using namespace boost::numeric::ublas; matrix<double> m (3, 3); copy ( m.data().begin(), m.data().end(), ostream_iterator<double>(cout, " ") ); Of course, if you have a sparse matrix, the number of elements referenced by matrix::data() may be lower than the number of elements your matrix normally should have. Also you have no control over the order of elements: they may be stored by row, by column, or in yet another way! Cheers, Stefan
Date: Tue, 11 Mar 2008 14:25:58 +0800 From: "Chung-Lin Wen" <jonathan.clwen@gmail.com> Subject: [Boost-users] [uBLAS] iterator for matrix? To: boost-users@lists.boost.org Message-ID: <eb7d82f30803102325w448b5a81w352bfa71a48b7258@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1"
Hi,
It seems the ublas::matrix don't have begin() and end() that the ordinary STL container would have. It do have begin1(), begin2(), end1(), end2(), but it only traverse a row or a column. So, how could I use the iterators rather than hand-crafted for-loop to traverse the whole matrix?
e.g., copy( matrix.begin(), matrix.end(), ostream_iterator<element_type>(cout, " ") ) ; // ERROR: won't compile: matrix don't have begin & end
(I know matrix have overloaded the operator<<, it's only an example )
participants (1)
-
Lang Stefan