Boost logo

Ublas :

Subject: Re: [ublas] submatrix with indexvector
From: Nasos Iliopoulos (nasos_i_at_[hidden])
Date: 2010-07-29 08:26:55


This will work, but for some reason the indirect_array has the contradiction that although it provides only const iterators (hence doesn't allow you to change the data in the container), it does return non-const reference (so you can change the container by indexing or by std algorithms using Ralf's suggestion).

I am not sure about the design decision and whether this should be filed as a bug (the indirect_array concept declares the iterator constant as well, so why return non-const reference?). If the concept is to be made consistent, non-const reference may not be allowed (your code and Ralf's may not work in the future).

On the other hand if constness is forced, it may break many peoples' code. After all why should the indirect_array be immutable? Maybe the simplest thing is that we just provide regular iterators and change the concept as well.

Nevertheless, what seems like complying with the concept and I find unlikely to change is:

ublas::indirect_array<vector_type> ia(data.size(), data);
used like:

#include <boost/numeric/ublas/storage.hpp>
#include <vector>

namespace ublas = boost::numeric::ublas;

typedef std::vector<std::size_t> vector_type;

int main() {
    vector_type data;

    for (std::size_t i=0; i!=10; i++) data.push_back(i);

    ublas::indirect_array<vector_type> ia(data.size(), data);
    for (std::size_t i=0; i!=10; i++) std::cout << ia(i) << std::endl;

    return 0;


> Date: Thu, 29 Jul 2010 08:48:52 +0200
> From: Ralf.Denzer_at_[hidden]
> To: ublas_at_[hidden]
> Subject: Re: [ublas] submatrix with indexvector
> Hi Philipp,
> > ublas::indirect_array<> l_idx(data.size());
> > std::copy(data.begin(), data.end(), l_idx.begin());
> I do usually:
> std::copy(data.begin(), data.end(), &l_idx(0));
> Bye
> Ralf
> ___________________________________________________________
> WEB.DE DSL ab 19,99 Euro/Monat. Bis zu 150,- Euro Startguthaben und
> 50,- Euro Geldprämie inklusive!
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> Sent to: nasos_i_at_[hidden]