
Ublas : 
From: Gunter Winkler (guwi17_at_[hidden])
Date: 20070306 02:18:53
Am Dienstag, 6. März 2007 07:40 schrieb Sourabh:
> Hi,
> I have a dense vector whose size is not known at the time of
> creation. However, I want to fill entries into the vector. What is
> the most efficient way of doing this ?
repeat
x.resize( 2*x.size(), true );
fill data
gives you amortized constant time for allocation. However, the
stl::vector type is much better optimized for such operations. uBLAS is
optimized for linear algebra, where the sizes are usually known at the
time of creation.
> Also, is there any constant time operation to get the number of
> nonzero elements in a sparse vector ?
A.nnz() returns the number of (structural) nonzeros. If you need the
exact number of nonzeros (excluding the actually stored zeros) you
have to loop over all structural nnzs. (There was a discussion about
that a few month ago on this list.)
mfg
Gunter