Boost logo

Ublas :

From: Sourabh (sourabh_at_[hidden])
Date: 2007-03-06 04:29:29


Please look at the following requirement:
 I have three vectors.
<sparsevector> (Sparse) contains 1 as the only non-zero entry.
<densevector> (Dense)
<othervector> (Dense, superset of <densevector>)

I want to fill the <densevector> with those entries of
<othervector> which are at the indices of non-zero
entries in <sparsevector>. Effectively <sparsevector> contains non-zero
entries as indices for the entries in <othervector> which are to be
filled in <densevector>.

I have written the following code. Can it be optimized ? It is taking
almost 1 second, which is too much.

densevector.resize ((sparsevector.nnz ()));
compressed_vector<double>::const_iterator it = sparsevector.begin ();
    for (unsigned i = 0; it != sparsevector.end (); ++it, ++i) {
        densevector (i) = othervectoer (it.index ());
    }