Boost logo

Ublas :

From: Nico Galoppo (nico_at_[hidden])
Date: 2006-07-05 08:37:48


Gunter Winkler wrote:
> Ok. Resizing does not do any storage allocation for a sparse type. The
> constructor (size1, size2, nnz) preallocates storage for nnz non zeroes. But
> this is no real problem because the allocation is automatically done in
> "amortized constant time" which means is essentially doubles its storage on
> each allocation step. You can explicitly call reserve(nnz, preserve) to
> adjust the allocated storage.

That's what I thought, but I found that I had to first call resize() explicitly
to avoid crashes when assign()'ing from tmp.

> // untested
> for (size_type i = 0; i < sizeM; ++ i) { // create size1 vector elements
> vector_data_value_type & ref =
> data_.insert_element (i, vector_data_value_type ()) .resize (sizem, false);
> ref.reserve(non_zeros / sizeM);
> }

I get the following error, it seems that my version of insert_element doesn't
return anything. Is there a macro that needs to be defined in order for this to
work?

error C2440: 'initializing' : cannot convert from 'void' to
'boost::numeric::ublas::compressed_vector<T,IB,IA,TA> &'

> This is quite long. You should try to copy the data using C.push_back(i,j,v);
> like I did in http://www.bauv.unibw-muenchen.de/~winkler/ublas/comp_sparse.cpp
> The copy time should be (much) less than the fill time.

I see, thanks for the code. For this, I'll have find out the sparsity pattern of
my matrix first, correct? I guess I could infer it by analyzing the temporary
gvov. Or is iterating over the gvov in an ordered fashion sufficient?

Thanks again,

--nico

-- 
Nico Galoppo           UNC-CH :: ETHZ         http://www.ngaloppo.org
                        +41-77-4319939