diff options
author | Gael Guennebaud <g.gael@free.fr> | 2014-10-07 18:29:28 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2014-10-07 18:29:28 +0200 |
commit | 57413492948d4c9dd6572f5bde6720b80122054a (patch) | |
tree | 22c8b070d5f929c32428e562505a27f704d978eb | |
parent | 118b1113d9a4fa1a263597cdd699e237e5f2b4ac (diff) |
bug #882: fix various const-correctness issues with *View classes.
-rw-r--r-- | Eigen/src/CholmodSupport/CholmodSupport.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseUnaryView.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/SelfAdjointView.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/TriangularMatrix.h | 18 | ||||
-rw-r--r-- | Eigen/src/SparseCholesky/SimplicialCholesky.h | 8 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseMatrixBase.h | 4 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseSelfAdjointView.h | 4 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseTriangularView.h | 4 |
8 files changed, 25 insertions, 24 deletions
diff --git a/Eigen/src/CholmodSupport/CholmodSupport.h b/Eigen/src/CholmodSupport/CholmodSupport.h index 0c3b86dd2..3eadb83a0 100644 --- a/Eigen/src/CholmodSupport/CholmodSupport.h +++ b/Eigen/src/CholmodSupport/CholmodSupport.h @@ -105,7 +105,7 @@ const cholmod_sparse viewAsCholmod(const SparseMatrix<_Scalar,_Options,_Index>& /** Returns a view of the Eigen sparse matrix \a mat as Cholmod sparse matrix. * The data are not copied but shared. */ template<typename _Scalar, int _Options, typename _Index, unsigned int UpLo> -cholmod_sparse viewAsCholmod(const SparseSelfAdjointView<SparseMatrix<_Scalar,_Options,_Index>, UpLo>& mat) +cholmod_sparse viewAsCholmod(const SparseSelfAdjointView<const SparseMatrix<_Scalar,_Options,_Index>, UpLo>& mat) { cholmod_sparse res = viewAsCholmod(mat.matrix().const_cast_derived()); diff --git a/Eigen/src/Core/CwiseUnaryView.h b/Eigen/src/Core/CwiseUnaryView.h index 61fd8ee35..6384dfdc3 100644 --- a/Eigen/src/Core/CwiseUnaryView.h +++ b/Eigen/src/Core/CwiseUnaryView.h @@ -37,7 +37,8 @@ struct traits<CwiseUnaryView<ViewOp, MatrixType> > typedef typename MatrixType::Nested MatrixTypeNested; typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested; enum { - Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | LvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions + FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0, + Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret, // need to cast the sizeof's from size_t to int explicitly, otherwise: // "error: no integral type can represent all of the enumerator values @@ -63,7 +64,7 @@ class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename in EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView) typedef typename internal::remove_all<MatrixType>::type NestedExpression; - explicit inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp()) + explicit inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp()) : m_matrix(mat), m_functor(func) {} EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView) diff --git a/Eigen/src/Core/SelfAdjointView.h b/Eigen/src/Core/SelfAdjointView.h index f5fbd7215..1c44d9c9a 100644 --- a/Eigen/src/Core/SelfAdjointView.h +++ b/Eigen/src/Core/SelfAdjointView.h @@ -38,7 +38,8 @@ struct traits<SelfAdjointView<MatrixType, UpLo> > : traits<MatrixType> typedef typename MatrixType::PlainObject FullMatrixType; enum { Mode = UpLo | SelfAdjoint, - Flags = MatrixTypeNestedCleaned::Flags & (HereditaryBits) + FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0, + Flags = MatrixTypeNestedCleaned::Flags & (HereditaryBits|FlagsLvalueBit) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit)) // FIXME these flags should be preserved }; }; @@ -95,6 +96,7 @@ template<typename _MatrixType, unsigned int UpLo> class SelfAdjointView EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index col) { + EIGEN_STATIC_ASSERT_LVALUE(SelfAdjointView); Base::check_coordinates_internal(row, col); return m_matrix.const_cast_derived().coeffRef(row, col); } diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index 263d54485..055ed7514 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -173,7 +173,8 @@ struct traits<TriangularView<MatrixType, _Mode> > : traits<MatrixType> typedef MatrixType ExpressionType; enum { Mode = _Mode, - Flags = (MatrixTypeNestedCleaned::Flags & (HereditaryBits | LvalueBit) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit))) + FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0, + Flags = (MatrixTypeNestedCleaned::Flags & (HereditaryBits | FlagsLvalueBit) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit))) }; }; } @@ -213,7 +214,7 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView // FIXME This, combined with const_cast_derived in transpose() leads to a const-correctness loophole EIGEN_DEVICE_FUNC - explicit inline TriangularView(const MatrixType& matrix) : m_matrix(matrix) + explicit inline TriangularView(MatrixType& matrix) : m_matrix(matrix) {} using Base::operator=; @@ -229,14 +230,9 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView const NestedExpression& nestedExpression() const { return m_matrix; } EIGEN_DEVICE_FUNC NestedExpression& nestedExpression() { return *const_cast<NestedExpression*>(&m_matrix); } - - typedef TriangularView<MatrixConjugateReturnType,Mode> ConjugateReturnType; - /** \sa MatrixBase::conjugate() */ - EIGEN_DEVICE_FUNC - inline ConjugateReturnType conjugate() - { return ConjugateReturnType(m_matrix.conjugate()); } + /** \sa MatrixBase::conjugate() const */ - + typedef TriangularView<const MatrixConjugateReturnType,Mode> ConjugateReturnType; EIGEN_DEVICE_FUNC inline const ConjugateReturnType conjugate() const { return ConjugateReturnType(m_matrix.conjugate()); } @@ -253,7 +249,8 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView inline TransposeReturnType transpose() { EIGEN_STATIC_ASSERT_LVALUE(MatrixType) - return TransposeReturnType(m_matrix.const_cast_derived().transpose()); + typename MatrixType::TransposeReturnType tmp(m_matrix.const_cast_derived()); + return TransposeReturnType(tmp); } typedef TriangularView<const typename MatrixType::ConstTransposeReturnType,TransposeMode> ConstTransposeReturnType; @@ -392,6 +389,7 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularViewImpl<_Mat EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index col) { + EIGEN_STATIC_ASSERT_LVALUE(TriangularViewType); Base::check_coordinates_internal(row, col); return derived().nestedExpression().const_cast_derived().coeffRef(row, col); } diff --git a/Eigen/src/SparseCholesky/SimplicialCholesky.h b/Eigen/src/SparseCholesky/SimplicialCholesky.h index 0e8fa6628..918a34e13 100644 --- a/Eigen/src/SparseCholesky/SimplicialCholesky.h +++ b/Eigen/src/SparseCholesky/SimplicialCholesky.h @@ -237,8 +237,8 @@ template<typename _MatrixType, int _UpLo, typename _Ordering> struct traits<Simp typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Index Index; typedef SparseMatrix<Scalar, ColMajor, Index> CholMatrixType; - typedef TriangularView<CholMatrixType, Eigen::Lower> MatrixL; - typedef TriangularView<typename CholMatrixType::AdjointReturnType, Eigen::Upper> MatrixU; + typedef TriangularView<const CholMatrixType, Eigen::Lower> MatrixL; + typedef TriangularView<const typename CholMatrixType::AdjointReturnType, Eigen::Upper> MatrixU; static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); } static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); } }; @@ -251,8 +251,8 @@ template<typename _MatrixType,int _UpLo, typename _Ordering> struct traits<Simpl typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Index Index; typedef SparseMatrix<Scalar, ColMajor, Index> CholMatrixType; - typedef TriangularView<CholMatrixType, Eigen::UnitLower> MatrixL; - typedef TriangularView<typename CholMatrixType::AdjointReturnType, Eigen::UnitUpper> MatrixU; + typedef TriangularView<const CholMatrixType, Eigen::UnitLower> MatrixL; + typedef TriangularView<const typename CholMatrixType::AdjointReturnType, Eigen::UnitUpper> MatrixU; static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); } static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); } }; diff --git a/Eigen/src/SparseCore/SparseMatrixBase.h b/Eigen/src/SparseCore/SparseMatrixBase.h index f96042f27..04baabe4f 100644 --- a/Eigen/src/SparseCore/SparseMatrixBase.h +++ b/Eigen/src/SparseCore/SparseMatrixBase.h @@ -297,9 +297,9 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> Derived& operator*=(const SparseMatrixBase<OtherDerived>& other); template<int Mode> - inline const TriangularView<Derived, Mode> triangularView() const; + inline const TriangularView<const Derived, Mode> triangularView() const; - template<unsigned int UpLo> inline const SparseSelfAdjointView<Derived, UpLo> selfadjointView() const; + template<unsigned int UpLo> inline const SparseSelfAdjointView<const Derived, UpLo> selfadjointView() const; template<unsigned int UpLo> inline SparseSelfAdjointView<Derived, UpLo> selfadjointView(); template<typename OtherDerived> Scalar dot(const MatrixBase<OtherDerived>& other) const; diff --git a/Eigen/src/SparseCore/SparseSelfAdjointView.h b/Eigen/src/SparseCore/SparseSelfAdjointView.h index 247d4e6d3..5da7d2bef 100644 --- a/Eigen/src/SparseCore/SparseSelfAdjointView.h +++ b/Eigen/src/SparseCore/SparseSelfAdjointView.h @@ -170,9 +170,9 @@ template<typename MatrixType, unsigned int _Mode> class SparseSelfAdjointView template<typename Derived> template<unsigned int Mode> -const SparseSelfAdjointView<Derived, Mode> SparseMatrixBase<Derived>::selfadjointView() const +const SparseSelfAdjointView<const Derived, Mode> SparseMatrixBase<Derived>::selfadjointView() const { - return SparseSelfAdjointView<Derived, Mode>(derived()); + return SparseSelfAdjointView<const Derived, Mode>(derived()); } template<typename Derived> diff --git a/Eigen/src/SparseCore/SparseTriangularView.h b/Eigen/src/SparseCore/SparseTriangularView.h index e200bc815..1f5e53155 100644 --- a/Eigen/src/SparseCore/SparseTriangularView.h +++ b/Eigen/src/SparseCore/SparseTriangularView.h @@ -266,10 +266,10 @@ protected: template<typename Derived> template<int Mode> -inline const TriangularView<Derived, Mode> +inline const TriangularView<const Derived, Mode> SparseMatrixBase<Derived>::triangularView() const { - return TriangularView<Derived, Mode>(derived()); + return TriangularView<const Derived, Mode>(derived()); } } // end namespace Eigen |