diff options
author | Gael Guennebaud <g.gael@free.fr> | 2014-06-25 17:23:52 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2014-06-25 17:23:52 +0200 |
commit | b868bfb84a4a86231bb338e9bcf08afd882d32dc (patch) | |
tree | 29f019cbbe4f5821fc41c6f2358961fc99c7c7e0 /Eigen | |
parent | 3b19b466a7609fd381db2c53569d4d1d1621dbfc (diff) |
Make operator=(EigenBase<>) uses the new assignment mechanism and introduce a generic EigenBase to EigenBase assignment kind based on the previous evalTo mechanism.
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Core/Assign.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/AssignEvaluator.h | 21 | ||||
-rw-r--r-- | Eigen/src/Core/BandMatrix.h | 23 | ||||
-rw-r--r-- | Eigen/src/Core/CoreEvaluators.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/DiagonalMatrix.h | 21 | ||||
-rw-r--r-- | Eigen/src/Core/PermutationMatrix.h | 2 | ||||
-rw-r--r-- | Eigen/src/Householder/HouseholderSequence.h | 12 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseAssign.h | 20 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseBlock.h | 16 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseMatrixBase.h | 2 |
10 files changed, 111 insertions, 15 deletions
diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h index abbba84c3..071cfbf7e 100644 --- a/Eigen/src/Core/Assign.h +++ b/Eigen/src/Core/Assign.h @@ -611,7 +611,7 @@ template <typename OtherDerived> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const EigenBase<OtherDerived>& other) { - other.derived().evalTo(derived()); + internal::call_assignment(derived(), other.derived()); return derived(); } diff --git a/Eigen/src/Core/AssignEvaluator.h b/Eigen/src/Core/AssignEvaluator.h index 77b4dd9bc..c45ac96f2 100644 --- a/Eigen/src/Core/AssignEvaluator.h +++ b/Eigen/src/Core/AssignEvaluator.h @@ -663,7 +663,9 @@ template<typename DstShape, typename SrcShape> struct AssignmentKind; // Assignement kind defined in this file: struct Dense2Dense {}; +struct EigenBase2EigenBase {}; +template<typename,typename> struct AssignmentKind { typedef EigenBase2EigenBase Kind; }; template<> struct AssignmentKind<DenseShape,DenseShape> { typedef Dense2Dense Kind; }; // This is the main assignment class @@ -750,8 +752,12 @@ void call_assignment_no_alias(Dst& dst, const Src& src, const Func& func) // TODO check whether this is the right place to perform these checks: EIGEN_STATIC_ASSERT_LVALUE(Dst) EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(ActualDstTypeCleaned,Src) - EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar); + // TODO this line is commented to allow matrix = permutation + // Actually, the "Scalar" type for a permutation matrix does not really make sense, + // perhaps it could be void, and EIGEN_CHECK_BINARY_COMPATIBILIY could allow micing void with anything...? +// EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar); + Assignment<ActualDstTypeCleaned,Src,Func>::run(actualDst, src, func); } template<typename Dst, typename Src> @@ -772,6 +778,19 @@ struct Assignment<DstXprType, SrcXprType, Functor, Dense2Dense, Scalar> } }; +// Generic assignment through evalTo. +// TODO: not sure we have to keep that one, but it helps porting current code to new evaluator mechanism. +template< typename DstXprType, typename SrcXprType, typename Functor, typename Scalar> +struct Assignment<DstXprType, SrcXprType, Functor, EigenBase2EigenBase, Scalar> +{ + static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar> &/*func*/) + { + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); + + src.evalTo(dst); + } +}; + } // namespace internal } // end namespace Eigen diff --git a/Eigen/src/Core/BandMatrix.h b/Eigen/src/Core/BandMatrix.h index ffd7fe8b3..ba4749707 100644 --- a/Eigen/src/Core/BandMatrix.h +++ b/Eigen/src/Core/BandMatrix.h @@ -327,6 +327,29 @@ class TridiagonalMatrix : public BandMatrix<Scalar,Size,Size,Options&SelfAdjoint protected: }; + +#ifdef EIGEN_TEST_EVALUATORS + +struct BandShape {}; + +template<typename _Scalar, int _Rows, int _Cols, int _Supers, int _Subs, int _Options> +struct evaluator_traits<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> > + : public evaluator_traits_base<BandMatrix<_Scalar,_Rows,_Cols,_Supers,_Subs,_Options> > +{ + typedef BandShape Shape; +}; + +template<typename _CoefficientsType,int _Rows, int _Cols, int _Supers, int _Subs,int _Options> +struct evaluator_traits<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> > + : public evaluator_traits_base<BandMatrixWrapper<_CoefficientsType,_Rows,_Cols,_Supers,_Subs,_Options> > +{ + typedef BandShape Shape; +}; + +template<> struct AssignmentKind<DenseShape,BandShape> { typedef EigenBase2EigenBase Kind; }; +#endif + + } // end namespace internal } // end namespace Eigen diff --git a/Eigen/src/Core/CoreEvaluators.h b/Eigen/src/Core/CoreEvaluators.h index 81b4d63bf..f9f229b09 100644 --- a/Eigen/src/Core/CoreEvaluators.h +++ b/Eigen/src/Core/CoreEvaluators.h @@ -32,10 +32,7 @@ struct storage_kind_to_evaluator_kind { template<typename StorageKind> struct storage_kind_to_shape; -template<> -struct storage_kind_to_shape<Dense> { - typedef DenseShape Shape; -}; +template<> struct storage_kind_to_shape<Dense> { typedef DenseShape Shape; }; // Evaluators have to be specialized with respect to various criteria such as: // - storage/structure/shape @@ -507,7 +504,7 @@ protected: // -------------------- CwiseUnaryView -------------------- template<typename UnaryOp, typename ArgType> -struct unary_evaluator<CwiseUnaryView<UnaryOp, ArgType> > +struct unary_evaluator<CwiseUnaryView<UnaryOp, ArgType>, IndexBased> : evaluator_base<CwiseUnaryView<UnaryOp, ArgType> > { typedef CwiseUnaryView<UnaryOp, ArgType> XprType; diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index ba0042ba4..fc9ecf561 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -44,6 +44,8 @@ class DiagonalBase : public EigenBase<Derived> EIGEN_DEVICE_FUNC DenseMatrixType toDenseMatrix() const { return derived(); } + +#ifndef EIGEN_TEST_EVALUATORS template<typename DenseDerived> EIGEN_DEVICE_FUNC void evalTo(MatrixBase<DenseDerived> &other) const; @@ -55,6 +57,7 @@ class DiagonalBase : public EigenBase<Derived> EIGEN_DEVICE_FUNC void subTo(MatrixBase<DenseDerived> &other) const { other.diagonal() -= diagonal(); } +#endif // EIGEN_TEST_EVALUATORS EIGEN_DEVICE_FUNC inline const DiagonalVectorType& diagonal() const { return derived().diagonal(); } @@ -122,6 +125,7 @@ class DiagonalBase : public EigenBase<Derived> #endif }; +#ifndef EIGEN_TEST_EVALUATORS template<typename Derived> template<typename DenseDerived> void DiagonalBase<Derived>::evalTo(MatrixBase<DenseDerived> &other) const @@ -129,6 +133,8 @@ void DiagonalBase<Derived>::evalTo(MatrixBase<DenseDerived> &other) const other.setZero(); other.diagonal() = diagonal(); } +#endif // EIGEN_TEST_EVALUATORS + #endif /** \class DiagonalMatrix @@ -376,6 +382,21 @@ struct evaluator_traits<DiagonalWrapper<Derived> > static const int AssumeAliasing = 0; }; +struct Diagonal2Dense {}; + +template<> struct AssignmentKind<DenseShape,DiagonalShape> { typedef Diagonal2Dense Kind; }; + +// Diagonal matrix to Dense assignment +template< typename DstXprType, typename SrcXprType, typename Functor, typename Scalar> +struct Assignment<DstXprType, SrcXprType, Functor, Diagonal2Dense, Scalar> +{ + static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar> &/*func*/) + { + dst.setZero(); + dst.diagonal() = src.diagonal(); + } +}; + } // namespace internal #endif // EIGEN_ENABLE_EVALUATORS diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index 61aa0ce31..4399e1d64 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -803,6 +803,8 @@ struct evaluator_traits<Transpose<PermutationBase<Derived> > > static const int AssumeAliasing = 0; }; +template<> struct AssignmentKind<DenseShape,PermutationShape> { typedef EigenBase2EigenBase Kind; }; + } // end namespace internal #endif // EIGEN_TEST_EVALUATORS diff --git a/Eigen/src/Householder/HouseholderSequence.h b/Eigen/src/Householder/HouseholderSequence.h index d800ca1fa..99d3eb21f 100644 --- a/Eigen/src/Householder/HouseholderSequence.h +++ b/Eigen/src/Householder/HouseholderSequence.h @@ -73,6 +73,18 @@ struct traits<HouseholderSequence<VectorsType,CoeffsType,Side> > }; }; +#ifdef EIGEN_TEST_EVALUATORS + +struct HouseholderSequenceShape {}; + +template<typename VectorsType, typename CoeffsType, int Side> +struct evaluator_traits<HouseholderSequence<VectorsType,CoeffsType,Side> > + : public evaluator_traits_base<HouseholderSequence<VectorsType,CoeffsType,Side> > +{ + typedef HouseholderSequenceShape Shape; +}; +#endif + template<typename VectorsType, typename CoeffsType, int Side> struct hseq_side_dependent_impl { diff --git a/Eigen/src/SparseCore/SparseAssign.h b/Eigen/src/SparseCore/SparseAssign.h index d4434e0ae..86a0b08c5 100644 --- a/Eigen/src/SparseCore/SparseAssign.h +++ b/Eigen/src/SparseCore/SparseAssign.h @@ -167,8 +167,10 @@ struct storage_kind_to_shape<Sparse> { }; struct Sparse2Sparse {}; +struct Sparse2Dense {}; template<> struct AssignmentKind<SparseShape,SparseShape> { typedef Sparse2Sparse Kind; }; +template<> struct AssignmentKind<DenseShape,SparseShape> { typedef Sparse2Dense Kind; }; template<typename DstXprType, typename SrcXprType> @@ -242,6 +244,24 @@ struct Assignment<DstXprType, SrcXprType, Functor, Sparse2Sparse, Scalar> } }; +// Sparse to Dense assignment +template< typename DstXprType, typename SrcXprType, typename Functor, typename Scalar> +struct Assignment<DstXprType, SrcXprType, Functor, Sparse2Dense, Scalar> +{ + static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar> &/*func*/) + { + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); + typedef typename SrcXprType::Index Index; + + dst.setZero(); + typename internal::evaluator<SrcXprType>::type srcEval(src); + typename internal::evaluator<DstXprType>::type dstEval(dst); + for (Index j=0; j<src.outerSize(); ++j) + for (typename internal::evaluator<SrcXprType>::InnerIterator i(srcEval,j); i; ++i) + dstEval.coeffRef(i.row(),i.col()) = i.value(); + } +}; + } // end namespace internal #endif // EIGEN_TEST_EVALUATORS diff --git a/Eigen/src/SparseCore/SparseBlock.h b/Eigen/src/SparseCore/SparseBlock.h index 4926f6923..f562b5479 100644 --- a/Eigen/src/SparseCore/SparseBlock.h +++ b/Eigen/src/SparseCore/SparseBlock.h @@ -67,7 +67,7 @@ public: Index nonZeros() const
{
#ifndef EIGEN_TEST_EVALUATORS
- typedef typename internal::evaluator<XprType>::type EvaluatorType;
+ Index nnz = 0;
Index end = m_outerStart + m_outerSize.value();
for(int j=m_outerStart; j<end; ++j)
for(typename XprType::InnerIterator it(m_matrix, j); it; ++it)
@@ -641,7 +641,7 @@ public: template<typename ArgType, int BlockRows, int BlockCols, int InnerPanel>
class unary_evaluator<Block<ArgType,BlockRows,BlockCols,InnerPanel>, IteratorBased>::OuterVectorInnerIterator
{
- const XprType& m_block;
+ const unary_evaluator& m_eval;
Index m_outerPos;
Index m_innerIndex;
Scalar m_value;
@@ -649,10 +649,10 @@ class unary_evaluator<Block<ArgType,BlockRows,BlockCols,InnerPanel>, IteratorBas public:
EIGEN_STRONG_INLINE OuterVectorInnerIterator(const unary_evaluator& aEval, Index outer)
- : m_block(aEval.m_block),
- m_outerPos( (IsRowMajor ? aEval.startCol() : aEval.startRow()) - 1), // -1 so that operator++ finds the first non-zero entry
- m_innerIndex(IsRowMajor ? aEval.startRow() : aEval.startCol()),
- m_end(IsRowMajor ? aEval.startCol()+aEval.blockCols() : aEval.startRow()+aEval.blockRows())
+ : m_eval(aEval),
+ m_outerPos( (IsRowMajor ? aEval.m_block.startCol() : aEval.m_block.startRow()) - 1), // -1 so that operator++ finds the first non-zero entry
+ m_innerIndex(IsRowMajor ? aEval.m_block.startRow() : aEval.m_block.startCol()),
+ m_end(IsRowMajor ? aEval.m_block.startCol()+aEval.m_block.blockCols() : aEval.m_block.startRow()+aEval.m_block.blockRows())
{
EIGEN_UNUSED_VARIABLE(outer);
eigen_assert(outer==0);
@@ -660,7 +660,7 @@ public: ++(*this);
}
- inline Index index() const { return m_outerPos - (IsRowMajor ? m_block.startCol() : m_block.startRow()); }
+ inline Index index() const { return m_outerPos - (IsRowMajor ? m_eval.m_block.startCol() : m_eval.m_block.startRow()); }
inline Index outer() const { return 0; }
inline Index row() const { return IsRowMajor ? 0 : index(); }
inline Index col() const { return IsRowMajor ? index() : 0; }
@@ -673,7 +673,7 @@ public: while(m_outerPos<m_end)
{
m_outerPos++;
- typename XprType::InnerIterator it(m_block.m_matrix, m_outerPos);
+ EvalIterator it(m_eval.m_argImpl, m_outerPos);
// search for the key m_innerIndex in the current outer-vector
while(it && it.index() < m_innerIndex) ++it;
if(it && it.index()==m_innerIndex)
diff --git a/Eigen/src/SparseCore/SparseMatrixBase.h b/Eigen/src/SparseCore/SparseMatrixBase.h index e4960a445..4c46008ae 100644 --- a/Eigen/src/SparseCore/SparseMatrixBase.h +++ b/Eigen/src/SparseCore/SparseMatrixBase.h @@ -337,6 +337,7 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> Block<Derived,Dynamic,Dynamic,true> innerVectors(Index outerStart, Index outerSize); const Block<const Derived,Dynamic,Dynamic,true> innerVectors(Index outerStart, Index outerSize) const; +#ifndef EIGEN_TEST_EVALUATORS /** \internal use operator= */ template<typename DenseDerived> void evalTo(MatrixBase<DenseDerived>& dst) const @@ -346,6 +347,7 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> for (typename Derived::InnerIterator i(derived(),j); i; ++i) dst.coeffRef(i.row(),i.col()) = i.value(); } +#endif Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> toDense() const { |