Several compilation fixes for MSVC and NVCC, basically:

- added explicit enum to int conversion where needed
- if a function is not defined as declared and the return type is "tricky"
  then the type must be typedefined somewhere. A "tricky return type" can be:
  * a template class with a default parameter which depends on another template parameter
  * a nested template class, or type of a nested template class
This commit is contained in:
Gael Guennebaud 2008-07-29 16:33:07 +00:00
parent e0215ee510
commit 842c4f8bfa
17 changed files with 219 additions and 207 deletions

View File

@ -31,7 +31,7 @@
* *
* \returns an expression of the coefficient-wise square root of *this. */ * \returns an expression of the coefficient-wise square root of *this. */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_sqrt_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_sqrt_op)
Cwise<ExpressionType>::sqrt() const Cwise<ExpressionType>::sqrt() const
{ {
return _expression(); return _expression();
@ -41,7 +41,7 @@ Cwise<ExpressionType>::sqrt() const
* *
* \returns an expression of the coefficient-wise exponential of *this. */ * \returns an expression of the coefficient-wise exponential of *this. */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_exp_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_exp_op)
Cwise<ExpressionType>::exp() const Cwise<ExpressionType>::exp() const
{ {
return _expression(); return _expression();
@ -51,7 +51,7 @@ Cwise<ExpressionType>::exp() const
* *
* \returns an expression of the coefficient-wise logarithm of *this. */ * \returns an expression of the coefficient-wise logarithm of *this. */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_log_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_log_op)
Cwise<ExpressionType>::log() const Cwise<ExpressionType>::log() const
{ {
return _expression(); return _expression();
@ -61,7 +61,7 @@ Cwise<ExpressionType>::log() const
* *
* \returns an expression of the coefficient-wise cosine of *this. */ * \returns an expression of the coefficient-wise cosine of *this. */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_cos_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_cos_op)
Cwise<ExpressionType>::cos() const Cwise<ExpressionType>::cos() const
{ {
return _expression(); return _expression();
@ -72,7 +72,7 @@ Cwise<ExpressionType>::cos() const
* *
* \returns an expression of the coefficient-wise sine of *this. */ * \returns an expression of the coefficient-wise sine of *this. */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_sin_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_sin_op)
Cwise<ExpressionType>::sin() const Cwise<ExpressionType>::sin() const
{ {
return _expression(); return _expression();
@ -83,10 +83,10 @@ Cwise<ExpressionType>::sin() const
* *
* \returns an expression of the coefficient-wise power of *this to the given exponent. */ * \returns an expression of the coefficient-wise power of *this to the given exponent. */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_pow_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_pow_op)
Cwise<ExpressionType>::pow(const Scalar& exponent) const Cwise<ExpressionType>::pow(const Scalar& exponent) const
{ {
return typename UnOp<ei_scalar_pow_op>::ReturnType(_expression(), ei_scalar_pow_op<Scalar>(exponent)); return EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_pow_op)(_expression(), ei_scalar_pow_op<Scalar>(exponent));
} }
@ -94,7 +94,7 @@ Cwise<ExpressionType>::pow(const Scalar& exponent) const
* *
* \returns an expression of the coefficient-wise inverse of *this. */ * \returns an expression of the coefficient-wise inverse of *this. */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_inverse_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_inverse_op)
Cwise<ExpressionType>::inverse() const Cwise<ExpressionType>::inverse() const
{ {
return _expression(); return _expression();
@ -104,7 +104,7 @@ Cwise<ExpressionType>::inverse() const
* *
* \returns an expression of the coefficient-wise square of *this. */ * \returns an expression of the coefficient-wise square of *this. */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_square_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_square_op)
Cwise<ExpressionType>::square() const Cwise<ExpressionType>::square() const
{ {
return _expression(); return _expression();
@ -114,7 +114,7 @@ Cwise<ExpressionType>::square() const
* *
* \returns an expression of the coefficient-wise cube of *this. */ * \returns an expression of the coefficient-wise cube of *this. */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_cube_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_cube_op)
Cwise<ExpressionType>::cube() const Cwise<ExpressionType>::cube() const
{ {
return _expression(); return _expression();
@ -133,10 +133,10 @@ Cwise<ExpressionType>::cube() const
*/ */
template<typename ExpressionType> template<typename ExpressionType>
template<typename OtherDerived> template<typename OtherDerived>
inline const typename Cwise<ExpressionType>::template BinOp<std::less, OtherDerived>::ReturnType inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
Cwise<ExpressionType>::operator<(const MatrixBase<OtherDerived> &other) const Cwise<ExpressionType>::operator<(const MatrixBase<OtherDerived> &other) const
{ {
return typename BinOp<std::less, OtherDerived>::ReturnType(_expression(), other.derived()); return EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)(_expression(), other.derived());
} }
/** \array_module /** \array_module
@ -147,10 +147,10 @@ Cwise<ExpressionType>::operator<(const MatrixBase<OtherDerived> &other) const
*/ */
template<typename ExpressionType> template<typename ExpressionType>
template<typename OtherDerived> template<typename OtherDerived>
inline const typename Cwise<ExpressionType>::template BinOp<std::less_equal, OtherDerived>::ReturnType inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
Cwise<ExpressionType>::operator<=(const MatrixBase<OtherDerived> &other) const Cwise<ExpressionType>::operator<=(const MatrixBase<OtherDerived> &other) const
{ {
return typename BinOp<std::less_equal, OtherDerived>::ReturnType(_expression(), other.derived()); return EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)(_expression(), other.derived());
} }
/** \array_module /** \array_module
@ -163,10 +163,10 @@ Cwise<ExpressionType>::operator<=(const MatrixBase<OtherDerived> &other) const
*/ */
template<typename ExpressionType> template<typename ExpressionType>
template<typename OtherDerived> template<typename OtherDerived>
inline const typename Cwise<ExpressionType>::template BinOp<std::greater, OtherDerived>::ReturnType inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
Cwise<ExpressionType>::operator>(const MatrixBase<OtherDerived> &other) const Cwise<ExpressionType>::operator>(const MatrixBase<OtherDerived> &other) const
{ {
return typename BinOp<std::greater, OtherDerived>::ReturnType(_expression(), other.derived()); return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)(_expression(), other.derived());
} }
/** \array_module /** \array_module
@ -177,10 +177,10 @@ Cwise<ExpressionType>::operator>(const MatrixBase<OtherDerived> &other) const
*/ */
template<typename ExpressionType> template<typename ExpressionType>
template<typename OtherDerived> template<typename OtherDerived>
inline const typename Cwise<ExpressionType>::template BinOp<std::greater_equal, OtherDerived>::ReturnType inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
Cwise<ExpressionType>::operator>=(const MatrixBase<OtherDerived> &other) const Cwise<ExpressionType>::operator>=(const MatrixBase<OtherDerived> &other) const
{ {
return typename BinOp<std::greater_equal, OtherDerived>::ReturnType(_expression(), other.derived()); return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)(_expression(), other.derived());
} }
/** \array_module /** \array_module
@ -191,10 +191,10 @@ Cwise<ExpressionType>::operator>=(const MatrixBase<OtherDerived> &other) const
*/ */
template<typename ExpressionType> template<typename ExpressionType>
template<typename OtherDerived> template<typename OtherDerived>
inline const typename Cwise<ExpressionType>::template BinOp<std::equal_to, OtherDerived>::ReturnType inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
Cwise<ExpressionType>::operator==(const MatrixBase<OtherDerived> &other) const Cwise<ExpressionType>::operator==(const MatrixBase<OtherDerived> &other) const
{ {
return typename BinOp<std::equal_to, OtherDerived>::ReturnType(_expression(), other.derived()); return EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)(_expression(), other.derived());
} }
/** \array_module /** \array_module
@ -205,10 +205,10 @@ Cwise<ExpressionType>::operator==(const MatrixBase<OtherDerived> &other) const
*/ */
template<typename ExpressionType> template<typename ExpressionType>
template<typename OtherDerived> template<typename OtherDerived>
inline const typename Cwise<ExpressionType>::template BinOp<std::not_equal_to, OtherDerived>::ReturnType inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
Cwise<ExpressionType>::operator!=(const MatrixBase<OtherDerived> &other) const Cwise<ExpressionType>::operator!=(const MatrixBase<OtherDerived> &other) const
{ {
return typename BinOp<std::not_equal_to, OtherDerived>::ReturnType(_expression(), other.derived()); return EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)(_expression(), other.derived());
} }

View File

@ -61,9 +61,11 @@ struct ei_traits<PartialReduxExpr<MatrixType, MemberOp, Direction> >
Flags = ((int(RowsAtCompileTime) == Dynamic || int(ColsAtCompileTime) == Dynamic) Flags = ((int(RowsAtCompileTime) == Dynamic || int(ColsAtCompileTime) == Dynamic)
? (unsigned int)_MatrixTypeNested::Flags ? (unsigned int)_MatrixTypeNested::Flags
: (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & HereditaryBits, : (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & HereditaryBits,
TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime, TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime
CoeffReadCost = TraversalSize * _MatrixTypeNested::CoeffReadCost };
+ MemberOp::template Cost<InputScalar,TraversalSize>::value typedef typename MemberOp::template Cost<InputScalar,int(TraversalSize)> CostOpType;
enum {
CoeffReadCost = TraversalSize * _MatrixTypeNested::CoeffReadCost + CostOpType::value
}; };
}; };

View File

@ -147,7 +147,7 @@ typename Derived::Eval Cholesky<MatrixType>::solve(const MatrixBase<Derived> &b)
* \returns the Cholesky decomposition of \c *this * \returns the Cholesky decomposition of \c *this
*/ */
template<typename Derived> template<typename Derived>
inline const Cholesky<typename ei_eval<Derived>::type> inline const Cholesky<typename MatrixBase<Derived>::EvalType>
MatrixBase<Derived>::cholesky() const MatrixBase<Derived>::cholesky() const
{ {
return Cholesky<typename ei_eval<Derived>::type>(derived()); return Cholesky<typename ei_eval<Derived>::type>(derived());

View File

@ -159,7 +159,7 @@ typename Derived::Eval CholeskyWithoutSquareRoot<MatrixType>::solve(const Matrix
* \returns the Cholesky decomposition without square root of \c *this * \returns the Cholesky decomposition without square root of \c *this
*/ */
template<typename Derived> template<typename Derived>
inline const CholeskyWithoutSquareRoot<typename ei_eval<Derived>::type> inline const CholeskyWithoutSquareRoot<typename MatrixBase<Derived>::EvalType>
MatrixBase<Derived>::choleskyNoSqrt() const MatrixBase<Derived>::choleskyNoSqrt() const
{ {
return derived(); return derived();

View File

@ -47,20 +47,20 @@ private:
enum { enum {
MightVectorize = (int(Derived::Flags) & int(OtherDerived::Flags) & ActualPacketAccessBit) MightVectorize = (int(Derived::Flags) & int(OtherDerived::Flags) & ActualPacketAccessBit)
&& ((int(Derived::Flags)&RowMajorBit)==(int(OtherDerived::Flags)&RowMajorBit)), && ((int(Derived::Flags)&RowMajorBit)==(int(OtherDerived::Flags)&RowMajorBit)),
MayInnerVectorize = MightVectorize && InnerSize!=Dynamic && int(InnerSize)%int(PacketSize)==0, MayInnerVectorize = MightVectorize && int(InnerSize)!=Dynamic && int(InnerSize)%int(PacketSize)==0,
MayLinearVectorize = MightVectorize && (int(Derived::Flags) & int(OtherDerived::Flags) & LinearAccessBit), MayLinearVectorize = MightVectorize && (int(Derived::Flags) & int(OtherDerived::Flags) & LinearAccessBit),
MaySliceVectorize = MightVectorize && InnerMaxSize==Dynamic /* slice vectorization can be slow, so we only MaySliceVectorize = MightVectorize && int(InnerMaxSize)==Dynamic /* slice vectorization can be slow, so we only
want it if the slices are big, which is indicated by InnerMaxSize rather than InnerSize, think of the case want it if the slices are big, which is indicated by InnerMaxSize rather than InnerSize, think of the case
of a dynamic block in a fixed-size matrix */ of a dynamic block in a fixed-size matrix */
}; };
public: public:
enum { enum {
Vectorization = MayInnerVectorize ? InnerVectorization Vectorization = int(MayInnerVectorize) ? int(InnerVectorization)
: MayLinearVectorize ? LinearVectorization : int(MayLinearVectorize) ? int(LinearVectorization)
: MaySliceVectorize ? SliceVectorization : int(MaySliceVectorize) ? int(SliceVectorization)
: NoVectorization : int(NoVectorization)
}; };
private: private:
@ -74,13 +74,13 @@ public:
enum { enum {
Unrolling = (int(Vectorization) == int(InnerVectorization) || int(Vectorization) == int(NoVectorization)) Unrolling = (int(Vectorization) == int(InnerVectorization) || int(Vectorization) == int(NoVectorization))
? ( ? (
MayUnrollCompletely ? CompleteUnrolling int(MayUnrollCompletely) ? int(CompleteUnrolling)
: MayUnrollInner ? InnerUnrolling : int(MayUnrollInner) ? int(InnerUnrolling)
: NoUnrolling : int(NoUnrolling)
) )
: int(Vectorization) == int(LinearVectorization) : int(Vectorization) == int(LinearVectorization)
? ( MayUnrollCompletely ? CompleteUnrolling : NoUnrolling ) ? ( int(MayUnrollCompletely) ? int(CompleteUnrolling) : int(NoUnrolling) )
: NoUnrolling : int(NoUnrolling)
}; };
}; };

View File

@ -336,7 +336,6 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block<MatrixTy
const ei_int_if_dynamic<ColsAtCompileTime> m_blockCols; const ei_int_if_dynamic<ColsAtCompileTime> m_blockCols;
}; };
/** \returns a dynamic-size expression of a block in *this. /** \returns a dynamic-size expression of a block in *this.
* *
* \param startRow the first row in the block * \param startRow the first row in the block
@ -356,18 +355,18 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block<MatrixTy
* \sa class Block, block(int,int) * \sa class Block, block(int,int)
*/ */
template<typename Derived> template<typename Derived>
inline Block<Derived> MatrixBase<Derived> inline typename BlockReturnType<Derived>::Type MatrixBase<Derived>
::block(int startRow, int startCol, int blockRows, int blockCols) ::block(int startRow, int startCol, int blockRows, int blockCols)
{ {
return Block<Derived>(derived(), startRow, startCol, blockRows, blockCols); return typename BlockReturnType<Derived>::Type(derived(), startRow, startCol, blockRows, blockCols);
} }
/** This is the const version of block(int,int,int,int). */ /** This is the const version of block(int,int,int,int). */
template<typename Derived> template<typename Derived>
inline const Block<Derived> MatrixBase<Derived> inline const typename BlockReturnType<Derived>::Type MatrixBase<Derived>
::block(int startRow, int startCol, int blockRows, int blockCols) const ::block(int startRow, int startCol, int blockRows, int blockCols) const
{ {
return Block<Derived>(derived(), startRow, startCol, blockRows, blockCols); return typename BlockReturnType<Derived>::Type(derived(), startRow, startCol, blockRows, blockCols);
} }
/** \returns a dynamic-size expression of a block in *this. /** \returns a dynamic-size expression of a block in *this.
@ -389,11 +388,11 @@ inline const Block<Derived> MatrixBase<Derived>
* \sa class Block, block(int) * \sa class Block, block(int)
*/ */
template<typename Derived> template<typename Derived>
inline Block<Derived> MatrixBase<Derived> inline typename BlockReturnType<Derived>::SubVectorType MatrixBase<Derived>
::block(int start, int size) ::block(int start, int size)
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : start, return typename BlockReturnType<Derived>::SubVectorType(derived(), RowsAtCompileTime == 1 ? 0 : start,
ColsAtCompileTime == 1 ? 0 : start, ColsAtCompileTime == 1 ? 0 : start,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
ColsAtCompileTime == 1 ? 1 : size); ColsAtCompileTime == 1 ? 1 : size);
@ -401,11 +400,11 @@ inline Block<Derived> MatrixBase<Derived>
/** This is the const version of block(int,int).*/ /** This is the const version of block(int,int).*/
template<typename Derived> template<typename Derived>
inline const Block<Derived> MatrixBase<Derived> inline const typename BlockReturnType<Derived>::SubVectorType
::block(int start, int size) const MatrixBase<Derived>::block(int start, int size) const
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : start, return typename BlockReturnType<Derived>::SubVectorType(derived(), RowsAtCompileTime == 1 ? 0 : start,
ColsAtCompileTime == 1 ? 0 : start, ColsAtCompileTime == 1 ? 0 : start,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
ColsAtCompileTime == 1 ? 1 : size); ColsAtCompileTime == 1 ? 1 : size);
@ -429,7 +428,7 @@ inline const Block<Derived> MatrixBase<Derived>
* \sa class Block, block(int,int) * \sa class Block, block(int,int)
*/ */
template<typename Derived> template<typename Derived>
inline typename MatrixBase<Derived>::template SubVectorReturnType<Dynamic>::Type inline typename BlockReturnType<Derived,Dynamic>::SubVectorType
MatrixBase<Derived>::start(int size) MatrixBase<Derived>::start(int size)
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
@ -443,7 +442,7 @@ MatrixBase<Derived>::start(int size)
/** This is the const version of start(int).*/ /** This is the const version of start(int).*/
template<typename Derived> template<typename Derived>
inline const typename MatrixBase<Derived>::template SubVectorReturnType<Dynamic>::Type inline const typename BlockReturnType<Derived,Dynamic>::SubVectorType
MatrixBase<Derived>::start(int size) const MatrixBase<Derived>::start(int size) const
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
@ -473,7 +472,7 @@ MatrixBase<Derived>::start(int size) const
* \sa class Block, block(int,int) * \sa class Block, block(int,int)
*/ */
template<typename Derived> template<typename Derived>
inline typename MatrixBase<Derived>::template SubVectorReturnType<Dynamic>::Type inline typename BlockReturnType<Derived,Dynamic>::SubVectorType
MatrixBase<Derived>::end(int size) MatrixBase<Derived>::end(int size)
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
@ -489,7 +488,7 @@ MatrixBase<Derived>::end(int size)
/** This is the const version of end(int).*/ /** This is the const version of end(int).*/
template<typename Derived> template<typename Derived>
inline const typename MatrixBase<Derived>::template SubVectorReturnType<Dynamic>::Type inline const typename BlockReturnType<Derived,Dynamic>::SubVectorType
MatrixBase<Derived>::end(int size) const MatrixBase<Derived>::end(int size) const
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
@ -518,7 +517,7 @@ MatrixBase<Derived>::end(int size) const
*/ */
template<typename Derived> template<typename Derived>
template<int Size> template<int Size>
inline typename MatrixBase<Derived>::template SubVectorReturnType<Size>::Type inline typename BlockReturnType<Derived,Size>::SubVectorType
MatrixBase<Derived>::start() MatrixBase<Derived>::start()
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
@ -529,7 +528,7 @@ MatrixBase<Derived>::start()
/** This is the const version of start<int>().*/ /** This is the const version of start<int>().*/
template<typename Derived> template<typename Derived>
template<int Size> template<int Size>
inline const typename MatrixBase<Derived>::template SubVectorReturnType<Size>::Type inline const typename BlockReturnType<Derived,Size>::SubVectorType
MatrixBase<Derived>::start() const MatrixBase<Derived>::start() const
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
@ -550,7 +549,7 @@ MatrixBase<Derived>::start() const
*/ */
template<typename Derived> template<typename Derived>
template<int Size> template<int Size>
inline typename MatrixBase<Derived>::template SubVectorReturnType<Size>::Type inline typename BlockReturnType<Derived,Size>::SubVectorType
MatrixBase<Derived>::end() MatrixBase<Derived>::end()
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
@ -564,7 +563,7 @@ MatrixBase<Derived>::end()
/** This is the const version of end<int>.*/ /** This is the const version of end<int>.*/
template<typename Derived> template<typename Derived>
template<int Size> template<int Size>
inline const typename MatrixBase<Derived>::template SubVectorReturnType<Size>::Type inline const typename BlockReturnType<Derived,Size>::SubVectorType
MatrixBase<Derived>::end() const MatrixBase<Derived>::end() const
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
@ -594,7 +593,7 @@ MatrixBase<Derived>::end() const
* \sa class Block, block(int,int,int,int) * \sa class Block, block(int,int,int,int)
*/ */
template<typename Derived> template<typename Derived>
inline Block<Derived> MatrixBase<Derived> inline typename BlockReturnType<Derived>::Type MatrixBase<Derived>
::corner(CornerType type, int cRows, int cCols) ::corner(CornerType type, int cRows, int cCols)
{ {
switch(type) switch(type)
@ -602,33 +601,33 @@ inline Block<Derived> MatrixBase<Derived>
default: default:
ei_assert(false && "Bad corner type."); ei_assert(false && "Bad corner type.");
case TopLeft: case TopLeft:
return Block<Derived>(derived(), 0, 0, cRows, cCols); return typename BlockReturnType<Derived>::Type(derived(), 0, 0, cRows, cCols);
case TopRight: case TopRight:
return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols); return typename BlockReturnType<Derived>::Type(derived(), 0, cols() - cCols, cRows, cCols);
case BottomLeft: case BottomLeft:
return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols); return typename BlockReturnType<Derived>::Type(derived(), rows() - cRows, 0, cRows, cCols);
case BottomRight: case BottomRight:
return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols); return typename BlockReturnType<Derived>::Type(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
} }
} }
/** This is the const version of corner(CornerType, int, int).*/ /** This is the const version of corner(CornerType, int, int).*/
template<typename Derived> template<typename Derived>
inline const Block<Derived> MatrixBase<Derived> inline const typename BlockReturnType<Derived>::Type
::corner(CornerType type, int cRows, int cCols) const MatrixBase<Derived>::corner(CornerType type, int cRows, int cCols) const
{ {
switch(type) switch(type)
{ {
default: default:
ei_assert(false && "Bad corner type."); ei_assert(false && "Bad corner type.");
case TopLeft: case TopLeft:
return Block<Derived>(derived(), 0, 0, cRows, cCols); return typename BlockReturnType<Derived>::Type(derived(), 0, 0, cRows, cCols);
case TopRight: case TopRight:
return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols); return typename BlockReturnType<Derived>::Type(derived(), 0, cols() - cCols, cRows, cCols);
case BottomLeft: case BottomLeft:
return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols); return typename BlockReturnType<Derived>::Type(derived(), rows() - cRows, 0, cRows, cCols);
case BottomRight: case BottomRight:
return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols); return typename BlockReturnType<Derived>::Type(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
} }
} }
@ -646,8 +645,8 @@ inline const Block<Derived> MatrixBase<Derived>
*/ */
template<typename Derived> template<typename Derived>
template<int CRows, int CCols> template<int CRows, int CCols>
inline Block<Derived, CRows, CCols> MatrixBase<Derived> inline typename BlockReturnType<Derived, CRows, CCols>::Type
::corner(CornerType type) MatrixBase<Derived>::corner(CornerType type)
{ {
switch(type) switch(type)
{ {
@ -667,8 +666,8 @@ inline Block<Derived, CRows, CCols> MatrixBase<Derived>
/** This is the const version of corner<int, int>(CornerType).*/ /** This is the const version of corner<int, int>(CornerType).*/
template<typename Derived> template<typename Derived>
template<int CRows, int CCols> template<int CRows, int CCols>
inline const Block<Derived, CRows, CCols> MatrixBase<Derived> inline const typename BlockReturnType<Derived, CRows, CCols>::Type
::corner(CornerType type) const MatrixBase<Derived>::corner(CornerType type) const
{ {
switch(type) switch(type)
{ {
@ -705,8 +704,8 @@ inline const Block<Derived, CRows, CCols> MatrixBase<Derived>
*/ */
template<typename Derived> template<typename Derived>
template<int BlockRows, int BlockCols> template<int BlockRows, int BlockCols>
inline Block<Derived, BlockRows, BlockCols> MatrixBase<Derived> inline typename BlockReturnType<Derived, BlockRows, BlockCols>::Type
::block(int startRow, int startCol) MatrixBase<Derived>::block(int startRow, int startCol)
{ {
return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol); return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
} }
@ -714,8 +713,8 @@ inline Block<Derived, BlockRows, BlockCols> MatrixBase<Derived>
/** This is the const version of block<>(int, int). */ /** This is the const version of block<>(int, int). */
template<typename Derived> template<typename Derived>
template<int BlockRows, int BlockCols> template<int BlockRows, int BlockCols>
inline const Block<Derived, BlockRows, BlockCols> MatrixBase<Derived> inline const typename BlockReturnType<Derived, BlockRows, BlockCols>::Type
::block(int startRow, int startCol) const MatrixBase<Derived>::block(int startRow, int startCol) const
{ {
return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol); return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
} }
@ -729,18 +728,18 @@ inline const Block<Derived, BlockRows, BlockCols> MatrixBase<Derived>
* *
* \sa row(), class Block */ * \sa row(), class Block */
template<typename Derived> template<typename Derived>
inline Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> inline typename MatrixBase<Derived>::ColXpr
MatrixBase<Derived>::col(int i) MatrixBase<Derived>::col(int i)
{ {
return Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>(derived(), i); return ColXpr(derived(), i);
} }
/** This is the const version of col(). */ /** This is the const version of col(). */
template<typename Derived> template<typename Derived>
inline const Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> inline const typename MatrixBase<Derived>::ColXpr
MatrixBase<Derived>::col(int i) const MatrixBase<Derived>::col(int i) const
{ {
return Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>(derived(), i); return ColXpr(derived(), i);
} }
/** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0. /** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0.
@ -752,18 +751,18 @@ MatrixBase<Derived>::col(int i) const
* *
* \sa col(), class Block */ * \sa col(), class Block */
template<typename Derived> template<typename Derived>
inline Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> inline typename MatrixBase<Derived>::RowXpr
MatrixBase<Derived>::row(int i) MatrixBase<Derived>::row(int i)
{ {
return Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>(derived(), i); return RowXpr(derived(), i);
} }
/** This is the const version of row(). */ /** This is the const version of row(). */
template<typename Derived> template<typename Derived>
inline const Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> inline const typename MatrixBase<Derived>::RowXpr
MatrixBase<Derived>::row(int i) const MatrixBase<Derived>::row(int i) const
{ {
return Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>(derived(), i); return RowXpr(derived(), i);
} }
#endif // EIGEN_BLOCK_H #endif // EIGEN_BLOCK_H

View File

@ -35,6 +35,16 @@
*/ */
template<typename Scalar, bool PacketAccess = (int(ei_packet_traits<Scalar>::size)>1?true:false) > struct ei_scalar_add_op; template<typename Scalar, bool PacketAccess = (int(ei_packet_traits<Scalar>::size)>1?true:false) > struct ei_scalar_add_op;
/** \internal
* convenient macro to defined the return type of a cwise binary operation */
#define EIGEN_CWISE_BINOP_RETURN_TYPE(OP) \
CwiseBinaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType, OtherDerived>
/** \internal
* convenient macro to defined the return type of a cwise unary operation */
#define EIGEN_CWISE_UNOP_RETURN_TYPE(OP) \
CwiseUnaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType>
/** \class Cwise /** \class Cwise
* *
* \brief Pseudo expression providing additional coefficient-wise operations * \brief Pseudo expression providing additional coefficient-wise operations
@ -56,56 +66,40 @@ template<typename ExpressionType> class Cwise
typedef typename ei_traits<ExpressionType>::Scalar Scalar; typedef typename ei_traits<ExpressionType>::Scalar Scalar;
typedef typename ei_meta_if<ei_must_nest_by_value<ExpressionType>::ret, typedef typename ei_meta_if<ei_must_nest_by_value<ExpressionType>::ret,
ExpressionType, const ExpressionType&>::ret ExpressionTypeNested; ExpressionType, const ExpressionType&>::ret ExpressionTypeNested;
// typedef NestByValue<typename ExpressionType::ConstantReturnType> ConstantReturnType;
typedef CwiseUnaryOp<ei_scalar_add_op<Scalar>, ExpressionType> ScalarAddReturnType; typedef CwiseUnaryOp<ei_scalar_add_op<Scalar>, ExpressionType> ScalarAddReturnType;
template<template<typename _Scalar> class Functor, typename OtherDerived> struct BinOp
{
typedef CwiseBinaryOp<Functor<typename ei_traits<ExpressionType>::Scalar>,
ExpressionType,
OtherDerived
> ReturnType;
};
template<template<typename _Scalar> class Functor> struct UnOp
{
typedef CwiseUnaryOp<Functor<typename ei_traits<ExpressionType>::Scalar>,
ExpressionType
> ReturnType;
};
inline Cwise(const ExpressionType& matrix) : m_matrix(matrix) {} inline Cwise(const ExpressionType& matrix) : m_matrix(matrix) {}
/** \internal */ /** \internal */
inline const ExpressionType& _expression() const { return m_matrix; } inline const ExpressionType& _expression() const { return m_matrix; }
template<typename OtherDerived> template<typename OtherDerived>
const typename BinOp<ei_scalar_product_op, OtherDerived>::ReturnType const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_product_op)
operator*(const MatrixBase<OtherDerived> &other) const; operator*(const MatrixBase<OtherDerived> &other) const;
template<typename OtherDerived> template<typename OtherDerived>
const typename BinOp<ei_scalar_quotient_op, OtherDerived>::ReturnType const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)
operator/(const MatrixBase<OtherDerived> &other) const; operator/(const MatrixBase<OtherDerived> &other) const;
template<typename OtherDerived> template<typename OtherDerived>
const typename BinOp<ei_scalar_min_op, OtherDerived>::ReturnType const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op)
min(const MatrixBase<OtherDerived> &other) const; min(const MatrixBase<OtherDerived> &other) const;
template<typename OtherDerived> template<typename OtherDerived>
const typename BinOp<ei_scalar_max_op, OtherDerived>::ReturnType const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op)
max(const MatrixBase<OtherDerived> &other) const; max(const MatrixBase<OtherDerived> &other) const;
const typename UnOp<ei_scalar_abs_op>::ReturnType abs() const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs_op) abs() const;
const typename UnOp<ei_scalar_abs2_op>::ReturnType abs2() const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs2_op) abs2() const;
const typename UnOp<ei_scalar_square_op>::ReturnType square() const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_square_op) square() const;
const typename UnOp<ei_scalar_cube_op>::ReturnType cube() const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_cube_op) cube() const;
const typename UnOp<ei_scalar_inverse_op>::ReturnType inverse() const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_inverse_op) inverse() const;
const typename UnOp<ei_scalar_sqrt_op>::ReturnType sqrt() const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_sqrt_op) sqrt() const;
const typename UnOp<ei_scalar_exp_op>::ReturnType exp() const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_exp_op) exp() const;
const typename UnOp<ei_scalar_log_op>::ReturnType log() const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_log_op) log() const;
const typename UnOp<ei_scalar_cos_op>::ReturnType cos() const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_cos_op) cos() const;
const typename UnOp<ei_scalar_sin_op>::ReturnType sin() const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_sin_op) sin() const;
const typename UnOp<ei_scalar_pow_op>::ReturnType pow(const Scalar& exponent) const; const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_pow_op) pow(const Scalar& exponent) const;
const ScalarAddReturnType const ScalarAddReturnType
@ -123,22 +117,22 @@ template<typename ExpressionType> class Cwise
ExpressionType& operator-=(const Scalar& scalar); ExpressionType& operator-=(const Scalar& scalar);
template<typename OtherDerived> const typename BinOp<std::less, OtherDerived>::ReturnType template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
operator<(const MatrixBase<OtherDerived>& other) const; operator<(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived> const typename BinOp<std::less_equal, OtherDerived>::ReturnType template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
operator<=(const MatrixBase<OtherDerived>& other) const; operator<=(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived> const typename BinOp<std::greater, OtherDerived>::ReturnType template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
operator>(const MatrixBase<OtherDerived>& other) const; operator>(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived> const typename BinOp<std::greater_equal, OtherDerived>::ReturnType template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
operator>=(const MatrixBase<OtherDerived>& other) const; operator>=(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived> const typename BinOp<std::equal_to, OtherDerived>::ReturnType template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
operator==(const MatrixBase<OtherDerived>& other) const; operator==(const MatrixBase<OtherDerived>& other) const;
template<typename OtherDerived> const typename BinOp<std::not_equal_to, OtherDerived>::ReturnType template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
operator!=(const MatrixBase<OtherDerived>& other) const; operator!=(const MatrixBase<OtherDerived>& other) const;

View File

@ -186,10 +186,10 @@ MatrixBase<Derived>::operator+=(const MatrixBase<OtherDerived>& other)
*/ */
template<typename ExpressionType> template<typename ExpressionType>
template<typename OtherDerived> template<typename OtherDerived>
inline const typename Cwise<ExpressionType>::template BinOp<ei_scalar_product_op, OtherDerived>::ReturnType inline const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_product_op)
Cwise<ExpressionType>::operator*(const MatrixBase<OtherDerived> &other) const Cwise<ExpressionType>::operator*(const MatrixBase<OtherDerived> &other) const
{ {
return typename BinOp<ei_scalar_product_op, OtherDerived>::ReturnType(_expression(), other.derived()); return EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_product_op)(_expression(), other.derived());
} }
/** \returns an expression of the coefficient-wise quotient of *this and \a other /** \returns an expression of the coefficient-wise quotient of *this and \a other
@ -198,10 +198,10 @@ Cwise<ExpressionType>::operator*(const MatrixBase<OtherDerived> &other) const
*/ */
template<typename ExpressionType> template<typename ExpressionType>
template<typename OtherDerived> template<typename OtherDerived>
inline const typename Cwise<ExpressionType>::template BinOp<ei_scalar_quotient_op, OtherDerived>::ReturnType inline const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)
Cwise<ExpressionType>::operator/(const MatrixBase<OtherDerived> &other) const Cwise<ExpressionType>::operator/(const MatrixBase<OtherDerived> &other) const
{ {
return typename BinOp<ei_scalar_quotient_op, OtherDerived>::ReturnType(_expression(), other.derived()); return EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)(_expression(), other.derived());
} }
/** \returns an expression of the coefficient-wise min of *this and \a other /** \returns an expression of the coefficient-wise min of *this and \a other
@ -210,10 +210,10 @@ Cwise<ExpressionType>::operator/(const MatrixBase<OtherDerived> &other) const
*/ */
template<typename ExpressionType> template<typename ExpressionType>
template<typename OtherDerived> template<typename OtherDerived>
inline const typename Cwise<ExpressionType>::template BinOp<ei_scalar_min_op, OtherDerived>::ReturnType inline const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op)
Cwise<ExpressionType>::min(const MatrixBase<OtherDerived> &other) const Cwise<ExpressionType>::min(const MatrixBase<OtherDerived> &other) const
{ {
return typename BinOp<ei_scalar_min_op, OtherDerived>::ReturnType(_expression(), other.derived()); return EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op)(_expression(), other.derived());
} }
/** \returns an expression of the coefficient-wise max of *this and \a other /** \returns an expression of the coefficient-wise max of *this and \a other
@ -222,10 +222,10 @@ Cwise<ExpressionType>::min(const MatrixBase<OtherDerived> &other) const
*/ */
template<typename ExpressionType> template<typename ExpressionType>
template<typename OtherDerived> template<typename OtherDerived>
inline const typename Cwise<ExpressionType>::template BinOp<ei_scalar_max_op, OtherDerived>::ReturnType inline const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op)
Cwise<ExpressionType>::max(const MatrixBase<OtherDerived> &other) const Cwise<ExpressionType>::max(const MatrixBase<OtherDerived> &other) const
{ {
return typename BinOp<ei_scalar_max_op, OtherDerived>::ReturnType(_expression(), other.derived()); return EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op)(_expression(), other.derived());
} }
/** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other /** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other

View File

@ -137,7 +137,7 @@ MatrixBase<Derived>::operator-() const
/** \returns an expression of the coefficient-wise absolute value of \c *this /** \returns an expression of the coefficient-wise absolute value of \c *this
*/ */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_abs_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs_op)
Cwise<ExpressionType>::abs() const Cwise<ExpressionType>::abs() const
{ {
return _expression(); return _expression();
@ -146,7 +146,7 @@ Cwise<ExpressionType>::abs() const
/** \returns an expression of the coefficient-wise squared absolute value of \c *this /** \returns an expression of the coefficient-wise squared absolute value of \c *this
*/ */
template<typename ExpressionType> template<typename ExpressionType>
inline const typename Cwise<ExpressionType>::template UnOp<ei_scalar_abs2_op>::ReturnType inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs2_op)
Cwise<ExpressionType>::abs2() const Cwise<ExpressionType>::abs2() const
{ {
return _expression(); return _expression();

View File

@ -175,34 +175,33 @@ template<typename Derived> class MatrixBase
* i.e., the number of rows for a columns major matrix, and the number of cols otherwise */ * i.e., the number of rows for a columns major matrix, and the number of cols otherwise */
int innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); } int innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); }
/** Represents a constant matrix */ /** \internal the type to which the expression gets evaluated (needed by MSVC) */
typedef typename ei_eval<Derived>::type EvalType;
/** \internal Represents a constant matrix */
typedef CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived> ConstantReturnType; typedef CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived> ConstantReturnType;
/** Represents a vector block of a matrix */ /** \internal Represents a scalar multiple of a matrix */
template<int Size> struct SubVectorReturnType
{
typedef Block<Derived, (ei_traits<Derived>::RowsAtCompileTime == 1 ? 1 : Size),
(ei_traits<Derived>::ColsAtCompileTime == 1 ? 1 : Size)> Type;
};
/** Represents a scalar multiple of a matrix */
typedef CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> ScalarMultipleReturnType; typedef CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> ScalarMultipleReturnType;
/** Represents a quotient of a matrix by a scalar*/ /** \internal Represents a quotient of a matrix by a scalar*/
typedef CwiseUnaryOp<ei_scalar_quotient1_op<Scalar>, Derived> ScalarQuotient1ReturnType; typedef CwiseUnaryOp<ei_scalar_quotient1_op<Scalar>, Derived> ScalarQuotient1ReturnType;
/** \internal the return type of MatrixBase::conjugate() */
/** the return type of MatrixBase::conjugate() */
typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex, typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex,
CwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Derived>, CwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Derived>,
Derived& Derived&
>::ret ConjugateReturnType; >::ret ConjugateReturnType;
/** the return type of MatrixBase::real() */ /** \internal the return type of MatrixBase::real() */
typedef CwiseUnaryOp<ei_scalar_real_op<Scalar>, Derived> RealReturnType; typedef CwiseUnaryOp<ei_scalar_real_op<Scalar>, Derived> RealReturnType;
/** the return type of MatrixBase::adjoint() */ /** \internal the return type of MatrixBase::adjoint() */
typedef Transpose<NestByValue<typename ei_unref<ConjugateReturnType>::type> > typedef Transpose<NestByValue<typename ei_unref<ConjugateReturnType>::type> >
AdjointReturnType; AdjointReturnType;
/** the return type of MatrixBase::eigenvalues() */ /** \internal the return type of MatrixBase::eigenvalues() */
typedef Matrix<typename NumTraits<typename ei_traits<Derived>::Scalar>::Real, ei_traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType; typedef Matrix<typename NumTraits<typename ei_traits<Derived>::Scalar>::Real, ei_traits<Derived>::ColsAtCompileTime, 1> EigenvaluesReturnType;
/** the return type of identity */ /** \internal expression tyepe of a column */
typedef Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> ColXpr;
/** \internal expression tyepe of a column */
typedef Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> RowXpr;
/** \internal the return type of identity */
typedef CwiseNullaryOp<ei_scalar_identity_op<Scalar>,Derived> IdentityReturnType; typedef CwiseNullaryOp<ei_scalar_identity_op<Scalar>,Derived> IdentityReturnType;
/** the return type of unit vectors */ /** \internal the return type of unit vectors */
typedef Block<CwiseNullaryOp<ei_scalar_identity_op<Scalar>, SquareMatrixType>, typedef Block<CwiseNullaryOp<ei_scalar_identity_op<Scalar>, SquareMatrixType>,
ei_traits<Derived>::RowsAtCompileTime, ei_traits<Derived>::RowsAtCompileTime,
ei_traits<Derived>::ColsAtCompileTime> BasisReturnType; ei_traits<Derived>::ColsAtCompileTime> BasisReturnType;
@ -330,48 +329,46 @@ template<typename Derived> class MatrixBase
const AdjointReturnType adjoint() const; const AdjointReturnType adjoint() const;
Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> row(int i); RowXpr row(int i);
const Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> row(int i) const; const RowXpr row(int i) const;
Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> col(int i); ColXpr col(int i);
const Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> col(int i) const; const ColXpr col(int i) const;
Minor<Derived> minor(int row, int col); Minor<Derived> minor(int row, int col);
const Minor<Derived> minor(int row, int col) const; const Minor<Derived> minor(int row, int col) const;
Block<Derived> block(int startRow, int startCol, int blockRows, int blockCols); typename BlockReturnType<Derived>::Type block(int startRow, int startCol, int blockRows, int blockCols);
const Block<Derived> const typename BlockReturnType<Derived>::Type
block(int startRow, int startCol, int blockRows, int blockCols) const; block(int startRow, int startCol, int blockRows, int blockCols) const;
Block<Derived> block(int start, int size); typename BlockReturnType<Derived>::SubVectorType block(int start, int size);
const Block<Derived> block(int start, int size) const; const typename BlockReturnType<Derived>::SubVectorType block(int start, int size) const;
typename SubVectorReturnType<Dynamic>::Type start(int size); typename BlockReturnType<Derived,Dynamic>::SubVectorType start(int size);
const typename SubVectorReturnType<Dynamic>::Type start(int size) const; const typename BlockReturnType<Derived,Dynamic>::SubVectorType start(int size) const;
typename SubVectorReturnType<Dynamic>::Type end(int size); typename BlockReturnType<Derived,Dynamic>::SubVectorType end(int size);
const typename SubVectorReturnType<Dynamic>::Type end(int size) const; const typename BlockReturnType<Derived,Dynamic>::SubVectorType end(int size) const;
Block<Derived> corner(CornerType type, int cRows, int cCols); typename BlockReturnType<Derived>::Type corner(CornerType type, int cRows, int cCols);
const Block<Derived> corner(CornerType type, int cRows, int cCols) const; const typename BlockReturnType<Derived>::Type corner(CornerType type, int cRows, int cCols) const;
template<int BlockRows, int BlockCols> template<int BlockRows, int BlockCols>
Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol); typename BlockReturnType<Derived, BlockRows, BlockCols>::Type block(int startRow, int startCol);
template<int BlockRows, int BlockCols> template<int BlockRows, int BlockCols>
const Block<Derived, BlockRows, BlockCols> block(int startRow, int startCol) const; const typename BlockReturnType<Derived, BlockRows, BlockCols>::Type block(int startRow, int startCol) const;
template<int CRows, int CCols> Block<Derived, CRows, CCols> corner(CornerType type); template<int CRows, int CCols>
template<int CRows, int CCols> const Block<Derived, CRows, CCols> corner(CornerType type) const; typename BlockReturnType<Derived, CRows, CCols>::Type corner(CornerType type);
template<int CRows, int CCols>
const typename BlockReturnType<Derived, CRows, CCols>::Type corner(CornerType type) const;
template<int Size> template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType start(void);
typename SubVectorReturnType<Size>::Type start(void); template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType start() const;
template<int Size>
const typename SubVectorReturnType<Size>::Type start() const;
template<int Size> template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType end();
typename SubVectorReturnType<Size>::Type end(); template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType end() const;
template<int Size>
const typename SubVectorReturnType<Size>::Type end() const;
DiagonalCoeffs<Derived> diagonal(); DiagonalCoeffs<Derived> diagonal();
const DiagonalCoeffs<Derived> diagonal() const; const DiagonalCoeffs<Derived> diagonal() const;
@ -529,18 +526,18 @@ template<typename Derived> class MatrixBase
/////////// LU module /////////// /////////// LU module ///////////
const typename ei_eval<Derived>::type inverse() const; const EvalType inverse() const;
void computeInverse(typename ei_eval<Derived>::type *result) const; void computeInverse(EvalType *result) const;
Scalar determinant() const; Scalar determinant() const;
/////////// Cholesky module /////////// /////////// Cholesky module ///////////
const Cholesky<typename ei_eval<Derived>::type> cholesky() const; const Cholesky<EvalType> cholesky() const;
const CholeskyWithoutSquareRoot<typename ei_eval<Derived>::type> choleskyNoSqrt() const; const CholeskyWithoutSquareRoot<EvalType> choleskyNoSqrt() const;
/////////// QR module /////////// /////////// QR module ///////////
const QR<typename ei_eval<Derived>::type> qr() const; const QR<EvalType> qr() const;
EigenvaluesReturnType eigenvalues() const; EigenvaluesReturnType eigenvalues() const;
RealScalar matrixNorm() const; RealScalar matrixNorm() const;
@ -548,9 +545,14 @@ template<typename Derived> class MatrixBase
/////////// Geometry module /////////// /////////// Geometry module ///////////
template<typename OtherDerived> template<typename OtherDerived>
typename ei_eval<Derived>::type EvalType cross(const MatrixBase<OtherDerived>& other) const;
cross(const MatrixBase<OtherDerived>& other) const; EvalType someOrthogonal(void) const;
typename ei_eval<Derived>::type someOrthogonal(void) const;
/**
*/
#ifdef EIGEN_MATRIXBASE_PLUGIN
#include EIGEN_MATRIXBASE_PLUGIN
#endif
}; };
#endif // EIGEN_MATRIXBASE_H #endif // EIGEN_MATRIXBASE_H

