Registered Member
|
I have been tinkering with initializer lists to try and see if there can be slightly more expressive initializations (see https://forum.kde.org/viewtopic.php?f=74&t=123881&p=375217#p375217).
I ran up against a wall that initiailizer_lists must be fully homogeneous, which sucks when you want to try and leverage expression templates. I was curious to see if tuples could be used, and it appears they can. I've implemented a prototype here: https://github.com/EricCousineau-TRI/repro/blob/f19ce9f90d57b05c0b003c161dcf8b6232c5118d/eigen_scratch/matrix_hstack_vstack_xpr_tpl.cc https://github.com/EricCousineau-TRI/repro/blob/f19ce9f90d57b05c0b003c161dcf8b6232c5118d/eigen_scratch/matrix_hstack_vstack_xpr_tpl.output.txt The functionality I was driving for was ragged sub-expression/sub-block concatenation, which may not work for the existing initializer setup except without temporaries, all while maintaining the elegance of EIgen's ability to work with different matrix types. Example from the code (from prior post):
Output:
Note that this does not require the size to be known beforehand. (It makes things slower, but may provide more convenience.) I haven't really checked the performance hit in compilation / evaluation time, but my fingers are crossed that they haven't prevented expression templates from delaying their evaluation until when needed. Additionally, the implementation uses some pretty hefty hacks, such as using the mechanics of std::apply borrowed from C++17. I'll try and post this to the mailing list when I have a chance, if anything to see if (a) it is actually useful, and (b) if it could be incorporated as an experimental / unsupported C++1y feature. |
Moderator
|
Very nice work, this is very interesting and could help dealing with http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1420.
Does it require a very recent compiler with some c++17 features? It would be nice if c++11 would be enough. |
Registered Member
|
I had developed it under clang-3.9 -std=c++1y, and it does break under -std=c++11. However, I think it's possible to refactor if functors are permitted to have template parameters (which I believe should be permissible). I'll try it out in the next week or so and let you know.
Thanks! |
Registered Member
|
It does look to be possible in C++11:
https://gist.github.com/EricCousineau-T ... 72649d33a1 - can be applied on the original file, minus the name. Dirty dirty coding, but works as proof-of-concept. (will push the actual commits soon, presently in a spot that I cannot push to GitHub) I tested this on `clang-3.9 --std=c++11`, and `gcc-4.9 --std=c++11`, and they both compiled and ran identical to the C++1y implementation. The prior C++1y implementation does not work in C++11, hence the changes |
Moderator
|
For the record, I've added a bug entry: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1433
|
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]