11 #ifndef EIGEN_DENSESTORAGEBASE_H    12 #define EIGEN_DENSESTORAGEBASE_H    14 #if defined(EIGEN_INITIALIZE_MATRICES_BY_ZERO)    15 # define EIGEN_INITIALIZE_COEFFS    16 # define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=Scalar(0);    17 #elif defined(EIGEN_INITIALIZE_MATRICES_BY_NAN)    18 # define EIGEN_INITIALIZE_COEFFS    19 # define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=std::numeric_limits<Scalar>::quiet_NaN();    21 # undef EIGEN_INITIALIZE_COEFFS    22 # define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED    30   template<
typename Index>
    37   template<
typename Index>
    42     Index max_index = (size_t(1) << (8 * 
sizeof(Index) - 1)) - 1; 
    43     bool error = (rows == 0 || cols == 0) ? 
false    44                : (rows > max_index / cols);
    50 template <
typename Derived, 
typename OtherDerived = Derived, 
bool IsVector = 
bool(Derived::IsVectorAtCompileTime)> 
struct conservative_resize_like_impl;
    52 template<
typename MatrixTypeA, 
typename MatrixTypeB, 
bool SwapPo
inters> 
struct matrix_swap_impl;
    64 #ifdef EIGEN_PARSED_BY_DOXYGEN    69 template<
typename Derived> 
struct dense_xpr_base_dispatcher_for_doxygen;
    71 template<
typename _Scalar, 
int _Rows, 
int _Cols, 
int _Options, 
int _MaxRows, 
int _MaxCols>
    72 struct dense_xpr_base_dispatcher_for_doxygen<
Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
    73     : 
public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {};
    75 template<
typename _Scalar, 
int _Rows, 
int _Cols, 
int _Options, 
int _MaxRows, 
int _MaxCols>
    76 struct dense_xpr_base_dispatcher_for_doxygen<
Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
    77     : 
public ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {};
    81 template<
typename Derived>
    82 class PlainObjectBase : 
public internal::dense_xpr_base_dispatcher_for_doxygen<Derived>
    99     using Base::RowsAtCompileTime;
   100     using Base::ColsAtCompileTime;
   101     using Base::SizeAtCompileTime;
   102     using Base::MaxRowsAtCompileTime;
   103     using Base::MaxColsAtCompileTime;
   104     using Base::MaxSizeAtCompileTime;
   105     using Base::IsVectorAtCompileTime;
   108     template<
typename PlainObjectType, 
int MapOptions, 
typename Str
ideType> 
friend class Eigen::Map;
   129     Base& base() { 
return *
static_cast<Base*
>(
this); }
   138         return m_storage.data()[colId + rowId * m_storage.cols()];
   140         return m_storage.data()[rowId + colId * m_storage.rows()];
   145       return m_storage.data()[index];
   151         return m_storage.data()[colId + rowId * m_storage.cols()];
   153         return m_storage.data()[rowId + colId * m_storage.rows()];
   158       return m_storage.data()[index];
   164         return m_storage.data()[colId + rowId * m_storage.cols()];
   166         return m_storage.data()[rowId + colId * m_storage.rows()];
   171       return m_storage.data()[index];
   175     template<
int LoadMode>
   178       return internal::ploadt<PacketScalar, LoadMode>
   180                                    ? colId + rowId * m_storage.cols()
   181                                    : rowId + colId * m_storage.rows()));
   185     template<
int LoadMode>
   188       return internal::ploadt<PacketScalar, LoadMode>(m_storage.data() + index);
   192     template<
int StoreMode>
   195       internal::pstoret<Scalar, PacketScalar, StoreMode>
   197                                    ? colId + rowId * m_storage.cols()
   198                                    : rowId + colId * m_storage.rows()), val);
   202     template<
int StoreMode>
   205       internal::pstoret<Scalar, PacketScalar, StoreMode>(m_storage.data() + index, val);
   210     { 
return m_storage.data(); }
   214     { 
return m_storage.data(); }
   238                    && nbRows>=0 && nbCols>=0 && 
