* 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
#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 <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 "CoreDeclarations"
#include <iostream>
#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"

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

View File

@ -256,7 +256,7 @@ template<typename Derived>
template<int StoreMode>
inline void MatrixBase<Derived>::writePacketCoeff
(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

View File

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

View File

@ -155,7 +155,7 @@ template<typename CustomNullaryOp>
const CwiseNullaryOp<CustomNullaryOp, Derived>
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

View File

@ -46,11 +46,11 @@ struct ei_traits<DiagonalCoeffs<MatrixType> >
typedef typename ei_nested<MatrixType>::type MatrixTypeNested;
typedef typename ei_unref<MatrixTypeNested>::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,

View File

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

View File

@ -564,6 +564,11 @@ template<typename Derived> class MatrixBase
const QR<typename ei_eval<Derived>::type> qr() const;
//@}
#ifdef EIGEN_MATRIX_CUSTOM_ADDONS_FILE
#include EIGEN_MATRIX_CUSTOM_ADDONS_FILE
#endif
};
#endif // EIGEN_MATRIXBASE_H

View File

@ -45,13 +45,13 @@ struct ei_traits<Minor<MatrixType> >
typedef typename ei_unref<MatrixTypeNested>::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
};

View File

@ -94,7 +94,7 @@ struct ei_traits<PartialRedux<Direction, BinaryOp, MatrixType> >
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<Derived>::redux(const BinaryOp& func) const
<= EIGEN_UNROLLING_LIMIT;
if(unroll)
return ei_redux_unroller<BinaryOp, Derived, 0,
unroll ? SizeAtCompileTime : Dynamic>
unroll ? int(SizeAtCompileTime) : Dynamic>
::run(derived(), func);
else
{
@ -304,7 +304,7 @@ bool MatrixBase<Derived>::all(void) const
<= EIGEN_UNROLLING_LIMIT;
if(unroll)
return ei_all_unroller<Derived,
unroll ? SizeAtCompileTime : Dynamic
unroll ? int(SizeAtCompileTime) : Dynamic
>::run(derived());
else
{
@ -326,7 +326,7 @@ bool MatrixBase<Derived>::any(void) const
<= EIGEN_UNROLLING_LIMIT;
if(unroll)
return ei_any_unroller<Derived,
unroll ? SizeAtCompileTime : Dynamic
unroll ? int(SizeAtCompileTime) : Dynamic
>::run(derived());
else
{

View File

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

View File

@ -80,7 +80,7 @@ struct ei_assignment_impl<Derived, OtherDerived, DummyVectorize, true>
if(unroll)
{
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());
}
else

View File

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

View File

@ -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<typename T, int n=1> struct ei_nested
ei_is_temporary<T>::ret,
T,
typename ei_meta_if<
ei_traits<T>::Flags & EvalBeforeNestingBit
|| (n+1) * NumTraits<typename ei_traits<T>::Scalar>::ReadCost < (n-1) * T::CoeffReadCost,
int(ei_traits<T>::Flags) & EvalBeforeNestingBit
|| (n+1) * int(NumTraits<typename ei_traits<T>::Scalar>::ReadCost) < (n-1) * int(T::CoeffReadCost),
typename ei_eval<T>::type,
const T&
>::ret