Index: matrix_sparse.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/numeric/ublas/matrix_sparse.hpp,v retrieving revision 1.50.2.15 diff -u -p -r1.50.2.15 matrix_sparse.hpp --- matrix_sparse.hpp 29 Oct 2004 12:36:43 -0000 1.50.2.15 +++ matrix_sparse.hpp 22 Mar 2005 13:27:20 -0000 @@ -21,6 +21,8 @@ #include #include +#include // std::lower_bound, std::copy + // Iterators based on ideas of Jeremy Siek namespace boost { namespace numeric { namespace ublas { @@ -2522,6 +2524,30 @@ namespace boost { namespace numeric { na index1_data_ (m.index1_data_), index2_data_ (m.index2_data_), value_data_ (m.value_data_) { storage_invariants (); } + + BOOST_UBLAS_INLINE + compressed_matrix (const coordinate_matrix &m): + matrix_expression (), + size1_ (m.size1()), size2_ (m.size2()), + index1_data_ (layout_type::size1 (size1_, size2_) + 1) + { + m.sort(); + reserve(m.nnz(), false); + filled2_ = m.nnz(); + const_subiterator_type i_start = m.index1_data().begin(); + const_subiterator_type i_end = (i_start + filled2_); + const_subiterator_type i = i_start; + size_type r = 1; + for (; (r < layout_type::size1 (size1_, size2_)) && (i != i_end); ++r) { + i = std::lower_bound(i, i_end, r); + index1_data_[r] = k_based( i - i_start ); + } + filled1_ = r + 1; + std::copy( m.index2_data().begin(), m.index2_data().begin() + filled2_, index2_data_.begin()); + std::copy( m.value_data().begin(), m.value_data().begin() + filled2_, value_data_.begin()); + index1_data_ [filled1_ - 1] = k_based(filled2_); + storage_invariants (); + } template BOOST_UBLAS_INLINE compressed_matrix (const matrix_expression &ae, size_type non_zeros = 0): @@ -2793,6 +2820,12 @@ namespace boost { namespace numeric { na matrix_assign (*this, ae); return *this; } + BOOST_UBLAS_INLINE + compressed_matrix &assign (const coordinate_matrix &ae) { + compressed_matrix m(ae); + assign_temporary(m); + return *this; + } template BOOST_UBLAS_INLINE compressed_matrix& operator += (const matrix_expression &ae) {