Boost logo

Ublas :

From: Vassilis Virvilis (vasvir_at_[hidden])
Date: 2006-06-28 13:46:42


Hi,

Consider the simple c++ program
---------------
#include <iostream>

#include <boost/numeric/ublas/vector_sparse.hpp>

using namespace boost::numeric;
typedef double Real;

//typedef ublas::mapped_vector<Real> SparseVector;
//typedef ublas::coordinate_vector<Real> SparseVector;
typedef ublas::compressed_vector<Real> SparseVector;

int main(int, char **)
{
     SparseVector a(3);
     a[0] = 1;
     a[1] = 2;
     a[2] = -3;

     // ublas::compressed_vector the resize is not preserving
     std::cout << a[0] << " " << a[1] << " " << a[2] << std::endl;
     a.resize(4);
     std::cout << a[0] << " " << a[1] << " " << a[2] << std::endl;

     return 0;
}
--------------

The resize doesn't work (asserts) due to
[Ôåô Éïýí 28 20:38:04 ~/src/boost-tests 571]$./compressed_resize
1 2 -3
Assertion failed in file /usr/include/boost/numeric/ublas/vector_sparse.hpp at line 868:
!preserve
compressed_resize: /usr/include/boost/numeric/ublas/vector_sparse.hpp:868: void boost::numeric::ublas::compressed_vector<T, IB, IA, TA>::resize(typename IA::value_type, bool) [with T = double, unsigned int IB = 0u, IA = boost::numeric::ublas::unbounded_array<unsigned int, std::allocator<unsigned int> >, TA = boost::numeric::ublas::unbounded_array<double, std::allocator<double> >]: Assertion `0' failed.
Áêõñþèçêå (core dumped)

with NDEBUG it compiles but doesn't preserve the vector's contents.
[Ôåô Éïýí 28 20:42:41 ~/src/boost-tests 573]$./compressed_resize
1 2 -3
0 0 0

By looking at sparse_vector.hpp one can see the compressed_vector::resize()
is not implemented for the preserving case. How difficult is this to be implemented?
Looks easy enough but then why it hasn't been implemented so far?

        .bill

PS: I am not subscribed in the list. Please keep me in the TO or the CC headers.