"Invalid sizes when resizing a matrix or array.");
   240       #ifdef EIGEN_INITIALIZE_COEFFS   241         Index size = nbRows*nbCols;
   242         bool size_changed = size != this->size();
   243         m_storage.resize(size, nbRows, nbCols);
   247         m_storage.resize(nbRows*nbCols, nbRows, nbCols);
   265       eigen_assert(((SizeAtCompileTime == 
Dynamic && (MaxSizeAtCompileTime==
Dynamic || size<=MaxSizeAtCompileTime)) || SizeAtCompileTime == size) && size>=0);
   266       #ifdef EIGEN_INITIALIZE_COEFFS   267         bool size_changed = size != this->size();
   269       if(RowsAtCompileTime == 1)
   270         m_storage.resize(size, 1, size);
   272         m_storage.resize(size, size, 1);
   273       #ifdef EIGEN_INITIALIZE_COEFFS   288       resize(rows(), nbCols);
   301       resize(nbRows, cols());
   311     template<
typename OtherDerived>
   314       const OtherDerived& other = _other.
derived();
   316       const Index othersize = other.rows()*other.cols();
   317       if(RowsAtCompileTime == 1)
   320         resize(1, othersize);
   322       else if(ColsAtCompileTime == 1)
   325         resize(othersize, 1);
   327       else resize(other.rows(), other.cols());
   354       conservativeResize(nbRows, cols());
   367       conservativeResize(rows(), nbCols);
   392     template<
typename OtherDerived>
   407     template<
typename OtherDerived>
   410       _resize_to_match(other);
   411       return Base::lazyAssign(other.derived());
   414     template<
typename OtherDerived>
   418       return Base::operator=(func);
   427 #ifndef EIGEN_PARSED_BY_DOXYGEN   431       : m_storage(
internal::constructor_without_unaligned_array_assert())
   438       : m_storage(a_size, nbRows, nbCols)
   446     template<
typename OtherDerived>
   449       _resize_to_match(other);
   450       Base::operator=(other.
derived());
   451       return this->derived();
   455     template<
typename OtherDerived>
   457       : m_storage(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols())
   459       _check_template_params();
   461       Base::operator=(other.
derived());
   479     { 
return MapType(data, size); }
   483     { 
return MapType(data, rows, cols); }
   498     template<
int Outer, 
int Inner>
   500     { 
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, stride); }
   501     template<
int Outer, 
int Inner>
   503     { 
return typename StridedMapType<Stride<Outer, Inner> >::type(data, stride); }
   504     template<
int Outer, 
int Inner>
   506     { 
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, size, stride); }
   507     template<
