New user self-registration is currently disabled. Please email eigen-core-team @ if you need an account.
Bug 178 - Remove const on nested expressions, and remove const_cast in mutators
Remove const on nested expressions, and remove const_cast in mutators
Status: NEW
Product: Eigen
Classification: Unclassified
Component: Core - expression templates
All All
: --- Unknown
Assigned To: Nobody
Depends on:
Blocks: 3.4
  Show dependency treegraph
Reported: 2011-02-06 18:08 UTC by Benoit Jacob
Modified: 2016-01-28 21:12 UTC (History)
3 users (show)


Description Benoit Jacob 2011-02-06 18:08:45 UTC
Currently expressions tend to store their nested expressions as const, for example at src/Core/Block.h:344, in class Block:

    const typename XprType::Nested m_xpr;

Consequently, mutators have to call const_cast_derived() on the nested expression.

This seems stupid and seems like something we want to fix for Eigen 3.1. By storing nested expressions with their own native constness, we could also drop those const_cast's.
Comment 1 Hauke Heibel 2011-02-06 18:15:23 UTC
Here is a list of all remaining occurrences:

Core\DiagonalProduct.h(110): const typename MatrixType::Nested m_matrix;
Core\DiagonalProduct.h(111): const typename DiagonalType::Nested m_diagonal;
Core\IO.h(118): const typename ExpressionType::Nested m_matrix;
Core\PermutationMatrix.h(514): const typename IndicesType::Nested m_indices;
Core\PermutationMatrix.h(611): const typename MatrixType::Nested m_matrix;
Core\Replicate.h(127): const typename MatrixType::Nested m_matrix;
Core\Reverse.h(187): const typename MatrixType::Nested m_matrix;
Core\Select.h(105): const typename ConditionMatrixType::Nested m_condition;
Core\Select.h(106): const typename ThenMatrixType::Nested m_then;
Core\Select.h(107): const typename ElseMatrixType::Nested m_else;
Core\SolveTriangular.h(265): const typename Rhs::Nested m_rhs;
Core\Transpositions.h(337): const typename IndicesType::Nested m_indices;
Core\Transpositions.h(407): const typename MatrixType::Nested m_matrix;
Eigen2Support\Minor.h(98): const typename MatrixType::Nested m_matrix;
Eigenvalues\Tridiagonalization.h(563): const typename MatrixType::Nested m_matrix;
Geometry\Homogeneous.h(124): const typename MatrixType::Nested m_matrix;
Geometry\Homogeneous.h(270): const typename LhsMatrixType::Nested m_lhs;
Geometry\Homogeneous.h(271): const typename MatrixType::Nested m_rhs;
Geometry\Homogeneous.h(309): const typename MatrixType::Nested m_lhs;
Geometry\Homogeneous.h(310): const typename Rhs::Nested m_rhs;
misc\Solve.h(69): const typename Rhs::Nested m_rhs;
Sparse\SparseBlock.h(99): const typename MatrixType::Nested m_matrix;
Sparse\SparseBlock.h(195): const typename MatrixType::Nested m_matrix;
Sparse\SparseBlock.h(359): const typename MatrixType::Nested m_matrix;
Sparse\SparseSelfAdjointView.h(151): const typename MatrixType::Nested m_matrix;

Should we remove the const from all of them!?
Comment 2 Benoit Jacob 2011-02-06 18:19:18 UTC
Yes, I think so, unless you see a reason not to.

My 'business plan' for 3.1 is 3 phases:

1. make this kind of big sweeping changes to clean up and stabilize our internals (most important is bug 99)
2. document our internals: write good developer documentation
3. work on remaining 3.1 blockers while new people start reading about our internals and can much better help us than they could before
4. ???
5. profit
Comment 3 Gael Guennebaud 2012-03-26 18:12:42 UTC
for the record several have been "magically" removed already, still remains:

Eigen/src/Core/Block.h:    const typename XprType::Nested m_xpr;
Eigen/src/Core/IO.h:    const typename ExpressionType::Nested m_matrix;
Eigen/src/Core/Transpositions.h:    const typename IndicesType::Nested m_indices;
Eigen/src/Eigen2Support/Minor.h:    const typename MatrixType::Nested m_matrix;
Eigen/src/misc/SparseSolve.h:    const typename Rhs::Nested m_rhs;
Eigen/src/misc/SparseSolve.h:    const typename Guess::Nested m_guess;
Eigen/src/SparseCore/SparseBlock.h:    const typename MatrixType::Nested m_matrix;

since this is not critial -> 3.2
Comment 4 Gael Guennebaud 2013-07-11 23:49:40 UTC
no need to delay 3.2 for that.
Comment 5 Gael Guennebaud 2016-01-28 21:12:49 UTC
Summary:     Bug 178: remove additional const on nested expression, and remove several const_cast.

Good enough for 3.3.

Note You need to log in before you can comment on or make changes to this bug.