diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2008-04-14 08:20:24 +0000 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2008-04-14 08:20:24 +0000 |
commit | ea3ccb1e8c278a7a59a6b802d00b9050f9d5358b (patch) | |
tree | 4bb85eb170764b786ae8b33387f913d9c4a75e98 /Eigen/src/Core | |
parent | ab4046970bd4e7772287ef882334b8be26ea86da (diff) |
* Start of the LU module, with matrix inversion already there and
fully optimized.
* Even if LargeBit is set, only parallelize for large enough objects
(controlled by EIGEN_PARALLELIZATION_TRESHOLD).
Diffstat (limited to 'Eigen/src/Core')
-rw-r--r-- | Eigen/src/Core/Assign.h | 13 | ||||
-rw-r--r-- | Eigen/src/Core/Block.h | 10 | ||||
-rw-r--r-- | Eigen/src/Core/Matrix.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixBase.h | 9 | ||||
-rw-r--r-- | Eigen/src/Core/Product.h | 6 | ||||
-rw-r--r-- | Eigen/src/Core/util/ForwardDeclarations.h | 9 | ||||
-rw-r--r-- | Eigen/src/Core/util/Macros.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/util/Meta.h | 1 |
8 files changed, 40 insertions, 19 deletions
diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h index 37ad2c0cf..1b6e928d2 100644 --- a/Eigen/src/Core/Assign.h +++ b/Eigen/src/Core/Assign.h @@ -135,6 +135,11 @@ Derived& MatrixBase<Derived> } } +template<typename T1, typename T2> bool ei_should_parallelize_assignment(const T1& t, const T2&) +{ + return (T1::Flags & T2::Flags & LargeBit) && t.size() >= EIGEN_PARALLELIZATION_TRESHOLD; +} + template <typename Derived, typename OtherDerived> struct ei_assignment_impl<Derived, OtherDerived, false> { @@ -157,7 +162,7 @@ struct ei_assignment_impl<Derived, OtherDerived, false> for(int j = 0; j < dst.cols(); j++) \ for(int i = 0; i < dst.rows(); i++) \ dst.coeffRef(i, j) = src.coeff(i, j); - EIGEN_RUN_PARALLELIZABLE_LOOP(Derived::Flags & OtherDerived::Flags & LargeBit) + EIGEN_RUN_PARALLELIZABLE_LOOP(ei_should_parallelize_assignment(dst, src)) #undef EIGEN_THE_PARALLELIZABLE_LOOP } else @@ -168,7 +173,7 @@ struct ei_assignment_impl<Derived, OtherDerived, false> for(int i = 0; i < dst.rows(); i++) \ for(int j = 0; j < dst.cols(); j++) \ dst.coeffRef(i, j) = src.coeff(i, j); - EIGEN_RUN_PARALLELIZABLE_LOOP(Derived::Flags & OtherDerived::Flags & LargeBit) + EIGEN_RUN_PARALLELIZABLE_LOOP(ei_should_parallelize_assignment(dst, src)) #undef EIGEN_THE_PARALLELIZABLE_LOOP } } @@ -198,7 +203,7 @@ struct ei_assignment_impl<Derived, OtherDerived, true> for(int i = 0; i < dst.rows(); i++) \ for(int j = 0; j < dst.cols(); j+=ei_packet_traits<typename Derived::Scalar>::size) \ dst.writePacketCoeff(i, j, src.packetCoeff(i, j)); - EIGEN_RUN_PARALLELIZABLE_LOOP(Derived::Flags & OtherDerived::Flags & LargeBit) + EIGEN_RUN_PARALLELIZABLE_LOOP(ei_should_parallelize_assignment(dst, src)) #undef EIGEN_THE_PARALLELIZABLE_LOOP } else @@ -207,7 +212,7 @@ struct ei_assignment_impl<Derived, OtherDerived, true> for(int j = 0; j < dst.cols(); j++) \ for(int i = 0; i < dst.rows(); i+=ei_packet_traits<typename Derived::Scalar>::size) \ dst.writePacketCoeff(i, j, src.packetCoeff(i, j)); - EIGEN_RUN_PARALLELIZABLE_LOOP(Derived::Flags & OtherDerived::Flags & LargeBit) + EIGEN_RUN_PARALLELIZABLE_LOOP(ei_should_parallelize_assignment(dst, src)) #undef EIGEN_THE_PARALLELIZABLE_LOOP } } diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index c026b174c..0ff72075e 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -67,11 +67,11 @@ struct ei_traits<Block<MatrixType, BlockRows, BlockCols> > : (BlockRows==Dynamic ? MatrixType::MaxRowsAtCompileTime : BlockRows), MaxColsAtCompileTime = ColsAtCompileTime == 1 ? 1 : (BlockCols==Dynamic ? MatrixType::MaxColsAtCompileTime : BlockCols), - FlagsLargeBit = ((RowsAtCompileTime != Dynamic && MatrixType::RowsAtCompileTime == Dynamic) - || (ColsAtCompileTime != Dynamic && MatrixType::ColsAtCompileTime == Dynamic)) - ? ~LargeBit - : ~(unsigned int)0, - Flags = MatrixType::Flags & FlagsLargeBit & ~VectorizableBit, + FlagsMaskLargeBit = ((RowsAtCompileTime != Dynamic && MatrixType::RowsAtCompileTime == Dynamic) + || (ColsAtCompileTime != Dynamic && MatrixType::ColsAtCompileTime == Dynamic)) + ? ~LargeBit + : ~(unsigned int)0, + Flags = MatrixType::Flags & FlagsMaskLargeBit & ~VectorizableBit, CoeffReadCost = MatrixType::CoeffReadCost }; }; diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index e79cbcbfb..2f65413da 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -95,11 +95,8 @@ struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > }; }; -template<typename _Scalar, int _Rows, int _Cols, - unsigned int _Flags = EIGEN_DEFAULT_MATRIX_FLAGS, - int _MaxRows = _Rows, int _MaxCols = _Cols> -class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, - _Flags, _MaxRows, _MaxCols> > +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > { public: diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 151ee74d9..d5912c9e6 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -506,6 +506,15 @@ template<typename Derived> class MatrixBase { return *static_cast<Derived*>(const_cast<MatrixBase*>(this)); } //@} + /** \name LU module + * + * \code #include <Eigen/LU> \endcode + */ + //@{ + const Inverse<Derived, true> inverse() const; + const Inverse<Derived, false> quickInverse() const; + //@} + private: PacketScalar _packetCoeff(int , int) const { ei_internal_assert(false && "_packetCoeff not defined"); } diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 6771b5d30..b593825f8 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -280,6 +280,8 @@ void Product<Lhs,Rhs,EvalMode>::_cacheOptimalEval(DestDerived& res) const { res.setZero(); const int cols4 = m_lhs.cols() & 0xfffffffC; + const bool should_parallelize = (Flags & DestDerived::Flags & LargeBit) + && res.size() >= EIGEN_PARALLELIZATION_TRESHOLD; #ifdef EIGEN_VECTORIZE if( (Flags & VectorizableBit) && (!(Lhs::Flags & RowMajorBit)) ) { @@ -318,7 +320,7 @@ void Product<Lhs,Rhs,EvalMode>::_cacheOptimalEval(DestDerived& res) const res.writePacketCoeff(i,k,ei_pmul(tmp, m_lhs.packetCoeff(i,j))); \ } \ } - EIGEN_RUN_PARALLELIZABLE_LOOP(Flags & DestDerived::Flags & LargeBit) + EIGEN_RUN_PARALLELIZABLE_LOOP(should_parallelize) #undef EIGEN_THE_PARALLELIZABLE_LOOP } else @@ -345,7 +347,7 @@ void Product<Lhs,Rhs,EvalMode>::_cacheOptimalEval(DestDerived& res) const res.coeffRef(i,k) += tmp * m_lhs.coeff(i,j); \ } \ } - EIGEN_RUN_PARALLELIZABLE_LOOP(Flags & DestDerived::Flags & LargeBit) + EIGEN_RUN_PARALLELIZABLE_LOOP(should_parallelize) #undef EIGEN_THE_PARALLELIZABLE_LOOP } } diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 6167f13bd..86eaf4e54 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -29,7 +29,11 @@ template<typename T> struct ei_traits; template<typename Lhs, typename Rhs> struct ei_product_eval_mode; template<typename T> struct NumTraits; -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> class Matrix; +template<typename _Scalar, int _Rows, int _Cols, + unsigned int _Flags = EIGEN_DEFAULT_MATRIX_FLAGS, + int _MaxRows = _Rows, int _MaxCols = _Cols> +class Matrix; + template<typename ExpressionType> class Lazy; template<typename ExpressionType> class Temporary; template<typename MatrixType> class Minor; @@ -47,7 +51,6 @@ template<typename MatrixType> class DiagonalCoeffs; template<typename MatrixType> class Identity; template<typename MatrixType> class Map; template<typename Derived> class Eval; -template<typename Derived> class EvalOMP; template<int Direction, typename UnaryOp, typename MatrixType> class PartialRedux; template<typename Scalar> struct ei_scalar_sum_op; @@ -70,4 +73,6 @@ template<typename Scalar> struct ei_scalar_quotient1_op; template<typename Scalar> struct ei_scalar_min_op; template<typename Scalar> struct ei_scalar_max_op; +template<typename ExpressionType, bool CheckExistence = true> class Inverse; + #endif // EIGEN_FORWARDDECLARATIONS_H diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 43d595451..fad046766 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -37,6 +37,10 @@ #define EIGEN_UNROLLING_LIMIT 400 #endif +#ifndef EIGEN_PARALLELIZATION_TRESHOLD +#define EIGEN_PARALLELIZATION_TRESHOLD 2000 +#endif + #ifdef EIGEN_DEFAULT_TO_ROW_MAJOR #define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER RowMajorBit #else diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index faf177473..4939128eb 100644 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -182,5 +182,4 @@ template<typename T> struct ei_packet_traits enum {size=1}; }; - #endif // EIGEN_META_H |