* 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.
This commit is contained in:
Gael Guennebaud 2008-05-12 18:09:30 +00:00
parent 678f18fce4
commit 4317fad869
16 changed files with 93 additions and 78 deletions

View File

@ -1,39 +1,7 @@
#ifndef EIGEN_CORE_H #ifndef EIGEN_CORE_H
#define EIGEN_CORE_H #define EIGEN_CORE_H
#define EIGEN_WIP_PRODUCT #include "CoreDeclarations"
#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 <emmintrin.h>
#include <xmmintrin.h>
#ifdef __SSE3__
#include <pmmintrin.h>
#endif
#ifdef __SSSE3__
#include <tmmintrin.h>
#endif
#elif (defined __ALTIVEC__)
#define EIGEN_VECTORIZE
#define EIGEN_VECTORIZE_ALTIVEC
#include <altivec.h>
// We _need_ to #undef bool as it's defined in <altivec.h> for some reason.
#undef bool
#endif
#endif
#include <cstdlib>
#include <cmath>
#include <complex>
#include <cassert>
#include <iostream> #include <iostream>
#ifdef EIGEN_VECTORIZE #ifdef EIGEN_VECTORIZE
@ -43,11 +11,6 @@ extern "C" int posix_memalign (void **, size_t, size_t) throw ();
namespace Eigen { 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/NumTraits.h"
#include "src/Core/MathFunctions.h" #include "src/Core/MathFunctions.h"
#include "src/Core/DummyPacketMath.h" #include "src/Core/DummyPacketMath.h"

47
Eigen/CoreDeclarations Normal file
View File

@ -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 <emmintrin.h>
#include <xmmintrin.h>
#ifdef __SSE3__
#include <pmmintrin.h>
#endif
#ifdef __SSSE3__
#include <tmmintrin.h>
#endif
#elif (defined __ALTIVEC__)
#define EIGEN_VECTORIZE
#define EIGEN_VECTORIZE_ALTIVEC
#include <altivec.h>
// We _need_ to #undef bool as it's defined in <altivec.h> for some reason.
#undef bool
#endif
#endif
#include <cstdlib>
#include <cmath>
#include <complex>
#include <cassert>
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

View File

@ -70,8 +70,8 @@ template<typename Derived1, typename Derived2, int Index>
struct ei_matrix_assignment_packet_unroller struct ei_matrix_assignment_packet_unroller
{ {
enum { enum {
row = Derived1::Flags&RowMajorBit ? Index / Derived1::ColsAtCompileTime : Index % Derived1::RowsAtCompileTime, row = int(Derived1::Flags)&RowMajorBit ? Index / int(Derived1::ColsAtCompileTime) : Index % Derived1::RowsAtCompileTime,
col = Derived1::Flags&RowMajorBit ? Index % 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) inline static void run(Derived1 &dst, const Derived2 &src)
@ -99,12 +99,12 @@ struct ei_matrix_assignment_packet_unroller<Derived1, Derived2, Dynamic>
}; };
template <typename Derived, typename OtherDerived, template <typename Derived, typename OtherDerived,
bool Vectorize = (Derived::Flags & OtherDerived::Flags & VectorizableBit) bool Vectorize = (int(Derived::Flags) & int(OtherDerived::Flags) & VectorizableBit)
&& ((Derived::Flags&RowMajorBit)==(OtherDerived::Flags&RowMajorBit)) && ((int(Derived::Flags)&RowMajorBit)==(int(OtherDerived::Flags)&RowMajorBit))
&& ( (Derived::Flags & OtherDerived::Flags & Like1DArrayBit) && ( (int(Derived::Flags) & int(OtherDerived::Flags) & Like1DArrayBit)
||((Derived::Flags&RowMajorBit) ||((int(Derived::Flags)&RowMajorBit)
? Derived::ColsAtCompileTime!=Dynamic && (Derived::ColsAtCompileTime%ei_packet_traits<typename Derived::Scalar>::size==0) ? int(Derived::ColsAtCompileTime)!=Dynamic && (int(Derived::ColsAtCompileTime)%ei_packet_traits<typename Derived::Scalar>::size==0)
: Derived::RowsAtCompileTime!=Dynamic && (Derived::RowsAtCompileTime%ei_packet_traits<typename Derived::Scalar>::size==0)) ), : int(Derived::RowsAtCompileTime)!=Dynamic && (int(Derived::RowsAtCompileTime)%ei_packet_traits<typename Derived::Scalar>::size==0)) ),
bool TriangularAssign = Derived::Flags & (NullLowerBit | NullUpperBit)> bool TriangularAssign = Derived::Flags & (NullLowerBit | NullUpperBit)>
struct ei_assignment_impl; struct ei_assignment_impl;
@ -156,7 +156,7 @@ struct ei_assignment_impl<Derived, OtherDerived, false, false>
{ {
ei_matrix_assignment_unroller ei_matrix_assignment_unroller
<Derived, OtherDerived, <Derived, OtherDerived,
unroll ? Derived::SizeAtCompileTime : Dynamic unroll ? int(Derived::SizeAtCompileTime) : Dynamic
>::run(dst.derived(), src.derived()); >::run(dst.derived(), src.derived());
} }
else else
@ -190,8 +190,8 @@ struct ei_assignment_impl<Derived, OtherDerived, true, false>
// std::cout << "vectorized unrolled\n"; // std::cout << "vectorized unrolled\n";
ei_matrix_assignment_packet_unroller ei_matrix_assignment_packet_unroller
<Derived, OtherDerived, <Derived, OtherDerived,
unroll && int(Derived::SizeAtCompileTime)>=ei_packet_traits<typename Derived::Scalar>::size unroll && int(Derived::SizeAtCompileTime)>=int(ei_packet_traits<typename Derived::Scalar>::size)
? Derived::SizeAtCompileTime-ei_packet_traits<typename Derived::Scalar>::size ? int(Derived::SizeAtCompileTime)-int(ei_packet_traits<typename Derived::Scalar>::size)
: Dynamic>::run(dst.const_cast_derived(), src.derived()); : Dynamic>::run(dst.const_cast_derived(), src.derived());
} }
else else

