diff options
author | Gael Guennebaud <g.gael@free.fr> | 2008-05-31 18:11:48 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2008-05-31 18:11:48 +0000 |
commit | 310f7aa09622e8e549b4e14cc3659e22bb02d915 (patch) | |
tree | 1d1c22bf1801a731b8d4bf7cb84443376660ea08 /Eigen/src/Core/Redux.h | |
parent | a2f71f9d7e1e443814fe60726d99a4b0508baefa (diff) |
moved purely "array" related stuff to a new module Array.
This include:
- cwise Pow,Sin,Cos,Exp...
- cwise Greater and other comparison operators
- .any(), .all() and partial reduction
- random
Diffstat (limited to 'Eigen/src/Core/Redux.h')
-rw-r--r-- | Eigen/src/Core/Redux.h | 197 |
1 files changed, 0 insertions, 197 deletions
diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index aaf1843d9..7c5534154 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -66,105 +66,6 @@ struct ei_redux_unroller<BinaryOp, Derived, Start, Dynamic> static Scalar run(const Derived&, const BinaryOp&) { return Scalar(); } }; - -/** \class PartialRedux - * - * \brief Generic expression of a partially reduxed matrix - * - * \param Direction indicates the direction of the redux (Vertical or Horizontal) - * \param BinaryOp type of the binary functor implementing the operator (must be associative) - * \param MatrixType the type of the matrix we are applying the redux operation - * - * This class represents an expression of a partial redux operator of a matrix. - * It is the return type of MatrixBase::verticalRedux(), MatrixBase::horizontalRedux(), - * and most of the time this is the only way it is used. - * - * \sa class CwiseBinaryOp - */ -template<int Direction, typename BinaryOp, typename MatrixType> -struct ei_traits<PartialRedux<Direction, BinaryOp, MatrixType> > -{ - typedef typename ei_result_of< - BinaryOp(typename MatrixType::Scalar) - >::type Scalar; - typedef typename ei_nested<MatrixType>::type MatrixTypeNested; - typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested; - enum { - RowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::RowsAtCompileTime, - ColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime, - Flags = ((int(RowsAtCompileTime) == Dynamic || int(ColsAtCompileTime) == Dynamic) - ? (unsigned int)_MatrixTypeNested::Flags - : (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & HereditaryBits, - TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime, - CoeffReadCost = TraversalSize * _MatrixTypeNested::CoeffReadCost - + (TraversalSize - 1) * ei_functor_traits<BinaryOp>::Cost - }; -}; - -template<int Direction, typename BinaryOp, typename MatrixType> -class PartialRedux : ei_no_assignment_operator, - public MatrixBase<PartialRedux<Direction, BinaryOp, MatrixType> > -{ - public: - - EIGEN_GENERIC_PUBLIC_INTERFACE(PartialRedux) - typedef typename ei_traits<PartialRedux>::MatrixTypeNested MatrixTypeNested; - typedef typename ei_traits<PartialRedux>::_MatrixTypeNested _MatrixTypeNested; - - PartialRedux(const MatrixType& mat, const BinaryOp& func = BinaryOp()) - : m_matrix(mat), m_functor(func) {} - - private: - - int _rows() const { return (Direction==Vertical ? 1 : m_matrix.rows()); } - int _cols() const { return (Direction==Horizontal ? 1 : m_matrix.cols()); } - - const Scalar _coeff(int i, int j) const - { - if (Direction==Vertical) - return m_matrix.col(j).redux(m_functor); - else - return m_matrix.row(i).redux(m_functor); - } - - protected: - const MatrixTypeNested m_matrix; - const BinaryOp m_functor; -}; - -/** \returns a row vector expression of *this vertically reduxed by \a func - * - * The template parameter \a BinaryOp is the type of the functor - * of the custom redux operator. Note that func must be an associative operator. - * - * \sa class PartialRedux, MatrixBase::horizontalRedux() - */ -template<typename Derived> -template<typename BinaryOp> -const PartialRedux<Vertical, BinaryOp, Derived> -MatrixBase<Derived>::verticalRedux(const BinaryOp& func) const -{ - return PartialRedux<Vertical, BinaryOp, Derived>(derived(), func); -} - -/** \returns a row vector expression of *this horizontally reduxed by \a func - * - * The template parameter \a BinaryOp is the type of the functor - * of the custom redux operator. Note that func must be an associative operator. - * - * \sa class PartialRedux, MatrixBase::verticalRedux() - */ -template<typename Derived> -template<typename BinaryOp> -const PartialRedux<Horizontal, BinaryOp, Derived> -MatrixBase<Derived>::horizontalRedux(const BinaryOp& func) const -{ - return PartialRedux<Horizontal, BinaryOp, Derived>(derived(), func); -} - - /** \returns the result of a full redux operation on the whole matrix or vector using \a func * * The template parameter \a BinaryOp is the type of the functor \a func which must be @@ -239,102 +140,4 @@ inline MatrixBase<Derived>::maxCoeff() const return this->redux(Eigen::ei_scalar_max_op<Scalar>()); } - - -template<typename Derived, int UnrollCount> -struct ei_all_unroller -{ - enum { - col = (UnrollCount-1) / Derived::RowsAtCompileTime, - row = (UnrollCount-1) % Derived::RowsAtCompileTime - }; - - inline static bool run(const Derived &mat) - { - return ei_all_unroller<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col); - } -}; - -template<typename Derived> -struct ei_all_unroller<Derived, 1> -{ - inline static bool run(const Derived &mat) { return mat.coeff(0, 0); } -}; - -template<typename Derived> -struct ei_all_unroller<Derived, Dynamic> -{ - inline static bool run(const Derived &) { return false; } -}; - -template<typename Derived, int UnrollCount> -struct ei_any_unroller -{ - enum { - col = (UnrollCount-1) / Derived::RowsAtCompileTime, - row = (UnrollCount-1) % Derived::RowsAtCompileTime - }; - - inline static bool run(const Derived &mat) - { - return ei_any_unroller<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col); - } -}; - -template<typename Derived> -struct ei_any_unroller<Derived, 1> -{ - inline static bool run(const Derived &mat) { return mat.coeff(0, 0); } -}; - -template<typename Derived> -struct ei_any_unroller<Derived, Dynamic> -{ - inline static bool run(const Derived &) { return false; } -}; - -/** \returns true if all coefficients are true - * - * \sa MatrixBase::any() - */ -template<typename Derived> -bool MatrixBase<Derived>::all(void) const -{ - const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) - <= EIGEN_UNROLLING_LIMIT; - if(unroll) - return ei_all_unroller<Derived, - unroll ? int(SizeAtCompileTime) : Dynamic - >::run(derived()); - else - { - for(int j = 0; j < cols(); j++) - for(int i = 0; i < rows(); i++) - if (!coeff(i, j)) return false; - return true; - } -} - -/** \returns true if at least one coefficient is true - * - * \sa MatrixBase::any() - */ -template<typename Derived> -bool MatrixBase<Derived>::any(void) const -{ - const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) - <= EIGEN_UNROLLING_LIMIT; - if(unroll) - return ei_any_unroller<Derived, - unroll ? int(SizeAtCompileTime) : Dynamic - >::run(derived()); - else - { - for(int j = 0; j < cols(); j++) - for(int i = 0; i < rows(); i++) - if (coeff(i, j)) return true; - return false; - } -} - #endif // EIGEN_REDUX_H |