Re: [eigen] C++0x initializer lists |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] C++0x initializer lists
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Wed, 2 Jun 2010 10:44:48 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type; bh=iL39ahIrudBB5HUweYFIIN2I/v9l3/YC9hLDrut1quU=; b=ZpTOS+ncnSUzfGzELHigudqVe1hCza/BmB3aK0rS6B2UDSt+0/QcPGCtUMZUdDKavP vA2TTIkr0TME6vSjITXxg4lJoSHb/vBcmXtoMxEVVAVQJTj2jp77w0T7dWjsYj+akd7V g9y4uk8SU1hwYNcqWT5sVyAnaN31T23Dr7/04=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=QkPT/RRAyO9xTYHBAd+hePuZRE3Udoc9DQs+m0sY/N9uLfX4SOXfq2tcef2FNhtBui ttklK/SXfypllnhrsAM+46BhqQzNBAIRGwa0UIReXhqLLi1yefs4TUUNygFg1mlb75Pt /O4H27PSj68yYMB89qz7fNVxh2qPuixCzIIHk=
Hi Ben,
well, first of all we want to support compilers which does not provide any support for C++0x, so any feature based on C++0x has to be optional and not the default.
C++0x's initializer lists are not as general than our comma initializer. Here are the differences:
* C++0x's initializer lists are limited to the initialization of a matrix or vector object by enumerating each coefficient individually. All elements of an initialization list have to be of the same type.
* in addition our comma initializer allows to:
- set the coeffs of any object at any time:
Matrix mat;
mat = foo(...);
mat << a, b, c, d, e, f;
mat.col(i) << a, b, c;
- the elements of the right hand side list can be any _expression_ (heterogeneous):
int rows=5, cols=5;
MatrixXf m(rows,cols);
m << (Matrix3f() << 1, 2, 3, 4, 5, 6, 7, 8, 9).finished(),
MatrixXf::Zero(3,cols-3),
MatrixXf::Zero(rows-3,3),
MatrixXf::Identity(rows-3,cols-3);
cout << m;
output: 1 2 3 0 0
4 5 6 0 0
7 8 9 0 0
0 0 0 1 0
0 0 0 0 1
So definitely, initialization lists cannot be a replacement for our comma initializer. At the very least it could be an additional feature enabled only when C++0x is detected...
gael
On Wed, Jun 2, 2010 at 7:09 AM, Ben Gamari
<bgamari.foss@xxxxxxxxx> wrote:
Hey all,
Has any work been done to implement C++0x's initializer lists in
Eigen? It seems like this would be an excellent cleanup for Eigen 3 and
G++ has supported initializer lists for quite a while now. Comma
initializers have always bothered me, so I for one would be very glad to
see their need disappear. Perhaps later this week I'll take a look at
the source myself if no one else is already looking into the matter.
Cheers,
- Ben