|[eigen] Best practices for accessing named regions within a larger array?|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: Eigen development <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] Best practices for accessing named regions within a larger array?
- From: Rhys Ulerich <rhys.ulerich@xxxxxxxxx>
- Date: Mon, 21 Nov 2011 17:05:55 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=aG09ccPUyaxcRWYKNspaCm556eYXy9Hz8ZtqDGlYCMA=; b=GMzfJLGkSXJrr3wNyVdaMCjv6wqwxIdQDQhMwtJZTPkyXCXfHHmtJV0PM9yifjC4nl REBsuhfUZYJ4pKFW/MhlIcVun+lOUbYcZfUXLgeBqAxcqSVTxvhcjKQKJi5uDdo+4ZzM GeEdlDzOpaQWXR0VNiK+fJ6XG1e8GF/cXTDs4=
I keep running into use cases where I'd like to have a contiguous
array cut up into "named" subarrays of varying widths.
As a simplistic example, say I want Array<double, Dynamic, 5> to have
the leftmost column named "rho", the next three columns named "rhou",
and the final column named "rhoe". That is, I'd like I'd like
foo.rho() to mean foo.leftCols<1>(), foo.rhou() to mean
foo.middleCols<3>(1), and foo.rhoe() to mean foo.rightCols<1>().
Having named regions within contiguous storage happens to be handy
within my simulation code for both memory access patterns and
Accomplishing this by using either inheritance or containment of an
Eigen::Array instance and then adding inlined members is
straightforward, of course. But both requires error-prone boilerplate
if the number of named views becomes large. That error-prone
boilerplate can be traded for macros (a la Boost.Preprocessor) at the
expense of readability.
I've not yet found a simple, clean, extensible way to produce such
views methods. Any suggestions or solutions that you've found