Boost logo

Ublas :

From: Sourabh (sourabh_at_[hidden])
Date: 2007-03-06 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
> > non-zero elements in a sparse vector ?
>
> A.nnz() returns the number of (structural) non-zeros. If you need the
> exact number of non-zeros (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 non-zero 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