int Outer, 
int Inner>
   509     { 
return typename StridedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
   510     template<
int Outer, 
int Inner>
   512     { 
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
   513     template<
int Outer, 
int Inner>
   515     { 
return typename StridedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
   517     template<
int Outer, 
int Inner>
   519     { 
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
   520     template<
int Outer, 
int Inner>
   522     { 
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
   523     template<
int Outer, 
int Inner>
   525     { 
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
   526     template<
int Outer, 
int Inner>
   528     { 
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
   529     template<
int Outer, 
int Inner>
   531     { 
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
   532     template<
int Outer, 
int Inner>
   534     { 
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
   537     using Base::setConstant;
   538     Derived& setConstant(
Index size, 
const Scalar& value);
   546     Derived& setOnes(
Index size);
   549     using Base::setRandom;
   550     Derived& setRandom(
Index size);
   553     #ifdef EIGEN_PLAINOBJECTBASE_PLUGIN   554     #include EIGEN_PLAINOBJECTBASE_PLUGIN   565     template<
typename OtherDerived>
   568       #ifdef EIGEN_NO_AUTOMATIC_RESIZING   569       eigen_assert((this->size()==0 || (IsVectorAtCompileTime ? (this->size() == other.
size())
   570                  : (rows() == other.
rows() && cols() == other.
cols())))
   571         && 
"Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined");
   592     template<
typename OtherDerived>
   596       return this->derived();
   599     template<
typename OtherDerived>
   602     template<
typename OtherDerived>
   610     template<
typename OtherDerived>
   621     template<
typename T0, 
typename T1>
   626                           FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
   627       resize(nbRows,nbCols);
   629     template<
typename T0, 
typename T1>
   633       m_storage.data()[0] = val0;
   634       m_storage.data()[1] = val1;
   637     template<
typename MatrixTypeA, 
typename MatrixTypeB, 
bool SwapPo
inters>
   643     template<
typename OtherDerived>
   651 #ifndef EIGEN_PARSED_BY_DOXYGEN   655                         && 
EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, (Options&RowMajor)==0)
   656                         && ((RowsAtCompileTime == 
Dynamic) || (RowsAtCompileTime >= 0))
   657                         && ((ColsAtCompileTime == 
Dynamic) || (ColsAtCompileTime >= 0))
   658                         && ((MaxRowsAtCompileTime == 
Dynamic) || (MaxRowsAtCompileTime >= 0))
   659                         && ((MaxColsAtCompileTime == 
Dynamic) || (MaxColsAtCompileTime >= 0))
   660                         && (MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime==
Dynamic)
   661                         && (MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime==
Dynamic)
   662                         && (Options & (
DontAlign|RowMajor)) == Options),
   663         INVALID_MATRIX_TEMPLATE_PARAMETERS)
   668     enum { ThisConstantIsPrivateInPlainObjectBase };
   671 template <
typename Derived, 
typename OtherDerived, 
bool IsVector>
   674   typedef typename Derived::Index 
Index;
   677     if (_this.rows() == rows && _this.cols() == cols) 
return;
   680     if ( ( Derived::IsRowMajor && _this.cols() == cols) || 
   681          (!Derived::IsRowMajor && _this.rows() == rows) )  
   684       _this.derived().m_storage.conservativeResize(rows*cols,rows,cols);
   689       typename Derived::PlainObject tmp(rows,cols);
   690       const Index common_rows = (std::min)(rows, _this.rows());
   691       const Index common_cols = (std::min)(cols, _this.cols());
   692       tmp.block(0,0,common_rows,common_cols) = _this.
block(0,0,common_rows,common_cols);
   693       _this.derived().
swap(tmp);
   699     if (_this.rows() == other.rows() && _this.cols() == other.cols()) 
return;
   709     if ( ( Derived::IsRowMajor && _this.cols() == other.cols()) || 
   710          (!Derived::IsRowMajor && _this.rows() == other.rows()) )  
   712       const Index new_rows = other.rows() - _this.rows();
   713       const Index new_cols = other.cols() - _this.cols();
   714       _this.derived().m_storage.conservativeResize(other.size(),other.rows(),other.cols());
   723       typename Derived::PlainObject tmp(other);
   724       const Index common_rows = (std::min)(tmp.rows(), _this.rows());
   725       const Index common_cols = (std::min)(tmp.cols(), _this.cols());
   726       tmp.block(0,0,common_rows,common_cols) = _this.
block(0,0,common_rows,common_cols);
   727       _this.derived().
swap(tmp);
   734 template <
typename Derived, 
typename OtherDerived>
   737   typedef typename Derived::Index 
Index;
   740     const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : size;
   741     const Index new_cols = Derived::RowsAtCompileTime==1 ? size : 1;
   742     _this.derived().m_storage.conservativeResize(size,new_rows,new_cols);
   747     if (_this.rows() == other.rows() && _this.cols() == other.cols()) 
return;
   749     const Index num_new_elements = other.size() - _this.size();
   751     const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : other.rows();
   752     const Index new_cols = Derived::RowsAtCompileTime==1 ? other.cols() : 1;
   753     _this.derived().m_storage.conservativeResize(other.size(),new_rows,new_cols);
   755     if (num_new_elements > 0)
   756       _this.
tail(num_new_elements) = other.
tail(num_new_elements);
   760 template<
typename MatrixTypeA, 
typename MatrixTypeB, 
bool SwapPo
inters>
   763   static inline void run(MatrixTypeA& a, MatrixTypeB& b)
   769 template<
typename MatrixTypeA, 
typename MatrixTypeB>
   772   static inline void run(MatrixTypeA& a, MatrixTypeB& b)
   774     static_cast<typename MatrixTypeA::Base&
>(a).m_storage.swap(static_cast<typename MatrixTypeB::Base&>(b).m_storage);
   782 #endif // EIGEN_DENSESTORAGEBASE_H Eigen::Map< const Derived, Unaligned, StrideType > type
EIGEN_STRONG_INLINE void conservativeResize(Index size)
Block< Derived > block(Index startRow, Index startCol, Index blockRows, Index blockCols)
static MapType Map(Scalar *data)
internal::traits< Derived >::Scalar Scalar
static void run(MatrixTypeA &a, MatrixTypeB &b)
RowsBlockXpr bottomRows(Index n)
EIGEN_STRONG_INLINE Scalar * data()
#define EIGEN_STRONG_INLINE
static StridedConstAlignedMapType< Stride< Outer, Inner > >::type MapAligned(const Scalar *data, const Stride< Outer, Inner > &stride)
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
EIGEN_STRONG_INLINE Derived & operator=(const PlainObjectBase &other)
static StridedAlignedMapType< Stride< Outer, Inner > >::type MapAligned(Scalar *data, Index size, const Stride< Outer, Inner > &stride)
Eigen::Map< Derived, Unaligned, StrideType > type
EIGEN_STRONG_INLINE void conservativeResize(Index nbRows, Index nbCols)
SegmentReturnType tail(Index vecSize)
EIGEN_STRONG_INLINE void _init2(Index nbRows, Index nbCols, typename internal::enable_if< Base::SizeAtCompileTime!=2, T0 >::type *=0)
A matrix or vector expression mapping an existing array of data. 
EIGEN_STRONG_INLINE PlainObjectBase(Index a_size, Index nbRows, Index nbCols)
EIGEN_STRONG_INLINE PacketScalar packet(Index index) const 
static void run(DenseBase< Derived > &_this, Index rows, Index cols)
static ConstMapType Map(const Scalar *data, Index size)
void resize(Index nbRows, NoChange_t)
internal::traits< Derived >::Index Index
Holds strides information for Map. 
EIGEN_STRONG_INLINE PlainObjectBase(const EigenBase< OtherDerived > &other)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
static AlignedMapType MapAligned(Scalar *data)
Eigen::Map< const Derived, Aligned, StrideType > type
const unsigned int RowMajorBit
Base class for all dense matrices, vectors, and arrays. 
static ConstAlignedMapType MapAligned(const Scalar *data, Index size)
const Base & base() const 
static MapType Map(Scalar *data, Index rows, Index cols)
Eigen::Map< Derived, Aligned, StrideType > type
EIGEN_STRONG_INLINE void conservativeResize(NoChange_t, Index nbCols)
EIGEN_STRONG_INLINE void _set_selector(const OtherDerived &other, const internal::false_type &)
internal::dense_xpr_base< Derived >::type Base
EIGEN_STRONG_INLINE Index rows() const 
const unsigned int AlignedBit
EIGEN_STRONG_INLINE void writePacket(Index index, const PacketScalar &val)
static EIGEN_ALWAYS_INLINE void run(Index rows, Index cols)
static ConstMapType Map(const Scalar *data, Index rows, Index cols)
Eigen::Map< Derived, Aligned > AlignedMapType
void throw_std_bad_alloc()
static void run(MatrixTypeA &a, MatrixTypeB &b)
EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const 
EIGEN_STRONG_INLINE const Scalar & coeff(Index index) const 
const Eigen::Map< const Derived, Aligned > ConstAlignedMapType
EIGEN_STRONG_INLINE void _set_selector(const OtherDerived &other, const internal::true_type &)
static StridedConstMapType< Stride< Outer, Inner > >::type Map(const Scalar *data, const Stride< Outer, Inner > &stride)
static AlignedMapType MapAligned(Scalar *data, Index size)
EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
static StridedConstMapType< Stride< Outer, Inner > >::type Map(const Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride)
Dense storage base class for matrices and arrays. 
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
EIGEN_STRONG_INLINE const Scalar & coeffRef(Index index) const 
static AlignedMapType MapAligned(Scalar *data, Index rows, Index cols)
void _swap(DenseBase< OtherDerived > const &other)
static void run(DenseBase< Derived > &_this, Index size)
static StridedAlignedMapType< Stride< Outer, Inner > >::type MapAligned(Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride)
Base class for all 1D and 2D array, and related expressions. 
const unsigned int EvalBeforeAssigningBit
EIGEN_STRONG_INLINE void _resize_to_match(const EigenBase< OtherDerived > &other)
EIGEN_STRONG_INLINE void _init2(const Scalar &val0, const Scalar &val1, typename internal::enable_if< Base::SizeAtCompileTime==2, T0 >::type *=0)
internal::traits< Derived >::StorageKind StorageKind
static void run(DenseBase< Derived > &_this, const DenseBase< OtherDerived > &other)
PlainObjectBase(internal::constructor_without_unaligned_array_assert)
static StridedAlignedMapType< Stride< Outer, Inner > >::type MapAligned(Scalar *data, const Stride< Outer, Inner > &stride)
DenseStorage< Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options > m_storage
static ConstAlignedMapType MapAligned(const Scalar *data, Index rows, Index cols)
static StridedMapType< Stride< Outer, Inner > >::type Map(Scalar *data, const Stride< Outer, Inner > &stride)
EIGEN_STRONG_INLINE Scalar & coeffRef(Index index)
EIGEN_STRONG_INLINE Derived & operator=(const EigenBase< OtherDerived > &other)
static EIGEN_ALWAYS_INLINE void run(Index, Index)
EIGEN_STRONG_INLINE const Scalar * data() const 
EIGEN_STRONG_INLINE void conservativeResizeLike(const DenseBase< OtherDerived > &other)
static EIGEN_STRONG_INLINE void _check_template_params()
static StridedMapType< Stride< Outer, Inner > >::type Map(Scalar *data, Index size, const Stride< Outer, Inner > &stride)
EIGEN_STRONG_INLINE PlainObjectBase()
EIGEN_STRONG_INLINE void conservativeResize(Index nbRows, NoChange_t)
static StridedMapType< Stride< Outer, Inner > >::type Map(Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride)
EIGEN_STRONG_INLINE Derived & _set_noalias(const DenseBase< OtherDerived > &other)
EIGEN_STRONG_INLINE Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing. 
static StridedConstMapType< Stride< Outer, Inner > >::type Map(const Scalar *data, Index size, const Stride< Outer, Inner > &stride)
EIGEN_STRONG_INLINE Derived & lazyAssign(const DenseBase< OtherDerived > &other)
#define EIGEN_ALWAYS_INLINE
const Eigen::Map< const Derived, Unaligned > ConstMapType
General-purpose arrays with easy API for coefficient-wise operations. 
void resize(NoChange_t, Index nbCols)
static ConstMapType Map(const Scalar *data)
EIGEN_STRONG_INLINE const Scalar & coeffRef(Index rowId, Index colId) const 
static StridedConstAlignedMapType< Stride< Outer, Inner > >::type MapAligned(const Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride)
static MapType Map(Scalar *data, Index size)
void swap(const DenseBase< OtherDerived > &other, int=OtherDerived::ThisConstantIsPrivateInPlainObjectBase)
#define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
EIGEN_STRONG_INLINE Derived & operator=(const ReturnByValue< OtherDerived > &func)
#define EIGEN_IMPLIES(a, b)
EIGEN_STRONG_INLINE void resizeLike(const EigenBase< OtherDerived > &_other)
#define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE)
EIGEN_STRONG_INLINE void writePacket(Index rowId, Index colId, const PacketScalar &val)
The matrix class, also used for vectors and row-vectors. 
EIGEN_STRONG_INLINE Index cols() const 
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
NumTraits< Scalar >::Real RealScalar
Eigen::Map< Derived, Unaligned > MapType
ColsBlockXpr rightCols(Index n)
Base class for all dense matrices, vectors, and expressions. 
Block< Derived > bottomRightCorner(Index cRows, Index cCols)
static void run(DenseBase< Derived > &_this, const DenseBase< OtherDerived > &other)
static StridedConstAlignedMapType< Stride< Outer, Inner > >::type MapAligned(const Scalar *data, Index size, const Stride< Outer, Inner > &stride)
static ConstAlignedMapType MapAligned(const Scalar *data)
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const 
internal::packet_traits< Scalar >::type PacketScalar