Subject: Re: [ublas] Sparse vector
From: Benjamin Sobotta (mayday_at_[hidden])
Date: 2009-06-05 14:54:43
On Friday 05 June 2009 06:52:02 pm John Reid wrote:
> Forgive me if I should have been able to work this out from the
> documentation. I didn't manage that.
> Can you recommend which of mapped, compressed or coordinate vector I
> should use for the following?
> I need a sparse vector over N elements. I will assign values to a subset
> of these elements in an unpredictable order then I need to iterate
> through the non-zero elements (and their indices) in order.
I recommend using compressed_vector. After insertion the non-zero elements can
be retrieved via value_data() and their respective indices (sorted) can be
accessed via index_data(). I usually get the amount of non-zero elements via
However I'm aware of the fact that the boost way to do this is using iterators
suited for the job. However in my application I needed indices and values
separately. Maybe this helps.