View File

@ -256,7 +256,7 @@ template<typename Derived>
template<int StoreMode> template<int StoreMode>
inline void MatrixBase<Derived>::writePacketCoeff inline void MatrixBase<Derived>::writePacketCoeff
(int row, int col, const typename ei_packet_traits<typename ei_traits<Derived>::Scalar>::type& x) (int row, int col, const typename ei_packet_traits<typename ei_traits<Derived>::Scalar>::type& x)
{ return derived().template _writePacketCoeff<StoreMode>(row,col,x); } { derived().template _writePacketCoeff<StoreMode>(row,col,x); }
#endif // EIGEN_COEFFS_H #endif // EIGEN_COEFFS_H

View File

@ -68,11 +68,11 @@ struct ei_traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
ColsAtCompileTime = Lhs::ColsAtCompileTime, ColsAtCompileTime = Lhs::ColsAtCompileTime,
MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime, MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime,
MaxColsAtCompileTime = Lhs::MaxColsAtCompileTime, MaxColsAtCompileTime = Lhs::MaxColsAtCompileTime,
Flags = ((LhsFlags | RhsFlags) & ( Flags = ((int(LhsFlags) | int(RhsFlags)) & (
DefaultLostFlagMask DefaultLostFlagMask
| Like1DArrayBit | Like1DArrayBit
| (ei_functor_traits<BinaryOp>::IsVectorizable && ((LhsFlags & RowMajorBit)==(RhsFlags & RowMajorBit)) | (ei_functor_traits<BinaryOp>::IsVectorizable && ((int(LhsFlags) & RowMajorBit)==(int(RhsFlags) & RowMajorBit))
? LhsFlags & RhsFlags & VectorizableBit : 0))), ? int(LhsFlags) & int(RhsFlags) & VectorizableBit : 0))),
CoeffReadCost = LhsCoeffReadCost + RhsCoeffReadCost + ei_functor_traits<BinaryOp>::Cost CoeffReadCost = LhsCoeffReadCost + RhsCoeffReadCost + ei_functor_traits<BinaryOp>::Cost
}; };
}; };

