aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-03-18 20:11:38 -0400
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-03-18 20:11:38 -0400
commit9dba86df0b5c1d28a18666003a10f53e59154904 (patch)
tree761906f4de819abf661ce4ff3e2bb7b5041894f8 /Eigen/src
parent74a7c5caeeb6631ddd9d97a0832d80f35e888600 (diff)
parent089bd8951211f8771cfc0a8143812c4fb0aaeb4e (diff)
merge
Diffstat (limited to 'Eigen/src')
-rw-r--r--Eigen/src/Array/Array.h3
-rw-r--r--Eigen/src/Array/ArrayWrapper.h2
-rw-r--r--Eigen/src/Array/Replicate.h27
-rw-r--r--Eigen/src/Array/VectorwiseOp.h4
-rw-r--r--Eigen/src/Core/CwiseBinaryOp.h16
-rw-r--r--Eigen/src/Core/DenseBase.h8
-rw-r--r--Eigen/src/Core/MatrixBase.h10
-rw-r--r--Eigen/src/Core/util/ForwardDeclarations.h26
-rw-r--r--Eigen/src/Sparse/SparseMatrixBase.h2
-rw-r--r--Eigen/src/Sparse/SparseProduct.h4
-rw-r--r--Eigen/src/plugins/CommonCwiseUnaryOps.h22
11 files changed, 97 insertions, 27 deletions
diff --git a/Eigen/src/Array/Array.h b/Eigen/src/Array/Array.h
index 91a091152..8a53b8c3e 100644
--- a/Eigen/src/Array/Array.h
+++ b/Eigen/src/Array/Array.h
@@ -44,6 +44,9 @@ class Array
typedef typename Base::PlainObject PlainObject;
protected:
+ template <typename Derived, typename OtherDerived, bool IsVector>
+ friend struct ei_conservative_resize_like_impl;
+
using Base::m_storage;
public:
enum { NeedsToAlign = (!(Options&DontAlign))
diff --git a/Eigen/src/Array/ArrayWrapper.h b/Eigen/src/Array/ArrayWrapper.h
index 0075dd537..4ac240899 100644
--- a/Eigen/src/Array/ArrayWrapper.h
+++ b/Eigen/src/Array/ArrayWrapper.h
@@ -188,7 +188,7 @@ class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
}
protected:
- const NestedExpressionType& m_expression;
+ const NestedExpressionType m_expression;
};
#endif // EIGEN_ARRAYWRAPPER_H
diff --git a/Eigen/src/Array/Replicate.h b/Eigen/src/Array/Replicate.h
index cd23e0d6f..46a06a61c 100644
--- a/Eigen/src/Array/Replicate.h
+++ b/Eigen/src/Array/Replicate.h
@@ -90,8 +90,29 @@ template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
inline Scalar coeff(int row, int col) const
{
- return m_matrix.coeff(row%m_matrix.rows(), col%m_matrix.cols());
+ // try to avoid using modulo; this is a pure optimization strategy
+ const int actual_row = ei_traits<MatrixType>::RowsAtCompileTime==1 ? 0
+ : RowFactor==1 ? row
+ : row%m_matrix.rows();
+ const int actual_col = ei_traits<MatrixType>::ColsAtCompileTime==1 ? 0
+ : ColFactor==1 ? col
+ : col%m_matrix.cols();
+
+ return m_matrix.coeff(actual_row, actual_col);
}
+ template<int LoadMode>
+ inline PacketScalar packet(int row, int col) const
+ {
+ const int actual_row = ei_traits<MatrixType>::RowsAtCompileTime==1 ? 0
+ : RowFactor==1 ? row
+ : row%m_matrix.rows();
+ const int actual_col = ei_traits<MatrixType>::ColsAtCompileTime==1 ? 0
+ : ColFactor==1 ? col
+ : col%m_matrix.cols();
+
+ return m_matrix.template packet<LoadMode>(actual_row, actual_col);
+ }
+
protected:
const typename MatrixType::Nested m_matrix;
@@ -139,10 +160,10 @@ DenseBase<Derived>::replicate(int rowFactor,int colFactor) const
* \sa VectorwiseOp::replicate(), DenseBase::replicate(), class Replicate
*/
template<typename ExpressionType, int Direction>
-const Replicate<ExpressionType,(Direction==Vertical?Dynamic:1),(Direction==Horizontal?Dynamic:1)>
+const typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
VectorwiseOp<ExpressionType,Direction>::replicate(int factor) const
{
- return Replicate<ExpressionType,Direction==Vertical?Dynamic:1,Direction==Horizontal?Dynamic:1>
+ return typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
(_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1);
}
diff --git a/Eigen/src/Array/VectorwiseOp.h b/Eigen/src/Array/VectorwiseOp.h
index 06d999b14..50cfa7a5e 100644
--- a/Eigen/src/Array/VectorwiseOp.h
+++ b/Eigen/src/Array/VectorwiseOp.h
@@ -384,8 +384,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
const Reverse<ExpressionType, Direction> reverse() const
{ return Reverse<ExpressionType, Direction>( _expression() ); }
- const Replicate<ExpressionType,(Direction==Vertical?Dynamic:1),(Direction==Horizontal?Dynamic:1)>
- replicate(int factor) const;
+ typedef Replicate<ExpressionType,Direction==Vertical?Dynamic:1,Direction==Horizontal?Dynamic:1> ReplicateReturnType;
+ const ReplicateReturnType replicate(int factor) const;
/** \nonstableyet
* \return an expression of the replication of each column (or row) of \c *this
diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h
index 9ed005dce..df13d3aad 100644
--- a/Eigen/src/Core/CwiseBinaryOp.h
+++ b/Eigen/src/Core/CwiseBinaryOp.h
@@ -121,8 +121,20 @@ class CwiseBinaryOp : ei_no_assignment_operator,
ei_assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
}
- EIGEN_STRONG_INLINE int rows() const { return m_lhs.rows(); }
- EIGEN_STRONG_INLINE int cols() const { return m_lhs.cols(); }
+ EIGEN_STRONG_INLINE int rows() const {
+ // return the fixed size type if available to enable compile time optimizations
+ if (ei_traits<typename ei_cleantype<LhsNested>::type>::RowsAtCompileTime==Dynamic)
+ return m_rhs.rows();
+ else
+ return m_lhs.rows();
+ }
+ EIGEN_STRONG_INLINE int cols() const {
+ // return the fixed size type if available to enable compile time optimizations
+ if (ei_traits<typename ei_cleantype<LhsNested>::type>::ColsAtCompileTime==Dynamic)
+ return m_rhs.cols();
+ else
+ return m_lhs.cols();
+ }
/** \returns the left hand side nested expression */
const _LhsNested& lhs() const { return m_lhs; }
diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h
index ecce3ad05..74945fc79 100644
--- a/Eigen/src/Core/DenseBase.h
+++ b/Eigen/src/Core/DenseBase.h
@@ -491,8 +491,12 @@ template<typename Derived> class DenseBase
* Notice that in the case of a plain matrix or vector (not an expression) this function just returns
* a const reference, in order to avoid a useless copy.
*/
- EIGEN_STRONG_INLINE const typename ei_eval<Derived>::type eval() const
- { return typename ei_eval<Derived>::type(derived()); }
+ inline const typename ei_eval<Derived>::type eval() const
+ {
+ // MSVC cannot honor strong inlining when the return type
+ // is a dynamic matrix
+ return typename ei_eval<Derived>::type(derived());
+ }
template<typename OtherDerived>
void swap(DenseBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other);
diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h
index ac79de66d..fd9577ca4 100644
--- a/Eigen/src/Core/MatrixBase.h
+++ b/Eigen/src/Core/MatrixBase.h
@@ -372,6 +372,16 @@ template<typename Derived> class MatrixBase
template<typename OtherScalar>
void applyOnTheRight(int p, int q, const PlanarRotation<OtherScalar>& j);
+///////// MatrixFunctions module /////////
+
+ typedef typename ei_stem_function<Scalar>::type StemFunction;
+ const MatrixExponentialReturnValue<Derived> exp() const;
+ const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const;
+ const MatrixFunctionReturnValue<Derived> cosh() const;
+ const MatrixFunctionReturnValue<Derived> sinh() const;
+ const MatrixFunctionReturnValue<Derived> cos() const;
+ const MatrixFunctionReturnValue<Derived> sin() const;
+
#ifdef EIGEN2_SUPPORT
template<typename ProductDerived, typename Lhs, typename Rhs>
Derived& operator+=(const Flagged<ProductBase<ProductDerived, Lhs,Rhs>, 0,
diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h
index d0ba7328f..eb7e93b91 100644
--- a/Eigen/src/Core/util/ForwardDeclarations.h
+++ b/Eigen/src/Core/util/ForwardDeclarations.h
@@ -46,10 +46,19 @@ template<typename ExpressionType> class NestByValue;
template<typename ExpressionType> class ForceAlignedAccess;
template<typename ExpressionType> class SwapWrapper;
template<typename MatrixType> class Minor;
-// MSVC will not compile when the expression ei_traits<MatrixType>::Flags&DirectAccessBit
-// is put into brackets like (ei_traits<MatrixType>::Flags&DirectAccessBit)!
+
+// MSVC has a big bug: when the expression ei_traits<MatrixType>::Flags&DirectAccessBit ? HasDirectAccess : NoDirectAccess
+// is used as default template parameter value here, it gets mis-evaluated as just ei_traits<MatrixType>::Flags
+// Moreover, adding brackets tends to give compilation errors with MSVC.
+// Solution: defer that to a helper struct.
+template<typename MatrixType>
+struct ei_block_direct_access_status
+{
+ enum { ret = ei_traits<MatrixType>::Flags&DirectAccessBit ? HasDirectAccess : NoDirectAccess };
+};
template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic,
- int _DirectAccessStatus = ei_traits<MatrixType>::Flags&DirectAccessBit ? HasDirectAccess : NoDirectAccess> class Block;
+ int _DirectAccessStatus = ei_block_direct_access_status<MatrixType>::ret> class Block;
+
template<typename MatrixType, int Size=Dynamic> class VectorBlock;
template<typename MatrixType> class Transpose;
template<typename MatrixType> class Conjugate;
@@ -163,6 +172,17 @@ template<typename Scalar,int Dim> class Translation;
template<typename Scalar> class UniformScaling;
template<typename MatrixType,int Direction> class Homogeneous;
+// MatrixFunctions module
+template<typename Derived> struct MatrixExponentialReturnValue;
+template<typename Derived> struct MatrixFunctionReturnValue;
+template <typename Scalar>
+struct ei_stem_function
+{
+ typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar;
+ typedef ComplexScalar type(ComplexScalar, int);
+};
+
+
#ifdef EIGEN2_SUPPORT
template<typename ExpressionType> class Cwise;
#endif
diff --git a/Eigen/src/Sparse/SparseMatrixBase.h b/Eigen/src/Sparse/SparseMatrixBase.h
index cf1a5d7bf..d269ce604 100644
--- a/Eigen/src/Sparse/SparseMatrixBase.h
+++ b/Eigen/src/Sparse/SparseMatrixBase.h
@@ -557,7 +557,7 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived>
* Notice that in the case of a plain matrix or vector (not an expression) this function just returns
* a const reference, in order to avoid a useless copy.
*/
- EIGEN_STRONG_INLINE const typename ei_eval<Derived>::type eval() const
+ inline const typename ei_eval<Derived>::type eval() const
{ return typename ei_eval<Derived>::type(derived()); }
// template<typename OtherDerived>
diff --git a/Eigen/src/Sparse/SparseProduct.h b/Eigen/src/Sparse/SparseProduct.h
index a56bc7601..efc676a69 100644
--- a/Eigen/src/Sparse/SparseProduct.h
+++ b/Eigen/src/Sparse/SparseProduct.h
@@ -562,7 +562,7 @@ class DenseTimeSparseProduct
// sparse * sparse
template<typename Derived>
template<typename OtherDerived>
-EIGEN_STRONG_INLINE const typename SparseProductReturnType<Derived,OtherDerived>::Type
+inline const typename SparseProductReturnType<Derived,OtherDerived>::Type
SparseMatrixBase<Derived>::operator*(const SparseMatrixBase<OtherDerived> &other) const
{
return typename SparseProductReturnType<Derived,OtherDerived>::Type(derived(), other.derived());
@@ -571,7 +571,7 @@ SparseMatrixBase<Derived>::operator*(const SparseMatrixBase<OtherDerived> &other
// sparse * dense
template<typename Derived>
template<typename OtherDerived>
-EIGEN_STRONG_INLINE const SparseTimeDenseProduct<Derived,OtherDerived>
+inline const SparseTimeDenseProduct<Derived,OtherDerived>
SparseMatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const
{
return SparseTimeDenseProduct<Derived,OtherDerived>(derived(), other.derived());
diff --git a/Eigen/src/plugins/CommonCwiseUnaryOps.h b/Eigen/src/plugins/CommonCwiseUnaryOps.h
index 6360ddf7c..ec76ca38f 100644
--- a/Eigen/src/plugins/CommonCwiseUnaryOps.h
+++ b/Eigen/src/plugins/CommonCwiseUnaryOps.h
@@ -55,12 +55,12 @@ typedef CwiseUnaryView<ei_scalar_imag_op<Scalar>, Derived> NonConstImagReturnTyp
/** \returns an expression of the opposite of \c *this
*/
-EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_opposite_op<typename ei_traits<Derived>::Scalar>,Derived>
+inline const CwiseUnaryOp<ei_scalar_opposite_op<typename ei_traits<Derived>::Scalar>,Derived>
operator-() const { return derived(); }
/** \returns an expression of \c *this scaled by the scalar factor \a scalar */
-EIGEN_STRONG_INLINE const ScalarMultipleReturnType
+inline const ScalarMultipleReturnType
operator*(const Scalar& scalar) const
{
return CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived>
@@ -72,7 +72,7 @@ const ScalarMultipleReturnType operator*(const RealScalar& scalar) const;
#endif
/** \returns an expression of \c *this divided by the scalar value \a scalar */
-EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_quotient1_op<typename ei_traits<Derived>::Scalar>, Derived>
+inline const CwiseUnaryOp<ei_scalar_quotient1_op<typename ei_traits<Derived>::Scalar>, Derived>
operator/(const Scalar& scalar) const
{
return CwiseUnaryOp<ei_scalar_quotient1_op<Scalar>, Derived>
@@ -80,7 +80,7 @@ operator/(const Scalar& scalar) const
}
/** Overloaded for efficient real matrix times complex scalar value */
-EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_multiple2_op<Scalar,std::complex<Scalar> >, Derived>
+inline const CwiseUnaryOp<ei_scalar_multiple2_op<Scalar,std::complex<Scalar> >, Derived>
operator*(const std::complex<Scalar>& scalar) const
{
return CwiseUnaryOp<ei_scalar_multiple2_op<Scalar,std::complex<Scalar> >, Derived>
@@ -112,7 +112,7 @@ cast() const
/** \returns an expression of the complex conjugate of \c *this.
*
* \sa adjoint() */
-EIGEN_STRONG_INLINE ConjugateReturnType
+inline ConjugateReturnType
conjugate() const
{
return ConjugateReturnType(derived());
@@ -121,13 +121,13 @@ conjugate() const
/** \returns a read-only expression of the real part of \c *this.
*
* \sa imag() */
-EIGEN_STRONG_INLINE RealReturnType
+inline RealReturnType
real() const { return derived(); }
/** \returns an read-only expression of the imaginary part of \c *this.
*
* \sa real() */
-EIGEN_STRONG_INLINE const ImagReturnType
+inline const ImagReturnType
imag() const { return derived(); }
/** \returns an expression of a custom coefficient-wise unary operator \a func of *this
@@ -142,7 +142,7 @@ imag() const { return derived(); }
* \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, Cwise::abs
*/
template<typename CustomUnaryOp>
-EIGEN_STRONG_INLINE const CwiseUnaryOp<CustomUnaryOp, Derived>
+inline const CwiseUnaryOp<CustomUnaryOp, Derived>
unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const
{
return CwiseUnaryOp<CustomUnaryOp, Derived>(derived(), func);
@@ -160,7 +160,7 @@ unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const
* \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, Cwise::abs
*/
template<typename CustomViewOp>
-EIGEN_STRONG_INLINE const CwiseUnaryView<CustomViewOp, Derived>
+inline const CwiseUnaryView<CustomViewOp, Derived>
unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const
{
return CwiseUnaryView<CustomViewOp, Derived>(derived(), func);
@@ -169,11 +169,11 @@ unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const
/** \returns a non const expression of the real part of \c *this.
*
* \sa imag() */
-EIGEN_STRONG_INLINE NonConstRealReturnType
+inline NonConstRealReturnType
real() { return derived(); }
/** \returns a non const expression of the imaginary part of \c *this.
*
* \sa real() */
-EIGEN_STRONG_INLINE NonConstImagReturnType
+inline NonConstImagReturnType
imag() { return derived(); }