Boost logo

Ublas :

From: Vassilis Virvilis (vasvir_at_[hidden])
Date: 2006-11-03 17:16:32


Gunter Winkler wrote:

Gunter,

Thank you for your prompt reply.

> Am Freitag, 3. November 2006 18:52 schrieb Vassilis Virvilis:
>
>>Is there any non obvious reason why this simple patch
>>can't be applied in
>>boost/numeric/ublas/vector_sparse.hpp ?
>

Ok I 'll give it a try. If you guide me through I think I 'll manage it.

>
> AFAIK there was simply no one who implemented it.
>
> about your patch:
>
> 1st: you should also drop the line
> BOOST_UBLAS_CHECK (!preserve, internal_logic ());
> if the preserve logic is implemented.

ok
>
> 2nd: If the new size is smaller than the old size, some (old) index
> values may be too large and you should reduce filled_ such that
> zero_based( index_data_[filled_-1] ) <= size;

I think it < size and not <= size. Please verify.

> (we should add this check to storage_invariants, too)

These are just some sanity checks.

4) Do we need to take any precautions for compressed_vector::reserve() ?????

Testing

I am using the following test program

// -------------------------------------------------------
#include <iostream>

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

typedef double Real;
//typedef boost::numeric::ublas::mapped_vector<Real> V;
//typedef boost::numeric::ublas::coordinate_vector<Real> V;
typedef boost::numeric::ublas::compressed_vector<Real> V;

int main(int, char **) {

   V v(10);

   v[8] = 1;
   v[9] = 1;
   v.resize(9);

   for (uint i = 0; i < v.size(); i++) {
      std::cout << i << ":" << v[i] << std::endl;
   }

   return 0;
}

// ------------- output ---------------
0:0
1:0
2:0
3:0
4:0
5:0
6:0
7:0
8:1

which looks ok.

What do you think about this try?

       .bill