View File

@ -155,7 +155,7 @@ template<typename CustomNullaryOp>
const CwiseNullaryOp<CustomNullaryOp, Derived> const CwiseNullaryOp<CustomNullaryOp, Derived>
MatrixBase<Derived>::create(const CustomNullaryOp& func) MatrixBase<Derived>::create(const CustomNullaryOp& func)
{ {
return CwiseNullaryOp<CustomNullaryOp, Derived>(rows(), cols(), func); return CwiseNullaryOp<CustomNullaryOp, Derived>(RowsAtCompileTime, ColsAtCompileTime, func);
} }
/** \returns an expression of a constant matrix of value \a value /** \returns an expression of a constant matrix of value \a value

View File

@ -46,11 +46,11 @@ struct ei_traits<DiagonalCoeffs<MatrixType> >
typedef typename ei_nested<MatrixType>::type MatrixTypeNested; typedef typename ei_nested<MatrixType>::type MatrixTypeNested;
typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested; typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested;
enum { enum {
RowsAtCompileTime = MatrixType::SizeAtCompileTime == Dynamic ? Dynamic RowsAtCompileTime = int(MatrixType::SizeAtCompileTime) == Dynamic ? Dynamic
: EIGEN_ENUM_MIN(MatrixType::RowsAtCompileTime, : EIGEN_ENUM_MIN(MatrixType::RowsAtCompileTime,
MatrixType::ColsAtCompileTime), MatrixType::ColsAtCompileTime),
ColsAtCompileTime = 1, ColsAtCompileTime = 1,
MaxRowsAtCompileTime = MatrixType::MaxSizeAtCompileTime == Dynamic ? Dynamic MaxRowsAtCompileTime = int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic
: EIGEN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime, : EIGEN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime,
MatrixType::MaxColsAtCompileTime), MatrixType::MaxColsAtCompileTime),
MaxColsAtCompileTime = 1, MaxColsAtCompileTime = 1,

View File

@ -85,11 +85,11 @@ MatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const
Scalar res; Scalar res;
const bool unroll = SizeAtCompileTime const bool unroll = SizeAtCompileTime
* (_Nested::CoeffReadCost + _OtherNested::CoeffReadCost + NumTraits<Scalar>::MulCost) * (_Nested::CoeffReadCost + _OtherNested::CoeffReadCost + NumTraits<Scalar>::MulCost)
+ (SizeAtCompileTime - 1) * NumTraits<Scalar>::AddCost + (int(SizeAtCompileTime) - 1) * NumTraits<Scalar>::AddCost
<= EIGEN_UNROLLING_LIMIT; <= EIGEN_UNROLLING_LIMIT;
if(unroll) if(unroll)
ei_dot_unroller<SizeAtCompileTime-1, ei_dot_unroller<int(SizeAtCompileTime)-1,
unroll ? SizeAtCompileTime : Dynamic, unroll ? int(SizeAtCompileTime) : Dynamic,
_Nested, _OtherNested> _Nested, _OtherNested>
::run(nested, otherNested, res); ::run(nested, otherNested, res);
else else
@ -135,7 +135,7 @@ template<typename Derived>
inline const CwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived> inline const CwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::normalized() const MatrixBase<Derived>::normalized() const
{ {
return (*this) * (Scalar(1)/norm()); return (*this) * (RealScalar(1)/norm());
} }
/** \returns true if *this is approximately orthogonal to \a other, /** \returns true if *this is approximately orthogonal to \a other,

View File

@ -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_sin(int) { ei_assert(false); return 0; }
inline int ei_cos(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)); } inline int ei_pow(int x, int y) { return int(std::pow(double(x), y)); }
#else #else
inline int ei_pow(int x, int y) { return std::pow(x, y); } inline int ei_pow(int x, int y) { return std::pow(x, y); }

View File

@ -396,7 +396,7 @@ template<typename Derived> class MatrixBase
bool isOrtho(const MatrixBase<OtherDerived>& other, bool isOrtho(const MatrixBase<OtherDerived>& other,
RealScalar prec = precision<Scalar>()) const; RealScalar prec = precision<Scalar>()) const;
bool isOrtho(RealScalar prec = precision<Scalar>()) const; bool isOrtho(RealScalar prec = precision<Scalar>()) const;
template<typename OtherDerived> template<typename OtherDerived>
inline bool operator==(const MatrixBase<OtherDerived>& other) const inline bool operator==(const MatrixBase<OtherDerived>& other) const
{ return derived().cwiseEqualTo(other.derived()).all(); } { return derived().cwiseEqualTo(other.derived()).all(); }
@ -563,6 +563,11 @@ template<typename Derived> class MatrixBase
//@{ //@{
const QR<typename ei_eval<Derived>::type> qr() const; const QR<typename ei_eval<Derived>::type> qr() const;
//@} //@}
#ifdef EIGEN_MATRIX_CUSTOM_ADDONS_FILE
#include EIGEN_MATRIX_CUSTOM_ADDONS_FILE
#endif
}; };

View File

@ -45,13 +45,13 @@ struct ei_traits<Minor<MatrixType> >
typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested; typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested;
enum { enum {
RowsAtCompileTime = (MatrixType::RowsAtCompileTime != Dynamic) ? RowsAtCompileTime = (MatrixType::RowsAtCompileTime != Dynamic) ?
MatrixType::RowsAtCompileTime - 1 : Dynamic, int(MatrixType::RowsAtCompileTime) - 1 : Dynamic,
ColsAtCompileTime = (MatrixType::ColsAtCompileTime != Dynamic) ? ColsAtCompileTime = (MatrixType::ColsAtCompileTime != Dynamic) ?
MatrixType::ColsAtCompileTime - 1 : Dynamic, int(MatrixType::ColsAtCompileTime) - 1 : Dynamic,
MaxRowsAtCompileTime = (MatrixType::MaxRowsAtCompileTime != Dynamic) ? MaxRowsAtCompileTime = (MatrixType::MaxRowsAtCompileTime != Dynamic) ?
MatrixType::MaxRowsAtCompileTime - 1 : Dynamic, int(MatrixType::MaxRowsAtCompileTime) - 1 : Dynamic,
MaxColsAtCompileTime = (MatrixType::MaxColsAtCompileTime != Dynamic) ? MaxColsAtCompileTime = (MatrixType::MaxColsAtCompileTime != Dynamic) ?
MatrixType::MaxColsAtCompileTime - 1 : Dynamic, int(MatrixType::MaxColsAtCompileTime) - 1 : Dynamic,
Flags = _MatrixTypeNested::Flags & DefaultLostFlagMask, Flags = _MatrixTypeNested::Flags & DefaultLostFlagMask,
CoeffReadCost = _MatrixTypeNested::CoeffReadCost CoeffReadCost = _MatrixTypeNested::CoeffReadCost
}; };

View File

@ -94,7 +94,7 @@ struct ei_traits<PartialRedux<Direction, BinaryOp, MatrixType> >
ColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::ColsAtCompileTime, ColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::ColsAtCompileTime,
MaxRowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::MaxRowsAtCompileTime, MaxRowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::MaxRowsAtCompileTime,
MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime, 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
: (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & DefaultLostFlagMask, : (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & DefaultLostFlagMask,
TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime, TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime,
@ -182,7 +182,7 @@ MatrixBase<Derived>::redux(const BinaryOp& func) const
<= EIGEN_UNROLLING_LIMIT; <= EIGEN_UNROLLING_LIMIT;
if(unroll) if(unroll)
return ei_redux_unroller<BinaryOp, Derived, 0, return ei_redux_unroller<BinaryOp, Derived, 0,
unroll ? SizeAtCompileTime : Dynamic> unroll ? int(SizeAtCompileTime) : Dynamic>
::run(derived(), func); ::run(derived(), func);
else else
{ {
@ -304,7 +304,7 @@ bool MatrixBase<Derived>::all(void) const
<= EIGEN_UNROLLING_LIMIT; <= EIGEN_UNROLLING_LIMIT;
if(unroll) if(unroll)
return ei_all_unroller<Derived, return ei_all_unroller<Derived,
unroll ? SizeAtCompileTime : Dynamic unroll ? int(SizeAtCompileTime) : Dynamic
>::run(derived()); >::run(derived());
else else
{ {
@ -326,7 +326,7 @@ bool MatrixBase<Derived>::any(void) const
<= EIGEN_UNROLLING_LIMIT; <= EIGEN_UNROLLING_LIMIT;
if(unroll) if(unroll)
return ei_any_unroller<Derived, return ei_any_unroller<Derived,
unroll ? SizeAtCompileTime : Dynamic unroll ? int(SizeAtCompileTime) : Dynamic
>::run(derived()); >::run(derived());
else else
{ {

View File

@ -48,7 +48,7 @@ struct ei_traits<Transpose<MatrixType> >
ColsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::RowsAtCompileTime,
MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime,
MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
Flags = _MatrixTypeNested::Flags ^ RowMajorBit, Flags = int(_MatrixTypeNested::Flags) ^ RowMajorBit,
CoeffReadCost = _MatrixTypeNested::CoeffReadCost CoeffReadCost = _MatrixTypeNested::CoeffReadCost
}; };
}; };

View File

@ -80,7 +80,7 @@ struct ei_assignment_impl<Derived, OtherDerived, DummyVectorize, true>
if(unroll) if(unroll)
{ {
ei_triangular_assign_unroller ei_triangular_assign_unroller
<Derived, OtherDerived, unroll ? Derived::SizeAtCompileTime : Dynamic, Derived::Flags>::run <Derived, OtherDerived, unroll ? int(Derived::SizeAtCompileTime) : Dynamic, Derived::Flags>::run
(dst.derived(), src.derived()); (dst.derived(), src.derived());
} }
else else

View File

@ -79,7 +79,7 @@ void MatrixBase<Derived>::visit(Visitor& visitor) const
<= EIGEN_UNROLLING_LIMIT; <= EIGEN_UNROLLING_LIMIT;
if(unroll) if(unroll)
return ei_visitor_unroller<Visitor, Derived, return ei_visitor_unroller<Visitor, Derived,
unroll ? SizeAtCompileTime : Dynamic unroll ? int(SizeAtCompileTime) : Dynamic
>::run(derived(), visitor); >::run(derived(), visitor);
else else
{ {

View File

@ -158,9 +158,9 @@ class ei_corrected_matrix_flags
}; };
public: public:
enum { ret = is_vectorizable enum { ret = int(is_vectorizable)
? _flags1 | VectorizableBit ? int(_flags1) | int(VectorizableBit)
: _flags1 & ~VectorizableBit : int(_flags1) & ~int(VectorizableBit)
}; };
}; };
@ -208,8 +208,8 @@ template<typename T, int n=1> struct ei_nested
ei_is_temporary<T>::ret, ei_is_temporary<T>::ret,
T, T,
typename ei_meta_if< typename ei_meta_if<
ei_traits<T>::Flags & EvalBeforeNestingBit int(ei_traits<T>::Flags) & EvalBeforeNestingBit
|| (n+1) * NumTraits<typename ei_traits<T>::Scalar>::ReadCost < (n-1) * T::CoeffReadCost, || (n+1) * int(NumTraits<typename ei_traits<T>::Scalar>::ReadCost) < (n-1) * int(T::CoeffReadCost),
typename ei_eval<T>::type, typename ei_eval<T>::type,
const T& const T&
>::ret >::ret