
Ublas : 
From: Sourabh (sourabh_at_[hidden])
Date: 20070306 02:58:04
On Tue, 6 Mar 2007, Gunter Winkler wrote:
> 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.
>
If I use x.resize (), there is a chance that some of the extra entries
remain in the vector, which I don't want.
Is there any way by which I careate stl vector, fill that, and assign the
contents of stl vector to uBLAS vector at the time of creation ? In uBLAS
vector interface I could not find such thing.
> > 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.)
The iterator on the sparse vector will allow me to iterate over the nnz
entries, I suppose. I can get their indices by index ()
function on iterator. My requirement is to create a dense vector out of
the nonzero elements of the sparse vector. I think, I can give the size
of the dense vector to be equal to A.nnz ().
Thanks for this help.
> mfg
> Gunter
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>
  Sourabh