From 4317fad8692eabe09bcafdd88de254deb8e3ea6f Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 12 May 2008 18:09:30 +0000 Subject: [PATCH] * Added several cast to int of the enums (needed for some compilers) * Fix a mistake in CwiseNullary. * Added a CoreDeclarions header that declares only the forward declarations and related basic stuffs. --- Eigen/Core | 39 +------------------------ Eigen/CoreDeclarations | 47 +++++++++++++++++++++++++++++++ Eigen/src/Core/Assign.h | 22 +++++++-------- Eigen/src/Core/Coeffs.h | 2 +- Eigen/src/Core/CwiseBinaryOp.h | 6 ++-- Eigen/src/Core/CwiseNullaryOp.h | 2 +- Eigen/src/Core/DiagonalCoeffs.h | 4 +-- Eigen/src/Core/Dot.h | 8 +++--- Eigen/src/Core/MathFunctions.h | 2 +- Eigen/src/Core/MatrixBase.h | 7 ++++- Eigen/src/Core/Minor.h | 8 +++--- Eigen/src/Core/Redux.h | 8 +++--- Eigen/src/Core/Transpose.h | 2 +- Eigen/src/Core/TriangularAssign.h | 2 +- Eigen/src/Core/Visitor.h | 2 +- Eigen/src/Core/util/Meta.h | 10 +++---- 16 files changed, 93 insertions(+), 78 deletions(-) create mode 100644 Eigen/CoreDeclarations diff --git a/Eigen/Core b/Eigen/Core index dfe18fe43..82ca1f165 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -1,39 +1,7 @@ #ifndef EIGEN_CORE_H #define EIGEN_CORE_H -#define EIGEN_WIP_PRODUCT - -#ifdef __GNUC__ -#define EIGEN_GNUC_AT_LEAST(x,y) (__GNUC__>=x && __GNUC_MINOR__>=y) || __GNUC__>x -#else -#define EIGEN_GNUC_AT_LEAST(x,y) false -#endif - -#ifndef EIGEN_DONT_VECTORIZE - #if (defined __SSE2__) && ( (!defined __GNUC__) || EIGEN_GNUC_AT_LEAST(4,2) ) - #define EIGEN_VECTORIZE - #define EIGEN_VECTORIZE_SSE - #include - #include - #ifdef __SSE3__ - #include - #endif - #ifdef __SSSE3__ - #include - #endif - #elif (defined __ALTIVEC__) - #define EIGEN_VECTORIZE - #define EIGEN_VECTORIZE_ALTIVEC - #include - // We _need_ to #undef bool as it's defined in for some reason. - #undef bool - #endif -#endif - -#include -#include -#include -#include +#include "CoreDeclarations" #include #ifdef EIGEN_VECTORIZE @@ -43,11 +11,6 @@ extern "C" int posix_memalign (void **, size_t, size_t) throw (); namespace Eigen { -#include "src/Core/util/Macros.h" -#include "src/Core/util/Constants.h" -#include "src/Core/util/ForwardDeclarations.h" -#include "src/Core/util/Meta.h" - #include "src/Core/NumTraits.h" #include "src/Core/MathFunctions.h" #include "src/Core/DummyPacketMath.h" diff --git a/Eigen/CoreDeclarations b/Eigen/CoreDeclarations new file mode 100644 index 000000000..9a44e4dc3 --- /dev/null +++ b/Eigen/CoreDeclarations @@ -0,0 +1,47 @@ +#ifndef EIGEN_CORE_DECLARATIONS_H +#define EIGEN_CORE_DECLARATIONS_H + +#define EIGEN_WIP_PRODUCT + +#ifdef __GNUC__ +#define EIGEN_GNUC_AT_LEAST(x,y) (__GNUC__>=x && __GNUC_MINOR__>=y) || __GNUC__>x +#else +#define EIGEN_GNUC_AT_LEAST(x,y) false +#endif + +#ifndef EIGEN_DONT_VECTORIZE + #if (defined __SSE2__) && ( (!defined __GNUC__) || EIGEN_GNUC_AT_LEAST(4,2) ) + #define EIGEN_VECTORIZE + #define EIGEN_VECTORIZE_SSE + #include + #include + #ifdef __SSE3__ + #include + #endif + #ifdef __SSSE3__ + #include + #endif + #elif (defined __ALTIVEC__) + #define EIGEN_VECTORIZE + #define EIGEN_VECTORIZE_ALTIVEC + #include + // We _need_ to #undef bool as it's defined in for some reason. + #undef bool + #endif +#endif + +#include +#include +#include +#include + +namespace Eigen { + +#include "src/Core/util/Macros.h" +#include "src/Core/util/Constants.h" +#include "src/Core/util/ForwardDeclarations.h" +#include "src/Core/util/Meta.h" + +} // namespace Eigen + +#endif // EIGEN_CORE_DECLARATIONS_H diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h index bf57b3754..1eb88d8ff 100644 --- a/Eigen/src/Core/Assign.h +++ b/Eigen/src/Core/Assign.h @@ -70,8 +70,8 @@ template struct ei_matrix_assignment_packet_unroller { enum { - row = Derived1::Flags&RowMajorBit ? Index / Derived1::ColsAtCompileTime : Index % Derived1::RowsAtCompileTime, - col = Derived1::Flags&RowMajorBit ? Index % Derived1::ColsAtCompileTime : Index / Derived1::RowsAtCompileTime + row = int(Derived1::Flags)&RowMajorBit ? Index / int(Derived1::ColsAtCompileTime) : Index % Derived1::RowsAtCompileTime, + col = int(Derived1::Flags)&RowMajorBit ? Index % int(Derived1::ColsAtCompileTime) : Index / Derived1::RowsAtCompileTime }; inline static void run(Derived1 &dst, const Derived2 &src) @@ -99,12 +99,12 @@ struct ei_matrix_assignment_packet_unroller }; template ::size==0) - : Derived::RowsAtCompileTime!=Dynamic && (Derived::RowsAtCompileTime%ei_packet_traits::size==0)) ), +bool Vectorize = (int(Derived::Flags) & int(OtherDerived::Flags) & VectorizableBit) + && ((int(Derived::Flags)&RowMajorBit)==(int(OtherDerived::Flags)&RowMajorBit)) + && ( (int(Derived::Flags) & int(OtherDerived::Flags) & Like1DArrayBit) + ||((int(Derived::Flags)&RowMajorBit) + ? int(Derived::ColsAtCompileTime)!=Dynamic && (int(Derived::ColsAtCompileTime)%ei_packet_traits::size==0) + : int(Derived::RowsAtCompileTime)!=Dynamic && (int(Derived::RowsAtCompileTime)%ei_packet_traits::size==0)) ), bool TriangularAssign = Derived::Flags & (NullLowerBit | NullUpperBit)> struct ei_assignment_impl; @@ -156,7 +156,7 @@ struct ei_assignment_impl { ei_matrix_assignment_unroller ::run(dst.derived(), src.derived()); } else @@ -190,8 +190,8 @@ struct ei_assignment_impl // std::cout << "vectorized unrolled\n"; ei_matrix_assignment_packet_unroller =ei_packet_traits::size - ? Derived::SizeAtCompileTime-ei_packet_traits::size + unroll && int(Derived::SizeAtCompileTime)>=int(ei_packet_traits::size) + ? int(Derived::SizeAtCompileTime)-int(ei_packet_traits::size) : Dynamic>::run(dst.const_cast_derived(), src.derived()); } else diff --git a/Eigen/src/Core/Coeffs.h b/Eigen/src/Core/Coeffs.h index 28845cd95..b58b2e0d2 100644 --- a/Eigen/src/Core/Coeffs.h +++ b/Eigen/src/Core/Coeffs.h @@ -256,7 +256,7 @@ template template inline void MatrixBase::writePacketCoeff (int row, int col, const typename ei_packet_traits::Scalar>::type& x) -{ return derived().template _writePacketCoeff(row,col,x); } +{ derived().template _writePacketCoeff(row,col,x); } #endif // EIGEN_COEFFS_H diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index daa81ddb7..dde7de437 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -68,11 +68,11 @@ struct ei_traits > ColsAtCompileTime = Lhs::ColsAtCompileTime, MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime, MaxColsAtCompileTime = Lhs::MaxColsAtCompileTime, - Flags = ((LhsFlags | RhsFlags) & ( + Flags = ((int(LhsFlags) | int(RhsFlags)) & ( DefaultLostFlagMask | Like1DArrayBit - | (ei_functor_traits::IsVectorizable && ((LhsFlags & RowMajorBit)==(RhsFlags & RowMajorBit)) - ? LhsFlags & RhsFlags & VectorizableBit : 0))), + | (ei_functor_traits::IsVectorizable && ((int(LhsFlags) & RowMajorBit)==(int(RhsFlags) & RowMajorBit)) + ? int(LhsFlags) & int(RhsFlags) & VectorizableBit : 0))), CoeffReadCost = LhsCoeffReadCost + RhsCoeffReadCost + ei_functor_traits::Cost }; }; diff --git a/Eigen/src/Core/CwiseNullaryOp.h b/Eigen/src/Core/CwiseNullaryOp.h index ee986de48..8e28919bb 100644 --- a/Eigen/src/Core/CwiseNullaryOp.h +++ b/Eigen/src/Core/CwiseNullaryOp.h @@ -155,7 +155,7 @@ template const CwiseNullaryOp MatrixBase::create(const CustomNullaryOp& func) { - return CwiseNullaryOp(rows(), cols(), func); + return CwiseNullaryOp(RowsAtCompileTime, ColsAtCompileTime, func); } /** \returns an expression of a constant matrix of value \a value diff --git a/Eigen/src/Core/DiagonalCoeffs.h b/Eigen/src/Core/DiagonalCoeffs.h index b9471e7a1..38866d95d 100644 --- a/Eigen/src/Core/DiagonalCoeffs.h +++ b/Eigen/src/Core/DiagonalCoeffs.h @@ -46,11 +46,11 @@ struct ei_traits > typedef typename ei_nested::type MatrixTypeNested; typedef typename ei_unref::type _MatrixTypeNested; enum { - RowsAtCompileTime = MatrixType::SizeAtCompileTime == Dynamic ? Dynamic + RowsAtCompileTime = int(MatrixType::SizeAtCompileTime) == Dynamic ? Dynamic : EIGEN_ENUM_MIN(MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime), ColsAtCompileTime = 1, - MaxRowsAtCompileTime = MatrixType::MaxSizeAtCompileTime == Dynamic ? Dynamic + MaxRowsAtCompileTime = int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic : EIGEN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime), MaxColsAtCompileTime = 1, diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index 28a93e71d..b0ec14a33 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -85,11 +85,11 @@ MatrixBase::dot(const MatrixBase& other) const Scalar res; const bool unroll = SizeAtCompileTime * (_Nested::CoeffReadCost + _OtherNested::CoeffReadCost + NumTraits::MulCost) - + (SizeAtCompileTime - 1) * NumTraits::AddCost + + (int(SizeAtCompileTime) - 1) * NumTraits::AddCost <= EIGEN_UNROLLING_LIMIT; if(unroll) - ei_dot_unroller ::run(nested, otherNested, res); else @@ -135,7 +135,7 @@ template inline const CwiseUnaryOp::Scalar>, Derived> MatrixBase::normalized() const { - return (*this) * (Scalar(1)/norm()); + return (*this) * (RealScalar(1)/norm()); } /** \returns true if *this is approximately orthogonal to \a other, diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 5ba37c076..557b93f56 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -46,7 +46,7 @@ inline int ei_log(int) { ei_assert(false); return 0; } inline int ei_sin(int) { ei_assert(false); return 0; } inline int ei_cos(int) { ei_assert(false); return 0; } -#if EIGEN_GNUC_AT_LEAST(4,2) +#if (!(EIGEN_GNUC_AT_LEAST(4,3))) inline int ei_pow(int x, int y) { return int(std::pow(double(x), y)); } #else inline int ei_pow(int x, int y) { return std::pow(x, y); } diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 9078e5677..d14fec1f1 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -396,7 +396,7 @@ template class MatrixBase bool isOrtho(const MatrixBase& other, RealScalar prec = precision()) const; bool isOrtho(RealScalar prec = precision()) const; - + template inline bool operator==(const MatrixBase& other) const { return derived().cwiseEqualTo(other.derived()).all(); } @@ -563,6 +563,11 @@ template class MatrixBase //@{ const QR::type> qr() const; //@} + + + #ifdef EIGEN_MATRIX_CUSTOM_ADDONS_FILE + #include EIGEN_MATRIX_CUSTOM_ADDONS_FILE + #endif }; diff --git a/Eigen/src/Core/Minor.h b/Eigen/src/Core/Minor.h index 4a0edc3a3..d7e08c4e0 100644 --- a/Eigen/src/Core/Minor.h +++ b/Eigen/src/Core/Minor.h @@ -45,13 +45,13 @@ struct ei_traits > typedef typename ei_unref::type _MatrixTypeNested; enum { RowsAtCompileTime = (MatrixType::RowsAtCompileTime != Dynamic) ? - MatrixType::RowsAtCompileTime - 1 : Dynamic, + int(MatrixType::RowsAtCompileTime) - 1 : Dynamic, ColsAtCompileTime = (MatrixType::ColsAtCompileTime != Dynamic) ? - MatrixType::ColsAtCompileTime - 1 : Dynamic, + int(MatrixType::ColsAtCompileTime) - 1 : Dynamic, MaxRowsAtCompileTime = (MatrixType::MaxRowsAtCompileTime != Dynamic) ? - MatrixType::MaxRowsAtCompileTime - 1 : Dynamic, + int(MatrixType::MaxRowsAtCompileTime) - 1 : Dynamic, MaxColsAtCompileTime = (MatrixType::MaxColsAtCompileTime != Dynamic) ? - MatrixType::MaxColsAtCompileTime - 1 : Dynamic, + int(MatrixType::MaxColsAtCompileTime) - 1 : Dynamic, Flags = _MatrixTypeNested::Flags & DefaultLostFlagMask, CoeffReadCost = _MatrixTypeNested::CoeffReadCost }; diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index 5b14f5b27..5672effc7 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -94,7 +94,7 @@ struct ei_traits > ColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime, - Flags = ((RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic) + Flags = ((int(RowsAtCompileTime) == Dynamic || int(ColsAtCompileTime) == Dynamic) ? (unsigned int)_MatrixTypeNested::Flags : (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & DefaultLostFlagMask, TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime, @@ -182,7 +182,7 @@ MatrixBase::redux(const BinaryOp& func) const <= EIGEN_UNROLLING_LIMIT; if(unroll) return ei_redux_unroller + unroll ? int(SizeAtCompileTime) : Dynamic> ::run(derived(), func); else { @@ -304,7 +304,7 @@ bool MatrixBase::all(void) const <= EIGEN_UNROLLING_LIMIT; if(unroll) return ei_all_unroller::run(derived()); else { @@ -326,7 +326,7 @@ bool MatrixBase::any(void) const <= EIGEN_UNROLLING_LIMIT; if(unroll) return ei_any_unroller::run(derived()); else { diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index e7f37bbae..5d4cbd2f4 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -48,7 +48,7 @@ struct ei_traits > ColsAtCompileTime = MatrixType::RowsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - Flags = _MatrixTypeNested::Flags ^ RowMajorBit, + Flags = int(_MatrixTypeNested::Flags) ^ RowMajorBit, CoeffReadCost = _MatrixTypeNested::CoeffReadCost }; }; diff --git a/Eigen/src/Core/TriangularAssign.h b/Eigen/src/Core/TriangularAssign.h index ec208f2ad..7b1be135e 100644 --- a/Eigen/src/Core/TriangularAssign.h +++ b/Eigen/src/Core/TriangularAssign.h @@ -80,7 +80,7 @@ struct ei_assignment_impl if(unroll) { ei_triangular_assign_unroller - ::run + ::run (dst.derived(), src.derived()); } else diff --git a/Eigen/src/Core/Visitor.h b/Eigen/src/Core/Visitor.h index 9dd8ef661..6e00e4142 100644 --- a/Eigen/src/Core/Visitor.h +++ b/Eigen/src/Core/Visitor.h @@ -79,7 +79,7 @@ void MatrixBase::visit(Visitor& visitor) const <= EIGEN_UNROLLING_LIMIT; if(unroll) return ei_visitor_unroller::run(derived(), visitor); else { diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index 264802b9b..3c4596d4c 100644 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -158,9 +158,9 @@ class ei_corrected_matrix_flags }; public: - enum { ret = is_vectorizable - ? _flags1 | VectorizableBit - : _flags1 & ~VectorizableBit + enum { ret = int(is_vectorizable) + ? int(_flags1) | int(VectorizableBit) + : int(_flags1) & ~int(VectorizableBit) }; }; @@ -208,8 +208,8 @@ template struct ei_nested ei_is_temporary::ret, T, typename ei_meta_if< - ei_traits::Flags & EvalBeforeNestingBit - || (n+1) * NumTraits::Scalar>::ReadCost < (n-1) * T::CoeffReadCost, + int(ei_traits::Flags) & EvalBeforeNestingBit + || (n+1) * int(NumTraits::Scalar>::ReadCost) < (n-1) * int(T::CoeffReadCost), typename ei_eval::type, const T& >::ret