[eigen] const-correctness in Eigen 3.0 |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] const-correctness in Eigen 3.0
- From: Jim Bosch <talljimbo@xxxxxxxxx>
- Date: Mon, 25 Oct 2010 19:18:29 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=AQ4OIsMkMbZc5bZxOXGfknfeDRBQi5ufSGig2arJx20=; b=QEisVtNOzNWRbWHemK27MyoAVXJvLOiOceQ1cVBFOkxiWrmOOyLmv2qXAcLW2f5GI4 vub0aOzLvnuQ+jzmPRSuhIr7vM5TJC8hjaIzBr8Mo40IucC8yVjLIll+q9ShuMnrfpqY x6o17hMA0dtFCGD/KUvGx9EUEQCOK+iY26ebc=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=ZKJMS0EIiMXDk++ZaKftWQinep2a266rwB/rMCR84vAylYuORSS1CTJCAuL8UO1RV5 434IZhrC/p9XLgAdDIrvBUKmcbGNqtuSjL1+qAD6K3OGstwGmHruQrO3dYGhR6QIvB3U 29f4RSVlVVromvhQLFE6uKp6CrnMdHXClPpII=
I've been following the occasional discussions regarding the
const-incorrectness of Map (and Block, Transpose, etc.) with interest; I
once put a lot of effort into getting this right in my own
template-based multidimensional array library, and I'd love to see this
get fixed in Eigen.
I'd be happy to put some effort into fixing this in Eigen 3.0, but as a
relatively new face (well, I've been lurking a long time!) tackling a
fairly widely-dispersed issue, I wanted to get some discussion going
instead of just going out and making a giant patch.
First off, here's what I think the solution should look like:
- Matrix and Array (and other PlainObjectBase subclasses) should
pretty much behave as they do currently.
- Map, Block, Transpose, and anything else that does not own its data
but supports direct access should come in both const and non-const
versions (probably just partial specializations). The non-const version
should be implicitly convertible to the const version.
- Calling block() or transpose() on a const reference to Matrix should
return a const Block or const Transpose(), etc.
What I think this implies:
- MatrixBase, ArrayBase, DenseBase, DenseCoeffsBase, and EigenBase
should also have partial specializations for const and non-const; the
non-const version should probably inherit from the const version in some
cases for code reuse, just adding non-const accessors and augmented
assignment operators.
- PlainObjectBase should inherit from a non-const base class.
- Expressions that don't have direct access should inherit from the
const MatrixBase or ArrayBase.
- There should probably be a flag for constness on every Eigen class.
I anticipate these changes would be fairly straightforward, but they are
very extensive. I don't seen any easier way to get const-correctness in
place in a consistent way, however, and I think doing it now will pay
off in the long run.
Any thoughts?
Jim Bosch