diff --git a/Eigen/src/Array/Array.h b/Eigen/src/Array/Array.h index 5cb2cbdb2..fc8c500c2 100644 --- a/Eigen/src/Array/Array.h +++ b/Eigen/src/Array/Array.h @@ -25,6 +25,12 @@ #ifndef EIGEN_ARRAY_H #define EIGEN_ARRAY_H +template +struct ei_traits > : ei_traits > +{ + typedef DenseStorageArray DenseStorageType; +}; + template class Array : public DenseStorageBase, ArrayBase, _Options> @@ -183,6 +189,11 @@ class Array other.evalTo(*this); } +// template +// Array& lazyAssign(const ArrayBase& other); +// template +// Array& lazyAssign(const MatrixBase& other); + /** \sa MatrixBase::operator=(const AnyMatrixBase&) */ template EIGEN_STRONG_INLINE Array(const AnyMatrixBase &other) diff --git a/Eigen/src/Array/ArrayBase.h b/Eigen/src/Array/ArrayBase.h index 980ee6489..ccc8b8373 100644 --- a/Eigen/src/Array/ArrayBase.h +++ b/Eigen/src/Array/ArrayBase.h @@ -84,7 +84,12 @@ template class ArrayBase using Base::size; using Base::coeff; using Base::coeffRef; + using Base::lazyAssign; using Base::operator=; + using Base::operator+=; + using Base::operator-=; + using Base::operator*=; + using Base::operator/=; typedef typename Base::RealScalar RealScalar; typedef typename Base::CoeffReturnType CoeffReturnType; @@ -114,6 +119,7 @@ template class ArrayBase # include "../plugins/MatrixCwiseUnaryOps.h" # include "../plugins/ArrayCwiseUnaryOps.h" # include "../plugins/CommonCwiseBinaryOps.h" +# include "../plugins/MatrixCwiseBinaryOps.h" # include "../plugins/ArrayCwiseBinaryOps.h" # ifdef EIGEN_ARRAYBASE_PLUGIN # include EIGEN_ARRAYBASE_PLUGIN @@ -137,6 +143,8 @@ template class ArrayBase /** Copies \a other into *this without evaluating other. \returns a reference to *this. */ // template // Derived& lazyAssign(const ArrayBase& other); +// template +// Derived& lazyAssign(const MatrixBase& other); #endif // not EIGEN_PARSED_BY_DOXYGEN Derived& operator+=(const Scalar& scalar) @@ -206,4 +214,32 @@ template class ArrayBase template explicit ArrayBase(const ArrayBase&); }; +/** replaces \c *this by \c *this - \a other. + * + * \returns a reference to \c *this + */ +template +template +EIGEN_STRONG_INLINE Derived & +ArrayBase::operator-=(const ArrayBase &other) +{ + SelfCwiseBinaryOp, Derived> tmp(derived()); + tmp = other; + return derived(); +} + +/** replaces \c *this by \c *this + \a other. + * + * \returns a reference to \c *this + */ +template +template +EIGEN_STRONG_INLINE Derived & +ArrayBase::operator+=(const ArrayBase& other) +{ + SelfCwiseBinaryOp, Derived> tmp(derived()); + tmp = other.derived(); + return derived(); +} + #endif // EIGEN_ARRAYBASE_H diff --git a/Eigen/src/Array/ArrayWrapper.h b/Eigen/src/Array/ArrayWrapper.h index 588928be9..5850b6cb5 100644 --- a/Eigen/src/Array/ArrayWrapper.h +++ b/Eigen/src/Array/ArrayWrapper.h @@ -28,7 +28,9 @@ template struct ei_traits > : public ei_traits -{}; +{ + typedef DenseStorageArray DenseStorageType; +}; template class ArrayWrapper : public ArrayBase > @@ -98,13 +100,16 @@ class ArrayWrapper : public ArrayBase > template struct ei_traits > : public ei_traits -{}; +{ + typedef DenseStorageMatrix DenseStorageType; +}; template class MatrixWrapper : public MatrixBase > { public: EIGEN_GENERIC_PUBLIC_INTERFACE(MatrixWrapper) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper); inline MatrixWrapper(const ExpressionType& matrix) : m_expression(matrix) {} diff --git a/Eigen/src/Core/AnyMatrixBase.h b/Eigen/src/Core/AnyMatrixBase.h index 6035585e8..0522c1d5e 100644 --- a/Eigen/src/Core/AnyMatrixBase.h +++ b/Eigen/src/Core/AnyMatrixBase.h @@ -37,7 +37,7 @@ */ template struct AnyMatrixBase { - typedef typename ei_plain_matrix_type::type PlainMatrixType; +// typedef typename ei_plain_matrix_type::type PlainMatrixType; /** \returns a reference to the derived object */ Derived& derived() { return *static_cast(this); } diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 598d846ea..461652410 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -58,12 +58,11 @@ * \sa DenseBase::block(int,int,int,int), DenseBase::block(int,int), class VectorBlock */ template -struct ei_traits > +struct ei_traits > : ei_traits { typedef typename ei_traits::Scalar Scalar; typedef typename ei_nested::type MatrixTypeNested; typedef typename ei_unref::type _MatrixTypeNested; - typedef typename ei_traits::StorageType StorageType; enum{ RowsAtCompileTime = BlockRows, ColsAtCompileTime = BlockCols, @@ -77,8 +76,7 @@ struct ei_traits > MaskPacketAccessBit = (InnerMaxSize == Dynamic || (InnerSize >= ei_packet_traits::size)) ? PacketAccessBit : 0, FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, - Flags = (ei_traits::Flags & (HereditaryBits | MaskPacketAccessBit | DirectAccessBit)) | FlagsLinearAccessBit, - CoeffReadCost = ei_traits::CoeffReadCost + Flags = (ei_traits::Flags & (HereditaryBits | MaskPacketAccessBit | DirectAccessBit)) | FlagsLinearAccessBit }; }; diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index dc24d8e4c..954ea9275 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -44,7 +44,7 @@ * \sa MatrixBase::binaryExpr(const MatrixBase &,const CustomBinaryOp &) const, class CwiseUnaryOp, class CwiseNullaryOp */ template -struct ei_traits > +struct ei_traits > : ei_traits { // even though we require Lhs and Rhs to have the same scalar type (see CwiseBinaryOp constructor), // we still want to handle the case when the result type is different. @@ -65,10 +65,6 @@ struct ei_traits > RhsCoeffReadCost = _RhsNested::CoeffReadCost, LhsFlags = _LhsNested::Flags, RhsFlags = _RhsNested::Flags, - RowsAtCompileTime = Lhs::RowsAtCompileTime, - ColsAtCompileTime = Lhs::ColsAtCompileTime, - MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime, - MaxColsAtCompileTime = Lhs::MaxColsAtCompileTime, Flags = (int(LhsFlags) | int(RhsFlags)) & ( HereditaryBits | (int(LhsFlags) & int(RhsFlags) & (LinearAccessBit | AlignedBit)) diff --git a/Eigen/src/Core/DenseStorageBase.h b/Eigen/src/Core/DenseStorageBase.h index b62e34413..b9257156e 100644 --- a/Eigen/src/Core/DenseStorageBase.h +++ b/Eigen/src/Core/DenseStorageBase.h @@ -307,7 +307,7 @@ class DenseStorageBase : public _Base /** \sa MatrixBase::lazyAssign() */ template - EIGEN_STRONG_INLINE Derived& lazyAssign(const MatrixBase& other) + EIGEN_STRONG_INLINE Derived& lazyAssign(const DenseBase& other) { _resize_to_match(other); return Base::lazyAssign(other.derived()); diff --git a/Eigen/src/Core/Fuzzy.h b/Eigen/src/Core/Fuzzy.h index fdc13d00d..dfa042377 100644 --- a/Eigen/src/Core/Fuzzy.h +++ b/Eigen/src/Core/Fuzzy.h @@ -54,6 +54,9 @@ bool DenseBase::isApprox( { const typename ei_nested::type nested(derived()); const typename ei_nested::type otherNested(other.derived()); +// std::cerr << typeid(Derived).name() << " => " << typeid(typename ei_nested::type).name() << "\n"; +// std::cerr << typeid(OtherDerived).name() << " => " << typeid(typename ei_nested::type).name() << "\n"; +// return false; return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * std::min(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum()); } diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 3815fffe7..75c0a73b5 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -112,6 +112,7 @@ struct ei_traits > { typedef _Scalar Scalar; typedef Dense StorageType; + typedef DenseStorageMatrix DenseStorageType; enum { RowsAtCompileTime = _Rows, ColsAtCompileTime = _Cols, diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 4c7113602..53dd6f991 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -124,14 +124,14 @@ template class MatrixBase * reference to a matrix, not a matrix! It is however guaranteed that the return type of eval() is either * PlainMatrixType or const PlainMatrixType&. */ - typedef typename ei_plain_matrix_type::type PlainMatrixType; -// typedef Matrix::Scalar, -// ei_traits::RowsAtCompileTime, -// ei_traits::ColsAtCompileTime, -// AutoAlign | (ei_traits::Flags&RowMajorBit ? RowMajor : ColMajor), -// ei_traits::MaxRowsAtCompileTime, -// ei_traits::MaxColsAtCompileTime -// > PlainMatrixType; +// typedef typename ei_plain_matrix_type::type PlainMatrixType; + typedef Matrix::Scalar, + ei_traits::RowsAtCompileTime, + ei_traits::ColsAtCompileTime, + AutoAlign | (ei_traits::Flags&RowMajorBit ? RowMajor : ColMajor), + ei_traits::MaxRowsAtCompileTime, + ei_traits::MaxColsAtCompileTime + > PlainMatrixType; /** \internal the column-major plain matrix type corresponding to this expression. Note that is not necessarily * exactly the return type of eval(): in the case of plain matrices, the return type of eval() is a const * reference to a matrix, not a matrix! diff --git a/Eigen/src/Core/SelfCwiseBinaryOp.h b/Eigen/src/Core/SelfCwiseBinaryOp.h index ac0ccd963..ad5dc819b 100644 --- a/Eigen/src/Core/SelfCwiseBinaryOp.h +++ b/Eigen/src/Core/SelfCwiseBinaryOp.h @@ -35,11 +35,15 @@ template struct ei_traits > : ei_traits {}; template class SelfCwiseBinaryOp - : public MatrixBase > + //: public MatrixBase > + : public MatrixType::template MakeBase< SelfCwiseBinaryOp >::Type { public: - EIGEN_GENERIC_PUBLIC_INTERFACE(SelfCwiseBinaryOp) + typedef typename MatrixType::template MakeBase< SelfCwiseBinaryOp >::Type Base; + _EIGEN_DENSE_PUBLIC_INTERFACE(SelfCwiseBinaryOp) + +// EIGEN_GENERIC_PUBLIC_INTERFACE(SelfCwiseBinaryOp) typedef typename ei_packet_traits::type Packet; using Base::operator=; @@ -65,7 +69,7 @@ template class SelfCwiseBinaryOp } template - void copyCoeff(int row, int col, const MatrixBase& other) + void copyCoeff(int row, int col, const DenseBase& other) { OtherDerived& _other = other.const_cast_derived(); ei_internal_assert(row >= 0 && row < rows() @@ -75,7 +79,7 @@ template class SelfCwiseBinaryOp } template - void copyCoeff(int index, const MatrixBase& other) + void copyCoeff(int index, const DenseBase& other) { OtherDerived& _other = other.const_cast_derived(); ei_internal_assert(index >= 0 && index < m_matrix.size()); @@ -84,7 +88,7 @@ template class SelfCwiseBinaryOp } template - void copyPacket(int row, int col, const MatrixBase& other) + void copyPacket(int row, int col, const DenseBase& other) { OtherDerived& _other = other.const_cast_derived(); ei_internal_assert(row >= 0 && row < rows() @@ -94,7 +98,7 @@ template class SelfCwiseBinaryOp } template - void copyPacket(int index, const MatrixBase& other) + void copyPacket(int index, const DenseBase& other) { OtherDerived& _other = other.const_cast_derived(); ei_internal_assert(index >= 0 && index < m_matrix.size()); diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h index ee2a3d27d..beb19cdaa 100644 --- a/Eigen/src/Core/util/Constants.h +++ b/Eigen/src/Core/util/Constants.h @@ -271,6 +271,9 @@ const int EiArch_Generic = 0x0; const int EiArch_SSE = 0x1; const int EiArch_AltiVec = 0x2; +enum DenseStorageMatrix {}; +enum DenseStorageArray {}; + #if defined EIGEN_VECTORIZE_SSE const int EiArch = EiArch_SSE; #elif defined EIGEN_VECTORIZE_ALTIVEC diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 6b9dbc781..6d6540acc 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -104,13 +104,35 @@ template struct ei_size_at_compile_time enum { ret = (_Rows==Dynamic || _Cols==Dynamic) ? Dynamic : _Rows * _Cols }; }; -/* ei_eval : the return type of eval(). For matrices, this is just a const reference - * in order to avoid a useless copy +/* ei_plain_matrix_type : the difference from ei_eval is that ei_plain_matrix_type is always a plain matrix type, + * whereas ei_eval is a const reference in the case of a matrix */ -template::StorageType> class ei_eval; +// template class MatrixBase; +// template class ArrayBase; +// template struct ei_is_matrix_or_array +// { +// struct is_matrix {int a[1];}; +// struct is_array {int a[2];}; +// struct is_none {int a[3];}; +// +// template +// static is_matrix testBaseClass(const MatrixBase*); +// template +// static is_array testBaseClass(const ArrayBase*); +// // static is_none testBaseClass(...); +// +// enum {BaseClassType = sizeof(testBaseClass(static_cast(0)))}; +// }; -template struct ei_eval +template::StorageType> class ei_plain_matrix_type; +template struct ei_plain_matrix_type_dense; +template struct ei_plain_matrix_type +{ + typedef typename ei_plain_matrix_type_dense::DenseStorageType>::type type; +}; + +template struct ei_plain_matrix_type_dense { typedef Matrix::Scalar, ei_traits::RowsAtCompileTime, @@ -121,6 +143,36 @@ template struct ei_eval > type; }; +template struct ei_plain_matrix_type_dense +{ + typedef Array::Scalar, + ei_traits::RowsAtCompileTime, + ei_traits::ColsAtCompileTime, + AutoAlign | (ei_traits::Flags&RowMajorBit ? RowMajor : ColMajor), + ei_traits::MaxRowsAtCompileTime, + ei_traits::MaxColsAtCompileTime + > type; +}; + +/* ei_eval : the return type of eval(). For matrices, this is just a const reference + * in order to avoid a useless copy + */ + +template::StorageType> class ei_eval; + +template struct ei_eval +{ + typedef typename ei_plain_matrix_type::type type; +// typedef typename T::PlainMatrixType type; +// typedef T::Matrix::Scalar, +// ei_traits::RowsAtCompileTime, +// ei_traits::ColsAtCompileTime, +// AutoAlign | (ei_traits::Flags&RowMajorBit ? RowMajor : ColMajor), +// ei_traits::MaxRowsAtCompileTime, +// ei_traits::MaxColsAtCompileTime +// > type; +}; + // for matrices, no need to evaluate, just use a const reference to avoid a useless copy template struct ei_eval, Dense> @@ -128,21 +180,14 @@ struct ei_eval, typedef const Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>& type; }; -/* ei_plain_matrix_type : the difference from ei_eval is that ei_plain_matrix_type is always a plain matrix type, - * whereas ei_eval is a const reference in the case of a matrix - */ -template struct ei_plain_matrix_type +template +struct ei_eval, Dense> { -// typedef typename T::PlainMatrixType type; - typedef Matrix::Scalar, - ei_traits::RowsAtCompileTime, - ei_traits::ColsAtCompileTime, - AutoAlign | (ei_traits::Flags&RowMajorBit ? RowMajor : ColMajor), - ei_traits::MaxRowsAtCompileTime, - ei_traits::MaxColsAtCompileTime - > type; + typedef const Array<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>& type; }; + + /* ei_plain_matrix_type_column_major : same as ei_plain_matrix_type but guaranteed to be column-major */ template struct ei_plain_matrix_type_column_major diff --git a/test/linearstructure.cpp b/test/linearstructure.cpp index 3e570f2a0..7df5477b9 100644 --- a/test/linearstructure.cpp +++ b/test/linearstructure.cpp @@ -31,7 +31,6 @@ template void linearStructure(const MatrixType& m) */ typedef typename MatrixType::Scalar Scalar; - typedef Matrix VectorType; int rows = m.rows(); int cols = m.cols(); @@ -95,5 +94,6 @@ void test_linearstructure() CALL_SUBTEST_6( linearStructure(MatrixXf(8, 12)) ); CALL_SUBTEST_7( linearStructure(MatrixXi(8, 12)) ); CALL_SUBTEST_8( linearStructure(MatrixXcd(20, 20)) ); + CALL_SUBTEST_9( linearStructure(ArrayXXf(12, 8)) ); } }