|
Ublas : |
From: Vassilis Virvilis (vasvir_at_[hidden])
Date: 2006-11-04 02:22:35
Gunter Winkler wrote:
> Am Freitag, 3. November 2006 23:16 schrieb Vassilis Virvilis:
>
>>>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.
>
>
> Yes, it must be less than the size.
>
>
>>4) Do we need to take any precautions for
>>compressed_vector::reserve() ?????
>
>
> for sparse types we have to carefully distinguish between resize (change
> logical size) and reserve (actually allocate/free memory). Thus resize
> only has to call reserve if the capacity would be larger than the size.
>
> You can print also v.nnz_capacity() and v.nnz() to verify the effect of
> resize.
sure here it is:
#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;
Ctypedef boost::numeric::ublas::compressed_vector<Real> V;
void printV(const V& v) {
std::cout << "size: " << v.size() << " nnz_Ccapacity: " << v.nnz_capacity() << " nnz: " << v.nnz() << std::endl;
for (uint i = 0; i < v.size(); i++) {
std::cout << i << ":" << v[i] << std::endl;
}
std::cout << "-------------------------" << std::endl;
}
int main(int, char **) {
V v(10);
v[8] = 1;
v[9] = 1;
printV(v);
v.resize(9);
printV(v);
return 0;
}
size: 10 nnz_Ccapacity: 2 nnz: 2
0:0
1:0
2:0
3:0
4:0
5:0
6:0
7:0
8:1
9:1
-------------------------
size: 9 nnz_Ccapacity: 2 nnz: 1
0:0
1:0
2:0
3:0
4:0
5:0
6:0
7:0
8:1
-------------------------
So I think the patch it is ok and should be applied. If there are other problems please
let me know
.bill