From ab4046970bd4e7772287ef882334b8be26ea86da Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sat, 12 Apr 2008 17:37:27 +0000 Subject: * Add fixed-size template versions of corner(), start(), end(). * Use them to write an unrolled path in echelon.cpp, as an experiment before I do this LU module. * For floating-point types, make ei_random() use an amplitude of 1. --- Eigen/src/Core/Block.h | 205 +++++++++++++++++++++++++++++++++++------ Eigen/src/Core/MathFunctions.h | 11 ++- Eigen/src/Core/MatrixBase.h | 17 ++++ Eigen/src/Core/PacketMath.h | 2 +- Eigen/src/Core/util/Macros.h | 1 + 5 files changed, 205 insertions(+), 31 deletions(-) (limited to 'Eigen/src/Core') diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index c8f4ac6b1..c026b174c 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -67,9 +67,11 @@ struct ei_traits > : (BlockRows==Dynamic ? MatrixType::MaxRowsAtCompileTime : BlockRows), MaxColsAtCompileTime = ColsAtCompileTime == 1 ? 1 : (BlockCols==Dynamic ? MatrixType::MaxColsAtCompileTime : BlockCols), - Flags = (RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic - ? (unsigned int)MatrixType::Flags - : (unsigned int)MatrixType::Flags &~ LargeBit) & ~VectorizableBit, + FlagsLargeBit = ((RowsAtCompileTime != Dynamic && MatrixType::RowsAtCompileTime == Dynamic) + || (ColsAtCompileTime != Dynamic && MatrixType::ColsAtCompileTime == Dynamic)) + ? ~LargeBit + : ~(unsigned int)0, + Flags = MatrixType::Flags & FlagsLargeBit & ~VectorizableBit, CoeffReadCost = MatrixType::CoeffReadCost }; }; @@ -236,8 +238,7 @@ const Block MatrixBase * \sa class Block, block(int,int) */ template -Block MatrixBase - ::start(int size) +Block MatrixBase::start(int size) { ei_assert(IsVectorAtCompileTime); return Block(derived(), 0, 0, @@ -247,8 +248,7 @@ Block MatrixBase /** This is the const version of start(int).*/ template -const Block MatrixBase - ::start(int size) const +const Block MatrixBase::start(int size) const { ei_assert(IsVectorAtCompileTime); return Block(derived(), 0, 0, @@ -272,8 +272,7 @@ const Block MatrixBase * \sa class Block, block(int,int) */ template -Block MatrixBase - ::end(int size) +Block MatrixBase::end(int size) { ei_assert(IsVectorAtCompileTime); return Block(derived(), @@ -285,8 +284,7 @@ Block MatrixBase /** This is the const version of end(int).*/ template -const Block MatrixBase - ::end(int size) const +const Block MatrixBase::end(int size) const { ei_assert(IsVectorAtCompileTime); return Block(derived(), @@ -296,6 +294,80 @@ const Block MatrixBase ColsAtCompileTime == 1 ? 1 : size); } +/** \returns a fixed-size expression of the first coefficients of *this. + * + * \only_for_vectors + * + * The template parameter \a Size is the number of coefficients in the block + * + * Example: \include MatrixBase_template_int_start.cpp + * Output: \verbinclude MatrixBase_template_int_start.out + * + * \sa class Block + */ +template +template +Block::RowsAtCompileTime == 1 ? 1 : Size, + ei_traits::ColsAtCompileTime == 1 ? 1 : Size> +MatrixBase::start() +{ + ei_assert(IsVectorAtCompileTime); + return Block(derived(), 0, 0); +} + +/** This is the const version of start().*/ +template +template +const Block::RowsAtCompileTime == 1 ? 1 : Size, + ei_traits::ColsAtCompileTime == 1 ? 1 : Size> +MatrixBase::start() const +{ + ei_assert(IsVectorAtCompileTime); + return Block(derived(), 0, 0); +} + +/** \returns a fixed-size expression of the last coefficients of *this. + * + * \only_for_vectors + * + * The template parameter \a Size is the number of coefficients in the block + * + * Example: \include MatrixBase_template_int_end.cpp + * Output: \verbinclude MatrixBase_template_int_end.out + * + * \sa class Block + */ +template +template +Block::RowsAtCompileTime == 1 ? 1 : Size, + ei_traits::ColsAtCompileTime == 1 ? 1 : Size> +MatrixBase::end() +{ + ei_assert(IsVectorAtCompileTime); + return Block + (derived(), + RowsAtCompileTime == 1 ? 0 : rows() - Size, + ColsAtCompileTime == 1 ? 0 : cols() - Size); +} + +/** This is the const version of end.*/ +template +template +const Block::RowsAtCompileTime == 1 ? 1 : Size, + ei_traits::ColsAtCompileTime == 1 ? 1 : Size> +MatrixBase::end() const +{ + ei_assert(IsVectorAtCompileTime); + return Block + (derived(), + RowsAtCompileTime == 1 ? 0 : rows() - Size, + ColsAtCompileTime == 1 ? 0 : cols() - Size); +} + /** \returns a dynamic-size expression of a corner of *this. * * \param type the type of corner. Can be \a Eigen::TopLeft, \a Eigen::TopRight, @@ -316,14 +388,23 @@ template Block MatrixBase ::corner(CornerType type, int cRows, int cCols) { - if(type == TopLeft) - return Block(derived(), 0, 0, cRows, cCols); - else if(type == TopRight) - return Block(derived(), 0, cols() - cCols, cRows, cCols); - else if(type == BottomLeft) - return Block(derived(), rows() - cRows, 0, cRows, cCols); - else - return Block(derived(), rows() - cRows, cols() - cCols, cRows, cCols); + switch(type) + { + case TopLeft: + return Block(derived(), 0, 0, cRows, cCols); + break; + case TopRight: + return Block(derived(), 0, cols() - cCols, cRows, cCols); + break; + case BottomLeft: + return Block(derived(), rows() - cRows, 0, cRows, cCols); + break; + case BottomRight: + return Block(derived(), rows() - cRows, cols() - cCols, cRows, cCols); + break; + default: + ei_assert(false && "Bad corner type."); + } } /** This is the const version of corner(CornerType, int, int).*/ @@ -331,14 +412,84 @@ template const Block MatrixBase ::corner(CornerType type, int cRows, int cCols) const { - if(type == TopLeft) - return Block(derived(), 0, 0, cRows, cCols); - else if(type == TopRight) - return Block(derived(), 0, cols() - cCols, cRows, cCols); - else if(type == BottomLeft) - return Block(derived(), rows() - cRows, 0, cRows, cCols); - else - return Block(derived(), rows() - cRows, cols() - cCols, cRows, cCols); + switch(type) + { + case TopLeft: + return Block(derived(), 0, 0, cRows, cCols); + break; + case TopRight: + return Block(derived(), 0, cols() - cCols, cRows, cCols); + break; + case BottomLeft: + return Block(derived(), rows() - cRows, 0, cRows, cCols); + break; + case BottomRight: + return Block(derived(), rows() - cRows, cols() - cCols, cRows, cCols); + break; + default: + ei_assert(false && "Bad corner type."); + } +} + +/** \returns a fixed-size expression of a corner of *this. + * + * \param type the type of corner. Can be \a Eigen::TopLeft, \a Eigen::TopRight, + * \a Eigen::BottomLeft, \a Eigen::BottomRight. + * + * The template parameters CRows and CCols arethe number of rows and columns in the corner. + * + * Example: \include MatrixBase_template_int_int_corner_enum.cpp + * Output: \verbinclude MatrixBase_template_int_int_corner_enum.out + * + * \sa class Block, block(int,int,int,int) + */ +template +template +Block MatrixBase + ::corner(CornerType type) +{ + switch(type) + { + case TopLeft: + return Block(derived(), 0, 0); + break; + case TopRight: + return Block(derived(), 0, cols() - CCols); + break; + case BottomLeft: + return Block(derived(), rows() - CRows, 0); + break; + case BottomRight: + return Block(derived(), rows() - CRows, cols() - CCols); + break; + default: + ei_assert(false && "Bad corner type."); + } +} + +/** This is the const version of corner(CornerType).*/ +template +template +const Block MatrixBase + ::corner(CornerType type) const +{ + switch(type) + { + case TopLeft: + return Block(derived(), 0, 0); + break; + case TopRight: + return Block(derived(), 0, cols() - CCols); + break; + case BottomLeft: + return Block(derived(), rows() - CRows, 0); + break; + case BottomRight: + return Block(derived(), rows() - CRows, cols() - CCols); + break; + default: + ei_assert(false && "Bad corner type."); + } } /** \returns a fixed-size expression of a block in *this. diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index f2d665872..72cf916f8 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -28,6 +28,11 @@ template inline typename NumTraits::Real precision(); template inline T ei_random(T a, T b); template inline T ei_random(); +template inline T ei_random_amplitude() +{ + if(NumTraits::HasFloatingPoint) return static_cast(1); + else return static_cast(10); +} template<> inline int precision() { return 0; } inline int ei_real(int x) { return x; } @@ -54,7 +59,7 @@ template<> inline int ei_random(int a, int b) } template<> inline int ei_random() { - return ei_random(-10, 10); + return ei_random(-ei_random_amplitude(), ei_random_amplitude()); } inline bool ei_isMuchSmallerThan(int a, int, int = precision()) { @@ -88,7 +93,7 @@ template<> inline float ei_random(float a, float b) } template<> inline float ei_random() { - return ei_random(-10.0f, 10.0f); + return ei_random(-ei_random_amplitude(), ei_random_amplitude()); } inline bool ei_isMuchSmallerThan(float a, float b, float prec = precision()) { @@ -122,7 +127,7 @@ template<> inline double ei_random(double a, double b) } template<> inline double ei_random() { - return ei_random(-10.0, 10.0); + return ei_random(-ei_random_amplitude(), ei_random_amplitude()); } inline bool ei_isMuchSmallerThan(double a, double b, double prec = precision()) { diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 5c2350d6c..151ee74d9 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -316,6 +316,23 @@ template class MatrixBase template const Block block(int startRow, int startCol) const; + template Block corner(CornerType type); + template const Block corner(CornerType type) const; + + template + Block::RowsAtCompileTime == 1 ? 1 : Size, + ei_traits::ColsAtCompileTime == 1 ? 1 : Size> start(); + template + const Block::RowsAtCompileTime == 1 ? 1 : Size, + ei_traits::ColsAtCompileTime == 1 ? 1 : Size> start() const; + + template + Block::RowsAtCompileTime == 1 ? 1 : Size, + ei_traits::ColsAtCompileTime == 1 ? 1 : Size> end(); + template + const Block::RowsAtCompileTime == 1 ? 1 : Size, + ei_traits::ColsAtCompileTime == 1 ? 1 : Size> end() const; + DiagonalCoeffs diagonal(); const DiagonalCoeffs diagonal() const; //@} diff --git a/Eigen/src/Core/PacketMath.h b/Eigen/src/Core/PacketMath.h index 3697f262e..cc925b50c 100644 --- a/Eigen/src/Core/PacketMath.h +++ b/Eigen/src/Core/PacketMath.h @@ -79,7 +79,7 @@ inline float ei_pfirst(const __m128& a) { return _mm_cvtss_f32(a); } inline double ei_pfirst(const __m128d& a) { return _mm_cvtsd_f64(a); } inline int ei_pfirst(const __m128i& a) { return _mm_cvtsi128_si32(a); } -#endif +#endif // EIGEN_VECTORIZE_SSE #endif // EIGEN_PACKET_MATH_H diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 2f39b48fd..43d595451 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -142,6 +142,7 @@ EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=) #define _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, BaseClass) \ typedef BaseClass Base; \ typedef typename Eigen::ei_traits::Scalar Scalar; \ +typedef typename Eigen::NumTraits::Real RealScalar; \ typedef typename Base::PacketScalar PacketScalar; \ typedef typename Eigen::ei_nested::type Nested; \ typedef typename Eigen::ei_eval::type Eval; \ -- cgit v1.2.3