Boost logo

Ublas :

From: Sourabh (sourabh_at_[hidden])
Date: 2007-03-07 05:58:10


On Wed, 7 Mar 2007, Vardan Akopian wrote:

> I think this is a perfect case to use index_data as Gunter suggested
> before. So the loop in your FillOmegas() would become:
> for (unsigned i = 0, iEnd = pathgatevector.filled(); i < iEnd; ++i) {
> omegas (i) = othervector(pathgatevector.index_data()[i]);
> }
> On my machine, this reduces the runtime from 1 minute to 0.26 (using
> the arguments 100000 1000 to your program)
>
> -Vardan
>

Can you please tell me what is the reason by which this approach is
getting performance improvement over the following way ?

   compressed_vector<double>::const_iterator it = pathgatevector.begin ();
   for (unsigned i = 0; it != pathgatevector.end (); ++it, ++i) {
               omegas (i) = othervector(it.index ());
    }
     
In both the cases, <omegas> is resized to pathgatevector.nnz(), already.

Can we do a comparative study of these two examples and say why one
approach is running in less time ?