From c6789a279c4def1ba33f6481ac7f9df68ba5f32b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 15 May 2008 09:40:11 +0000 Subject: [PATCH] Fix compilation issues with MSVC and NVCC. Added a few typedef of complex return types in MatrixBase (Needed by MSVC) --- Eigen/CoreDeclarations | 3 +- Eigen/src/Core/Block.h | 20 ++++++-------- Eigen/src/Core/CwiseNullaryOp.h | 18 ++++++------ Eigen/src/Core/CwiseUnaryOp.h | 2 +- Eigen/src/Core/Dot.h | 2 +- Eigen/src/Core/MatrixBase.h | 49 +++++++++++++++++++-------------- Eigen/src/Core/ProductWIP.h | 10 +++---- Eigen/src/Core/util/Macros.h | 2 +- Eigen/src/Core/util/Meta.h | 2 +- 9 files changed, 57 insertions(+), 51 deletions(-) diff --git a/Eigen/CoreDeclarations b/Eigen/CoreDeclarations index 9a44e4dc3..d141a7c08 100644 --- a/Eigen/CoreDeclarations +++ b/Eigen/CoreDeclarations @@ -6,7 +6,7 @@ #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 +#define EIGEN_GNUC_AT_LEAST(x,y) 0 #endif #ifndef EIGEN_DONT_VECTORIZE @@ -34,6 +34,7 @@ #include #include #include +#include namespace Eigen { diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index ef6b84eff..d5b1d9de1 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -321,25 +321,23 @@ inline const Block MatrixBase::end(int size) const */ template template -inline Block::RowsAtCompileTime == 1 ? 1 : Size, - ei_traits::ColsAtCompileTime == 1 ? 1 : Size> +inline typename MatrixBase::template SubVectorReturnType::Type MatrixBase::start() { ei_assert(IsVectorAtCompileTime); - return Block(derived(), 0, 0); + return Block(derived(), 0, 0); } /** This is the const version of start().*/ template template -inline const Block::RowsAtCompileTime == 1 ? 1 : Size, - ei_traits::ColsAtCompileTime == 1 ? 1 : Size> +inline const typename MatrixBase::template SubVectorReturnType::Type MatrixBase::start() const { ei_assert(IsVectorAtCompileTime); - return Block(derived(), 0, 0); + return Block(derived(), 0, 0); } /** \returns a fixed-size expression of the last coefficients of *this. @@ -355,8 +353,7 @@ MatrixBase::start() const */ template template -inline Block::RowsAtCompileTime == 1 ? 1 : Size, - ei_traits::ColsAtCompileTime == 1 ? 1 : Size> +inline typename MatrixBase::template SubVectorReturnType::Type MatrixBase::end() { ei_assert(IsVectorAtCompileTime); @@ -370,8 +367,7 @@ MatrixBase::end() /** This is the const version of end.*/ template template -inline const Block::RowsAtCompileTime == 1 ? 1 : Size, - ei_traits::ColsAtCompileTime == 1 ? 1 : Size> +inline const typename MatrixBase::template SubVectorReturnType::Type MatrixBase::end() const { ei_assert(IsVectorAtCompileTime); diff --git a/Eigen/src/Core/CwiseNullaryOp.h b/Eigen/src/Core/CwiseNullaryOp.h index 5efcc27f3..7d47fa198 100644 --- a/Eigen/src/Core/CwiseNullaryOp.h +++ b/Eigen/src/Core/CwiseNullaryOp.h @@ -172,7 +172,7 @@ MatrixBase::create(const CustomNullaryOp& func) * \sa class CwiseNullaryOp */ template -const CwiseNullaryOp::Scalar>, Derived> +const typename MatrixBase::ConstantReturnType MatrixBase::constant(int rows, int cols, const Scalar& value) { return create(rows, cols, ei_scalar_constant_op(value)); @@ -194,7 +194,7 @@ MatrixBase::constant(int rows, int cols, const Scalar& value) * \sa class CwiseNullaryOp */ template -const CwiseNullaryOp::Scalar>, Derived> +const typename MatrixBase::ConstantReturnType MatrixBase::constant(int size, const Scalar& value) { return create(size, ei_scalar_constant_op(value)); @@ -210,7 +210,7 @@ MatrixBase::constant(int size, const Scalar& value) * \sa class CwiseNullaryOp */ template -const CwiseNullaryOp::Scalar>, Derived> +const typename MatrixBase::ConstantReturnType MatrixBase::constant(const Scalar& value) { return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_constant_op(value)); @@ -254,7 +254,7 @@ Derived& MatrixBase::setConstant(const Scalar& value) * \sa zero(), zero(int) */ template -const CwiseNullaryOp::Scalar>, Derived> +const typename MatrixBase::ConstantReturnType MatrixBase::zero(int rows, int cols) { return constant(rows, cols, Scalar(0)); @@ -277,7 +277,7 @@ MatrixBase::zero(int rows, int cols) * \sa zero(), zero(int,int) */ template -const CwiseNullaryOp::Scalar>, Derived> +const typename MatrixBase::ConstantReturnType MatrixBase::zero(int size) { return constant(size, Scalar(0)); @@ -294,7 +294,7 @@ MatrixBase::zero(int size) * \sa zero(int), zero(int,int) */ template -const CwiseNullaryOp::Scalar>, Derived> +const typename MatrixBase::ConstantReturnType MatrixBase::zero() { return constant(Scalar(0)); @@ -349,7 +349,7 @@ Derived& MatrixBase::setZero() * \sa ones(), ones(int), isOnes(), class Ones */ template -const CwiseNullaryOp::Scalar>, Derived> +const typename MatrixBase::ConstantReturnType MatrixBase::ones(int rows, int cols) { return constant(rows, cols, Scalar(1)); @@ -372,7 +372,7 @@ MatrixBase::ones(int rows, int cols) * \sa ones(), ones(int,int), isOnes(), class Ones */ template -const CwiseNullaryOp::Scalar>, Derived> +const typename MatrixBase::ConstantReturnType MatrixBase::ones(int size) { return constant(size, Scalar(1)); @@ -389,7 +389,7 @@ MatrixBase::ones(int size) * \sa ones(int), ones(int,int), isOnes(), class Ones */ template -const CwiseNullaryOp::Scalar>, Derived> +const typename MatrixBase::ConstantReturnType MatrixBase::ones() { return constant(Scalar(1)); diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index e1527da84..32ddfe2ed 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -165,7 +165,7 @@ MatrixBase::cast() const /** \relates MatrixBase */ template -inline const CwiseUnaryOp::Scalar>, Derived> +inline const typename MatrixBase::ScalarMultipleReturnType MatrixBase::operator*(const Scalar& scalar) const { return CwiseUnaryOp, Derived> diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index b0ec14a33..0284ffd75 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -132,7 +132,7 @@ inline typename NumTraits::Scalar>::Real MatrixBase< * \sa norm() */ template -inline const CwiseUnaryOp::Scalar>, Derived> +inline const typename MatrixBase::ScalarMultipleReturnType MatrixBase::normalized() const { return (*this) * (RealScalar(1)/norm()); diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index ee6a197a9..101571ea1 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -163,6 +163,20 @@ template class MatrixBase * \sa rows(), cols(), IsVectorAtCompileTime. */ inline bool isVector() const { return rows()==1 || cols()==1; } //@} + + /// \name Default return types + //@{ + /** Represents a constant matrix */ + typedef CwiseNullaryOp,Derived> ConstantReturnType; + /** Represents a vector block of a matrix */ + template struct SubVectorReturnType + { + typedef Block::RowsAtCompileTime == 1 ? 1 : Size), + (ei_traits::ColsAtCompileTime == 1 ? 1 : Size)> Type; + }; + /** Represents a product scalar-matrix */ + typedef CwiseUnaryOp, Derived> ScalarMultipleReturnType; + //@} /// \name Copying and initialization //@{ @@ -244,8 +258,7 @@ template class MatrixBase Derived& operator*=(const Scalar& other); Derived& operator/=(const Scalar& other); - const CwiseUnaryOp::Scalar>, Derived> - operator*(const Scalar& scalar) const; + const ScalarMultipleReturnType operator*(const Scalar& scalar) const; const CwiseUnaryOp::Scalar>, Derived> operator/(const Scalar& scalar) const; @@ -274,7 +287,7 @@ template class MatrixBase Scalar dot(const MatrixBase& other) const; RealScalar norm2() const; RealScalar norm() const; - const CwiseUnaryOp::Scalar>, Derived> normalized() const; + const ScalarMultipleReturnType normalized() const; Transpose transpose(); const Transpose transpose() const; @@ -320,18 +333,14 @@ template class MatrixBase template const Block corner(CornerType type) const; template - Block::RowsAtCompileTime == 1 ? 1 : Size, - ei_traits::ColsAtCompileTime == 1 ? 1 : Size> start(); + typename SubVectorReturnType::Type start(void); template - const Block::RowsAtCompileTime == 1 ? 1 : Size, - ei_traits::ColsAtCompileTime == 1 ? 1 : Size> start() const; + const typename SubVectorReturnType::Type start() const; template - Block::RowsAtCompileTime == 1 ? 1 : Size, - ei_traits::ColsAtCompileTime == 1 ? 1 : Size> end(); + typename SubVectorReturnType::Type end(); template - const Block::RowsAtCompileTime == 1 ? 1 : Size, - ei_traits::ColsAtCompileTime == 1 ? 1 : Size> end() const; + const typename SubVectorReturnType::Type end() const; DiagonalCoeffs diagonal(); const DiagonalCoeffs diagonal() const; @@ -339,11 +348,11 @@ template class MatrixBase /// \name Generating special matrices //@{ - static const CwiseNullaryOp,Derived> + static const ConstantReturnType constant(int rows, int cols, const Scalar& value); - static const CwiseNullaryOp,Derived> + static const ConstantReturnType constant(int size, const Scalar& value); - static const CwiseNullaryOp,Derived> + static const ConstantReturnType constant(const Scalar& value); template @@ -359,12 +368,12 @@ template class MatrixBase static const CwiseNullaryOp,Derived> random(int rows, int cols); static const CwiseNullaryOp,Derived> random(int size); static const CwiseNullaryOp,Derived> random(); - static const CwiseNullaryOp,Derived> zero(int rows, int cols); - static const CwiseNullaryOp,Derived> zero(int size); - static const CwiseNullaryOp,Derived> zero(); - static const CwiseNullaryOp,Derived> ones(int rows, int cols); - static const CwiseNullaryOp,Derived> ones(int size); - static const CwiseNullaryOp,Derived> ones(); + static const ConstantReturnType zero(int rows, int cols); + static const ConstantReturnType zero(int size); + static const ConstantReturnType zero(); + static const ConstantReturnType ones(int rows, int cols); + static const ConstantReturnType ones(int size); + static const ConstantReturnType ones(); static const CwiseNullaryOp,Derived> identity(); static const CwiseNullaryOp,Derived> identity(int rows, int cols); diff --git a/Eigen/src/Core/ProductWIP.h b/Eigen/src/Core/ProductWIP.h index b7865bb70..c6d5f6d95 100644 --- a/Eigen/src/Core/ProductWIP.h +++ b/Eigen/src/Core/ProductWIP.h @@ -167,13 +167,13 @@ template class ei_product_eval_to_column_major template struct ei_product_nested_rhs { typedef typename ei_meta_if< - ei_is_temporary::ret && !(ei_traits::Flags & RowMajorBit), + (ei_is_temporary::ret && !(ei_traits::Flags & RowMajorBit)), T, typename ei_meta_if< - (ei_traits::Flags & EvalBeforeNestingBit) + ((ei_traits::Flags & EvalBeforeNestingBit) || (ei_traits::Flags & RowMajorBit) || (!(ei_traits::Flags & DirectAccessBit)) - || (n+1) * NumTraits::Scalar>::ReadCost < (n-1) * T::CoeffReadCost, + || (n+1) * (NumTraits::Scalar>::ReadCost) < (n-1) * T::CoeffReadCost), typename ei_product_eval_to_column_major::type, const T& >::ret @@ -185,10 +185,10 @@ template struct ei_product_nested_lhs typedef typename ei_meta_if< ei_is_temporary::ret && !(ei_traits::Flags & RowMajorBit), T, - typename ei_meta_if< + typename ei_meta_if<( (ei_traits::Flags & EvalBeforeNestingBit) || (!(ei_traits::Flags & DirectAccessBit)) - || (n+1) * NumTraits::Scalar>::ReadCost < (n-1) * T::CoeffReadCost, + || (n+1) * (NumTraits::Scalar>::ReadCost) < (n-1) * T::CoeffReadCost), typename ei_eval::type, const T& >::ret diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index a05067c24..93694df09 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -135,7 +135,7 @@ 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; \ -typedef Eigen::Flagged Temporary; \ +typedef Eigen::Flagged Temporary; \ enum { RowsAtCompileTime = Base::RowsAtCompileTime, \ ColsAtCompileTime = Base::ColsAtCompileTime, \ MaxRowsAtCompileTime = Base::MaxRowsAtCompileTime, \ diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index 9c3630d02..e3cf3ba6b 100644 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -194,7 +194,7 @@ template struct ei_unconst { typedef T type; }; template struct ei_is_temporary { - enum { ret = ei_traits::Flags & TemporaryBit }; + enum { ret = int(ei_traits::Flags) & TemporaryBit }; }; template struct ei_nested