diff options
author | Gael Guennebaud <g.gael@free.fr> | 2015-06-09 23:11:24 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2015-06-09 23:11:24 +0200 |
commit | feaf76c00103df5f0ae2d7a365a91f70253922cd (patch) | |
tree | 3846bcf95648a0e619cbc658bdd8ebe60edd6723 /Eigen/src/SparseCore/SparseRef.h | |
parent | f899aeb301f758218b8d126a7165f7e31fcc7cf7 (diff) |
bug #910: add a StandardCompressedFormat option to Ref<SparseMatrix> to enforce standard compressed storage format.
If the input is not compressed, then this trigger a copy for a const Ref, and a runtime assert for non-const Ref.
Diffstat (limited to 'Eigen/src/SparseCore/SparseRef.h')
-rw-r--r-- | Eigen/src/SparseCore/SparseRef.h | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/Eigen/src/SparseCore/SparseRef.h b/Eigen/src/SparseCore/SparseRef.h index 2ca039323..8df62a119 100644 --- a/Eigen/src/SparseCore/SparseRef.h +++ b/Eigen/src/SparseCore/SparseRef.h @@ -12,6 +12,10 @@ namespace Eigen { +enum { + StandardCompressedFormat = 2 +}; + namespace internal { template<typename Derived> class SparseRefBase; @@ -72,6 +76,19 @@ protected: } // namespace internal + +/** + * \ingroup Sparse_Module + * + * \brief A sparse matrix expression referencing an existing sparse expression + * + * \tparam PlainObjectType the equivalent sparse matrix type of the referenced data + * \tparam Options specifies whether the a standard compressed format is required \c Options is \c #StandardCompressedFormat, or \c 0. + * The default is \c 0. + * \tparam StrideType Only used for dense Ref + * + * \sa class Ref + */ template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> class Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType > : public internal::SparseRefBase<Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType > > @@ -93,6 +110,7 @@ class Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType > inline Ref(SparseMatrix<MatScalar,OtherOptions,MatIndex>& expr) { EIGEN_STATIC_ASSERT(bool(Traits::template match<SparseMatrix<MatScalar,OtherOptions,MatIndex> >::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); + eigen_assert( ((Options & int(StandardCompressedFormat))==0) || (expr.isCompressed()) ); Base::construct(expr.derived()); } @@ -100,6 +118,7 @@ class Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType > inline Ref(MappedSparseMatrix<MatScalar,OtherOptions,MatIndex>& expr) { EIGEN_STATIC_ASSERT(bool(Traits::template match<SparseMatrix<MatScalar,OtherOptions,MatIndex> >::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); + eigen_assert( ((Options & int(StandardCompressedFormat))==0) || (expr.isCompressed()) ); Base::construct(expr.derived()); } @@ -112,6 +131,7 @@ class Ref<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType > { EIGEN_STATIC_ASSERT(bool(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); + eigen_assert( ((Options & int(StandardCompressedFormat))==0) || (expr.isCompressed()) ); Base::construct(expr.const_cast_derived()); } }; @@ -148,7 +168,15 @@ class Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType template<typename Expression> void construct(const Expression& expr,internal::true_type) { - Base::construct(expr); + if((Options & int(StandardCompressedFormat)) && (!expr.isCompressed())) + { + m_object = expr; + Base::construct(m_object); + } + else + { + Base::construct(expr); + } } template<typename Expression> |