View File

@ -240,4 +240,13 @@ template<unsigned int Flags> struct ei_are_flags_consistent
}; };
}; };
/** \internal Gives the type of a sub-matrix or sub-vector of a matrix of type \a ExpressionType and size \a Size
* TODO: could be a good idea to define a big ReturnType struct ??
*/
template<typename ExpressionType, int RowsOrSize=Dynamic, int Cols=Dynamic> struct BlockReturnType {
typedef Block<ExpressionType, (ei_traits<ExpressionType>::RowsAtCompileTime == 1 ? 1 : RowsOrSize),
(ei_traits<ExpressionType>::ColsAtCompileTime == 1 ? 1 : RowsOrSize)> SubVectorType;
typedef Block<ExpressionType, RowsOrSize, Cols> Type;
};
#endif // EIGEN_META_H #endif // EIGEN_META_H

View File

@ -30,7 +30,7 @@
* \returns the cross product of \c *this and \a other */ * \returns the cross product of \c *this and \a other */
template<typename Derived> template<typename Derived>
template<typename OtherDerived> template<typename OtherDerived>
inline typename ei_eval<Derived>::type inline typename MatrixBase<Derived>::EvalType
MatrixBase<Derived>::cross(const MatrixBase<OtherDerived>& other) const MatrixBase<Derived>::cross(const MatrixBase<OtherDerived>& other) const
{ {
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,3); EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived,3);
@ -100,7 +100,7 @@ struct ei_perpendicular_selector<Derived,2>
* \sa cross() * \sa cross()
*/ */
template<typename Derived> template<typename Derived>
typename ei_eval<Derived>::type typename MatrixBase<Derived>::EvalType
MatrixBase<Derived>::someOrthogonal() const MatrixBase<Derived>::someOrthogonal() const
{ {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);

View File

@ -356,10 +356,10 @@ Quaternion<Scalar> Quaternion<Scalar>::slerp(Scalar t, const Quaternion& other)
// 2 - Quaternion slerp(Scalar t, const Quaternion& other) const // 2 - Quaternion slerp(Scalar t, const Quaternion& other) const
// which returns the s-lerp between this and other // which returns the s-lerp between this and other
// ?? // ??
if (*this == other) if (m_coeffs == other.m_coeffs)
return *this; return *this;
Scalar d = this->dot(other); Scalar d = m_coeffs.dot(other.m_coeffs);
// theta is the angle between the 2 quaternions // theta is the angle between the 2 quaternions
Scalar theta = std::acos(ei_abs(d)); Scalar theta = std::acos(ei_abs(d));
@ -370,7 +370,7 @@ Quaternion<Scalar> Quaternion<Scalar>::slerp(Scalar t, const Quaternion& other)
if (d<0) if (d<0)
scale1 = -scale1; scale1 = -scale1;
return scale0 * (*this) + scale1 * other; return Quaternion(scale0 * m_coeffs + scale1 * other.m_coeffs);
} }
// set from a rotation matrix // set from a rotation matrix

