|
Ublas : |
Subject: Re: [ublas] Accessing the indices of non-zero elements in a UBLAS sparse vector
From: Oswin Krause (Oswin.Krause_at_[hidden])
Date: 2011-09-23 06:53:41
Hi,
maybe i have to correct myself, my information seems to be outdated.
the source code for mapped_vector::iterator states:
BOOST_UBLAS_INLINE
iterator &operator ++ () {
++ it_;
return *this;
}
BOOST_UBLAS_INLINE
reference operator * () const {
BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ());
return (*it_).second;
}
So it should work out of the box without the index workaround. Sorry for
the inconvenience caused...finally i can beatify some of my own code :)
(after i have checked whether this is also true for the sparse matrices.
unfortunately, THAT code is a mess).
The worst thing about ublas is the completely inexistent documentation.
And i'm terrible sorry that my previous mails added to the amount of wrong
information which cna be found via google :(
Greetings,
Oswin
>
>
> 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.
>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: Oswin.Krause_at_[hidden]
>