some cleaning in DenseStorageBase

This commit is contained in:
Gael Guennebaud 2009-12-17 13:56:33 +01:00
parent ebb2878829
commit 5ca90e1b0c
5 changed files with 78 additions and 148 deletions

View File

@ -25,42 +25,13 @@
#ifndef EIGEN_ARRAY_H #ifndef EIGEN_ARRAY_H
#define EIGEN_ARRAY_H #define EIGEN_ARRAY_H
// template<typename MatrixType, typename OtherDerived, bool SwapPointers>
// struct ei_matrix_swap_impl
// {
// static inline void run(MatrixType& matrix, MatrixBase<OtherDerived>& other)
// {
// matrix.base().swap(other);
// }
// };
//
// template<typename MatrixType, typename OtherDerived>
// struct ei_matrix_swap_impl<MatrixType, OtherDerived, true>
// {
// static inline void run(MatrixType& matrix, MatrixBase<OtherDerived>& other)
// {
// matrix.m_storage.swap(other.derived().m_storage);
// }
// };
// template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
// template<typename OtherDerived>
// inline void Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other)
// {
// enum { SwapPointers = ei_is_same_type<Matrix, OtherDerived>::ret && Base::SizeAtCompileTime==Dynamic };
// ei_matrix_swap_impl<Matrix, OtherDerived, bool(SwapPointers)>::run(*this, *const_cast<MatrixBase<OtherDerived>*>(&other));
// }
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Array class Array
: public DenseStorageBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, ArrayBase, _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> : public DenseStorageBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, ArrayBase, _Options>
{ {
public: public:
typedef DenseStorageBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, ArrayBase, _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> Base; typedef DenseStorageBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, ArrayBase, _Options> Base;
_EIGEN_DENSE_PUBLIC_INTERFACE(Array) _EIGEN_DENSE_PUBLIC_INTERFACE(Array)
enum { Options = _Options }; enum { Options = _Options };

View File

@ -136,13 +136,13 @@ inline Derived& DenseBase<Derived>::setRandom()
* *
* \sa MatrixBase::setRandom(), setRandom(int,int), class CwiseNullaryOp, MatrixBase::Random() * \sa MatrixBase::setRandom(), setRandom(int,int), class CwiseNullaryOp, MatrixBase::Random()
*/ */
// template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename Derived, template<typename> class _Base, int _Options>
// EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& EIGEN_STRONG_INLINE Derived&
// Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setRandom(int size) DenseStorageBase<Derived,_Base,_Options>::setRandom(int size)
// { {
// resize(size); resize(size);
// return setRandom(); return setRandom();
// } }
/** Resizes to the given size, and sets all coefficients in this expression to random values. /** Resizes to the given size, and sets all coefficients in this expression to random values.
* *
@ -154,12 +154,12 @@ inline Derived& DenseBase<Derived>::setRandom()
* *
* \sa MatrixBase::setRandom(), setRandom(int), class CwiseNullaryOp, MatrixBase::Random() * \sa MatrixBase::setRandom(), setRandom(int), class CwiseNullaryOp, MatrixBase::Random()
*/ */
// template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename Derived, template<typename> class _Base, int _Options>
// EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& EIGEN_STRONG_INLINE Derived&
// Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setRandom(int rows, int cols) DenseStorageBase<Derived,_Base,_Options>::setRandom(int rows, int cols)
// { {
// resize(rows, cols); resize(rows, cols);
// return setRandom(); return setRandom();
// } }
#endif // EIGEN_RANDOM_H #endif // EIGEN_RANDOM_H

View File

@ -278,13 +278,13 @@ EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setConstant(const Scalar& value
* *
* \sa MatrixBase::setConstant(const Scalar&), setConstant(int,int,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&) * \sa MatrixBase::setConstant(const Scalar&), setConstant(int,int,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
*/ */
// template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename Derived, template<typename> class _Base, int _Options>
// EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& EIGEN_STRONG_INLINE Derived&
// Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setConstant(int size, const Scalar& value) DenseStorageBase<Derived,_Base,_Options>::setConstant(int size, const Scalar& value)
// { {
// resize(size); resize(size);
// return setConstant(value); return setConstant(value);
// } }
/** Resizes to the given size, and sets all coefficients in this expression to the given \a value. /** Resizes to the given size, and sets all coefficients in this expression to the given \a value.
* *
@ -296,13 +296,13 @@ EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setConstant(const Scalar& value
* *
* \sa MatrixBase::setConstant(const Scalar&), setConstant(int,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&) * \sa MatrixBase::setConstant(const Scalar&), setConstant(int,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
*/ */
// template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename Derived, template<typename> class _Base, int _Options>
// EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& EIGEN_STRONG_INLINE Derived&
// Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setConstant(int rows, int cols, const Scalar& value) DenseStorageBase<Derived,_Base,_Options>::setConstant(int rows, int cols, const Scalar& value)
// { {
// resize(rows, cols); resize(rows, cols);
// return setConstant(value); return setConstant(value);
// } }
// zero: // zero:
@ -408,13 +408,13 @@ EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setZero()
* *
* \sa DenseBase::setZero(), setZero(int,int), class CwiseNullaryOp, DenseBase::Zero() * \sa DenseBase::setZero(), setZero(int,int), class CwiseNullaryOp, DenseBase::Zero()
*/ */
// template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename Derived, template<typename> class _Base, int _Options>
// EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& EIGEN_STRONG_INLINE Derived&
// Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setZero(int size) DenseStorageBase<Derived,_Base,_Options>::setZero(int size)
// { {
// resize(size); resize(size);
// return setConstant(Scalar(0)); return setConstant(Scalar(0));
// } }
/** Resizes to the given size, and sets all coefficients in this expression to zero. /** Resizes to the given size, and sets all coefficients in this expression to zero.
* *
@ -426,13 +426,13 @@ EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setZero()
* *
* \sa DenseBase::setZero(), setZero(int), class CwiseNullaryOp, DenseBase::Zero() * \sa DenseBase::setZero(), setZero(int), class CwiseNullaryOp, DenseBase::Zero()
*/ */
// template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename Derived, template<typename> class _Base, int _Options>
// EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& EIGEN_STRONG_INLINE Derived&
// Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setZero(int rows, int cols) DenseStorageBase<Derived,_Base,_Options>::setZero(int rows, int cols)
// { {
// resize(rows, cols); resize(rows, cols);
// return setConstant(Scalar(0)); return setConstant(Scalar(0));
// } }
// ones: // ones:
@ -534,13 +534,13 @@ EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setOnes()
* *
* \sa MatrixBase::setOnes(), setOnes(int,int), class CwiseNullaryOp, MatrixBase::Ones() * \sa MatrixBase::setOnes(), setOnes(int,int), class CwiseNullaryOp, MatrixBase::Ones()
*/ */
// template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename Derived, template<typename> class _Base, int _Options>
// EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& EIGEN_STRONG_INLINE Derived&
// Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setOnes(int size) DenseStorageBase<Derived,_Base,_Options>::setOnes(int size)
// { {
// resize(size); resize(size);
// return setConstant(Scalar(1)); return setConstant(Scalar(1));
// } }
/** Resizes to the given size, and sets all coefficients in this expression to one. /** Resizes to the given size, and sets all coefficients in this expression to one.
* *
@ -552,13 +552,13 @@ EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setOnes()
* *
* \sa MatrixBase::setOnes(), setOnes(int), class CwiseNullaryOp, MatrixBase::Ones() * \sa MatrixBase::setOnes(), setOnes(int), class CwiseNullaryOp, MatrixBase::Ones()
*/ */
// template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename Derived, template<typename> class _Base, int _Options>
// EIGEN_STRONG_INLINE Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& EIGEN_STRONG_INLINE Derived&
// Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::setOnes(int rows, int cols) DenseStorageBase<Derived,_Base,_Options>::setOnes(int rows, int cols)
// { {
// resize(rows, cols); resize(rows, cols);
// return setConstant(Scalar(1)); return setConstant(Scalar(1));
// } }
// Identity: // Identity:

View File

@ -35,7 +35,7 @@
template <typename Derived, typename OtherDerived, bool IsVector = static_cast<bool>(Derived::IsVectorAtCompileTime)> struct ei_conservative_resize_like_impl; template <typename Derived, typename OtherDerived, bool IsVector = static_cast<bool>(Derived::IsVectorAtCompileTime)> struct ei_conservative_resize_like_impl;
template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> struct ei_matrix_swap_impl; template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> struct ei_matrix_swap_impl;
template<typename Derived, template<typename> class _Base, typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename Derived, template<typename> class _Base, int _Options>
class DenseStorageBase : public _Base<Derived> class DenseStorageBase : public _Base<Derived>
{ {
public: public:
@ -402,60 +402,20 @@ class DenseStorageBase : public _Base<Derived>
//@} //@}
using Base::setConstant; using Base::setConstant;
/** Resizes to the given \a size, and sets all coefficients in this expression to the given \a value. Derived& setConstant(int size, const Scalar& value);
* Derived& setConstant(int rows, int cols, const Scalar& value);
* \only_for_vectors
*
* Example: \include Matrix_setConstant_int.cpp
* Output: \verbinclude Matrix_setConstant_int.out
*
* \sa MatrixBase::setConstant(const Scalar&), setConstant(int,int,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
*/
Derived& setConstant(int size, const Scalar& value)
{
resize(size);
return setConstant(value);
}
/** Resizes to the given size, and sets all coefficients in this expression to the given \a value.
*
* \param rows the new number of rows
* \param cols the new number of columns
*
* Example: \include Matrix_setConstant_int_int.cpp
* Output: \verbinclude Matrix_setConstant_int_int.out
*
* \sa MatrixBase::setConstant(const Scalar&), setConstant(int,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
*/
Derived& setConstant(int rows, int cols, const Scalar& value)
{
resize(rows, cols);
return setConstant(value);
}
using Base::setZero; using Base::setZero;
Derived& setZero(int size) Derived& setZero(int size);
{ return setConstant(size, Scalar(0)); } Derived& setZero(int rows, int cols);
Derived& setZero(int rows, int cols)
{ return setConstant(rows, cols, Scalar(0)); }
using Base::setOnes; using Base::setOnes;
Derived& setOnes(int size) Derived& setOnes(int size);
{ return setConstant(size, Scalar(1)); } Derived& setOnes(int rows, int cols);
Derived& setOnes(int rows, int cols)
{ return setConstant(rows, cols, Scalar(1)); }
using Base::setRandom; using Base::setRandom;
Derived& setRandom(int size) Derived& setRandom(int size);
{ Derived& setRandom(int rows, int cols);
resize(size);
return setRandom();
}
Derived& setRandom(int rows, int cols)
{
resize(rows, cols);
return setRandom();
}
#ifdef EIGEN_DENSESTORAGEBASE_PLUGIN #ifdef EIGEN_DENSESTORAGEBASE_PLUGIN
#include EIGEN_DENSESTORAGEBASE_PLUGIN #include EIGEN_DENSESTORAGEBASE_PLUGIN
@ -524,15 +484,15 @@ class DenseStorageBase : public _Base<Derived>
EIGEN_DEBUG_MATRIX_CTOR; EIGEN_DEBUG_MATRIX_CTOR;
#endif #endif
EIGEN_STATIC_ASSERT(((_Rows >= _MaxRows) EIGEN_STATIC_ASSERT(((RowsAtCompileTime >= MaxRowsAtCompileTime)
&& (_Cols >= _MaxCols) && (ColsAtCompileTime >= MaxColsAtCompileTime)
&& (_MaxRows >= 0) && (MaxRowsAtCompileTime >= 0)
&& (_MaxCols >= 0) && (MaxColsAtCompileTime >= 0)
&& (_Rows <= Dynamic) && (RowsAtCompileTime <= Dynamic)
&& (_Cols <= Dynamic) && (ColsAtCompileTime <= Dynamic)
&& (_MaxRows == _Rows || _Rows==Dynamic) && (MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime==Dynamic)
&& (_MaxCols == _Cols || _Cols==Dynamic) && (MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime==Dynamic)
&& ((_MaxRows==Dynamic?1:_MaxRows)*(_MaxCols==Dynamic?1:_MaxCols)<Dynamic) && ((MaxRowsAtCompileTime==Dynamic?1:MaxRowsAtCompileTime)*(MaxColsAtCompileTime==Dynamic?1:MaxColsAtCompileTime)<Dynamic)
&& (_Options & (DontAlign|RowMajor)) == _Options), && (_Options & (DontAlign|RowMajor)) == _Options),
INVALID_MATRIX_TEMPLATE_PARAMETERS) INVALID_MATRIX_TEMPLATE_PARAMETERS)
} }

View File

@ -124,12 +124,11 @@ struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix class Matrix
: public DenseStorageBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, MatrixBase, _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> : public DenseStorageBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, MatrixBase, _Options>
// : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
{ {
public: public:
typedef DenseStorageBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, MatrixBase, _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> Base; typedef DenseStorageBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, MatrixBase, _Options> Base;
_EIGEN_GENERIC_PUBLIC_INTERFACE(Matrix) _EIGEN_GENERIC_PUBLIC_INTERFACE(Matrix)
enum { Options = _Options }; enum { Options = _Options };