Boost logo

Ublas :

Subject: Re: [ublas] Initializing from an initializer_list
From: Nasos Iliopoulos (nasos_i_at_[hidden])
Date: 2013-05-09 11:47:34

I think we should add intializer_lists in the future, since it will help
with containers that need to be created (and initialized) plenty of times.

For other cases uBlas has an advanced facility that can be used to fill
a container using a similar format with initializer lists. It is an
assigner though rather than initialization facility. The good thing is
that it can be used to fill the container with either scalars, vectors
or matrices, navigate while inserting them or define insertion
traversal policies like by row or by column (features that an
initiliazer list cannot have). It also covers special operations for
sparse containers so that the insertion is fast in those cases as well.

You can do this: (A a matrix)
A <<= 0, 1, 2,
          3, 4, 5,
          6, 7, 8;

But also this:
   A <<= 0, 1, 2,
          3, 4, 5; // a is a 3-vector here

or even:
     B <<= A, A,
          A, A;
     std::cout << B << std::endl;
     // [ A A ]
     // [ A A ]

I am still to write the documentation for ublas:assignment but I think
the examples pretty much cover most of the functionality:

The unit tests cover some additional items:

Some benchmarks are here:


On 05/09/2013 09:38 AM, gsermaid wrote:
> Hi all,
> One feature I would really like to see for ublas vectors is the
> ability to initialize them from a std::initializer_list, in a similar
> way to the std::vector.
> This would allow filling in a vector much more easily and help
> creating test cases more quickly. Are there any plans for such a
> functionality in a future ublas release?
> Best regards
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> Sent to: athanasios.iliopoulos.ctr.gr_at_[hidden]