a couple of fixes, now Array passes the linearstructure test

This commit is contained in:
Gael Guennebaud
2009-12-17 19:28:54 +01:00
parent 4b70b47998
commit af4d8c5cec
14 changed files with 146 additions and 44 deletions

View File

@@ -25,6 +25,12 @@
#ifndef EIGEN_ARRAY_H
#define EIGEN_ARRAY_H
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
struct ei_traits<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > : ei_traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
{
typedef DenseStorageArray DenseStorageType;
};
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Array
: public DenseStorageBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, ArrayBase, _Options>
@@ -183,6 +189,11 @@ class Array
other.evalTo(*this);
}
// template<typename OtherDerived>
// Array& lazyAssign(const ArrayBase<OtherDerived>& other);
// template<typename OtherDerived>
// Array& lazyAssign(const MatrixBase<OtherDerived>& other);
/** \sa MatrixBase::operator=(const AnyMatrixBase<OtherDerived>&) */
template<typename OtherDerived>
EIGEN_STRONG_INLINE Array(const AnyMatrixBase<OtherDerived> &other)

View File

@@ -84,7 +84,12 @@ template<typename Derived> 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<typename Derived> 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<typename Derived> class ArrayBase
/** Copies \a other into *this without evaluating other. \returns a reference to *this. */
// template<typename OtherDerived>
// Derived& lazyAssign(const ArrayBase<OtherDerived>& other);
// template<typename OtherDerived>
// Derived& lazyAssign(const MatrixBase<OtherDerived>& other);
#endif // not EIGEN_PARSED_BY_DOXYGEN
Derived& operator+=(const Scalar& scalar)
@@ -206,4 +214,32 @@ template<typename Derived> class ArrayBase
template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&);
};
/** replaces \c *this by \c *this - \a other.
*
* \returns a reference to \c *this
*/
template<typename Derived>
template<typename OtherDerived>
EIGEN_STRONG_INLINE Derived &
ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other)
{
SelfCwiseBinaryOp<ei_scalar_difference_op<Scalar>, Derived> tmp(derived());
tmp = other;
return derived();
}
/** replaces \c *this by \c *this + \a other.
*
* \returns a reference to \c *this
*/
template<typename Derived>
template<typename OtherDerived>
EIGEN_STRONG_INLINE Derived &
ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other)
{
SelfCwiseBinaryOp<ei_scalar_sum_op<Scalar>, Derived> tmp(derived());
tmp = other.derived();
return derived();
}
#endif // EIGEN_ARRAYBASE_H

View File

@@ -28,7 +28,9 @@
template<typename ExpressionType>
struct ei_traits<ArrayWrapper<ExpressionType> >
: public ei_traits<ExpressionType>
{};
{
typedef DenseStorageArray DenseStorageType;
};
template<typename ExpressionType>
class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
@@ -98,13 +100,16 @@ class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
template<typename ExpressionType>
struct ei_traits<MatrixWrapper<ExpressionType> >
: public ei_traits<ExpressionType>
{};
{
typedef DenseStorageMatrix DenseStorageType;
};
template<typename ExpressionType>
class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
{
public:
EIGEN_GENERIC_PUBLIC_INTERFACE(MatrixWrapper)
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper);
inline MatrixWrapper(const ExpressionType& matrix) : m_expression(matrix) {}