View File

@ -120,9 +120,18 @@ public:
/** \returns a writable expression of the translation vector of the transformation */ /** \returns a writable expression of the translation vector of the transformation */
inline TranslationPart translation() { return m_matrix.template block<Dim,1>(0,Dim); } inline TranslationPart translation() { return m_matrix.template block<Dim,1>(0,Dim); }
/** \returns an expression of the product between the transform \c *this and a matrix expression \a other
*
* The right hand side \a other might be either:
* \li a vector of size Dim,
* \li an homogeneous vector of size Dim+1,
* \li a transformation matrix of size Dim+1 x Dim+1.
*/
// note: this function is defined here because some compilers cannot find the respective declaration
template<typename OtherDerived> template<typename OtherDerived>
const typename ei_transform_product_impl<OtherDerived,_Dim,_Dim+1>::ResultType const typename ei_transform_product_impl<OtherDerived,_Dim,_Dim+1>::ResultType
operator * (const MatrixBase<OtherDerived> &other) const; operator * (const MatrixBase<OtherDerived> &other) const
{ return ei_transform_product_impl<OtherDerived,Dim,HDim>::run(*this,other.derived()); }
/** Contatenates two transformations */ /** Contatenates two transformations */
const typename ProductReturnType<MatrixType,MatrixType>::Type const typename ProductReturnType<MatrixType,MatrixType>::Type
@ -216,21 +225,6 @@ QMatrix Transform<Scalar,Dim>::toQMatrix(void) const
} }
#endif #endif
/** \returns an expression of the product between the transform \c *this and a matrix expression \a other
*
* The right hand side \a other might be either:
* \li a vector of size Dim,
* \li an homogeneous vector of size Dim+1,
* \li a transformation matrix of size Dim+1 x Dim+1.
*/
template<typename Scalar, int Dim>
template<typename OtherDerived>
const typename ei_transform_product_impl<OtherDerived,Dim,Dim+1>::ResultType
Transform<Scalar,Dim>::operator*(const MatrixBase<OtherDerived> &other) const
{
return ei_transform_product_impl<OtherDerived,Dim,HDim>::run(*this,other.derived());
}
/** Applies on the right the non uniform scale transformation represented /** Applies on the right the non uniform scale transformation represented
* by the vector \a other to \c *this and returns a reference to \c *this. * by the vector \a other to \c *this and returns a reference to \c *this.
* \sa prescale() * \sa prescale()

View File

@ -301,7 +301,7 @@ struct ei_compute_inverse<MatrixType, 4>
* \sa inverse() * \sa inverse()
*/ */
template<typename Derived> template<typename Derived>
inline void MatrixBase<Derived>::computeInverse(typename ei_eval<Derived>::type *result) const inline void MatrixBase<Derived>::computeInverse(typename MatrixBase<Derived>::EvalType *result) const
{ {
typedef typename ei_eval<Derived>::type MatrixType; typedef typename ei_eval<Derived>::type MatrixType;
ei_assert(rows() == cols()); ei_assert(rows() == cols());
@ -324,10 +324,9 @@ inline void MatrixBase<Derived>::computeInverse(typename ei_eval<Derived>::type
* \sa computeInverse() * \sa computeInverse()
*/ */
template<typename Derived> template<typename Derived>
inline const typename ei_eval<Derived>::type MatrixBase<Derived>::inverse() const inline const typename MatrixBase<Derived>::EvalType MatrixBase<Derived>::inverse() const
{ {
typedef typename ei_eval<Derived>::type MatrixType; EvalType result(rows(), cols());
MatrixType result(rows(), cols());
computeInverse(&result); computeInverse(&result);
return result; return result;
} }

View File

@ -168,7 +168,7 @@ MatrixType QR<MatrixType>::matrixQ(void) const
* \sa class QR * \sa class QR
*/ */
template<typename Derived> template<typename Derived>
const QR<typename ei_eval<Derived>::type> const QR<typename MatrixBase<Derived>::EvalType>
MatrixBase<Derived>::qr() const MatrixBase<Derived>::qr() const
{ {
return QR<typename ei_eval<Derived>::type>(derived()); return QR<typename ei_eval<Derived>::type>(derived());

View File

@ -41,6 +41,7 @@ template<typename _MatrixType> class SelfAdjointEigenSolver
{ {
public: public:
enum {Size = _MatrixType::RowsAtCompileTime };
typedef _MatrixType MatrixType; typedef _MatrixType MatrixType;
typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Scalar Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar; typedef typename NumTraits<Scalar>::Real RealScalar;
@ -49,6 +50,18 @@ template<typename _MatrixType> class SelfAdjointEigenSolver
typedef Matrix<RealScalar, Dynamic, 1> RealVectorTypeX; typedef Matrix<RealScalar, Dynamic, 1> RealVectorTypeX;
typedef Tridiagonalization<MatrixType> TridiagonalizationType; typedef Tridiagonalization<MatrixType> TridiagonalizationType;
SelfAdjointEigenSolver()
: m_eivec(Size, Size),
m_eivalues(Size)
{
ei_assert(Size!=Dynamic);
}
SelfAdjointEigenSolver(int size)
: m_eivec(size, size),
m_eivalues(size)
{}
/** Constructors computing the eigenvalues of the selfadjoint matrix \a matrix, /** Constructors computing the eigenvalues of the selfadjoint matrix \a matrix,
* as well as the eigenvectors if \a computeEigenvectors is true. * as well as the eigenvectors if \a computeEigenvectors is true.
* *