Boost logo

Ublas :

Subject: Re: [ublas] Accessing the indices of non-zero elements in a UBLAS sparse vector
From: John Reid (j.reid_at_[hidden])
Date: 2011-09-23 06:03:09


On 23/09/11 09:54, Oswin Krause wrote:
> Hi,
>
> i already answered your question.
Sorry for making you repeat yourself. However see below.

You can only convert iterators to
> const_iterators, but not the other way around (this is also true for all
> std collections). The way to do it is:
>
> for( mapped_vector< double>::const_iterator i = cv.begin(); i !=
> cv.end(); ++i ) {
> std::cout<< i.index()<< " : "<< *i<< "\n";
> cv(i.index()) += 1;//access *i using the index in cv
> }
>
> a bit prettier and for most compilers not slower in release mode.
>

If cv is a mapped vector then isn't cv(i.index()) going to be O(log N)?
I already have an iterator to the element, I would rather change it in
constant time. Is there a recommended way to do this?

Thanks,
John.