26 #ifndef EIGEN_DENSESTORAGEBASE_H
27 #define EIGEN_DENSESTORAGEBASE_H
29 #ifdef EIGEN_INITIALIZE_MATRICES_BY_ZERO
30 # define EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=Scalar(0);
32 # define EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
39 template<
typename Index>
44 Index max_index = (size_t(1) << (8 *
sizeof(Index) - 1)) - 1;
45 bool error = (rows < 0 || cols < 0) ?
true
46 : (rows == 0 || cols == 0) ?
false
47 : (rows > max_index / cols);
52 template <
typename Derived,
typename OtherDerived = Derived,
bool IsVector =
bool(Derived::IsVectorAtCompileTime)>
struct conservative_resize_like_impl;
54 template<
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
struct matrix_swap_impl;
66 #ifdef EIGEN_PARSED_BY_DOXYGEN
71 template<
typename Derived>
struct dense_xpr_base_dispatcher_for_doxygen;
73 template<
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
int _MaxCols>
74 struct dense_xpr_base_dispatcher_for_doxygen<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
75 :
public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {};
77 template<
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
int _MaxCols>
78 struct dense_xpr_base_dispatcher_for_doxygen<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
79 :
public ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {};
83 template<
typename Derived>
84 class PlainObjectBase :
public internal::dense_xpr_base_dispatcher_for_doxygen<Derived>
86 template<typename Derived>
91 enum {
Options = internal::traits<Derived>::Options };
92 typedef typename internal::dense_xpr_base<Derived>::type
Base;
94 typedef typename internal::traits<Derived>::StorageKind
StorageKind;
95 typedef typename internal::traits<Derived>::Index
Index;
96 typedef typename internal::traits<Derived>::Scalar
Scalar;
97 typedef typename internal::packet_traits<Scalar>::type
PacketScalar;
101 using Base::RowsAtCompileTime;
102 using Base::ColsAtCompileTime;
103 using Base::SizeAtCompileTime;
104 using Base::MaxRowsAtCompileTime;
105 using Base::MaxColsAtCompileTime;
106 using Base::MaxSizeAtCompileTime;
107 using Base::IsVectorAtCompileTime;
110 template<
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
friend class Eigen::Map;
177 template<
int LoadMode>
180 return internal::ploadt<PacketScalar, LoadMode>
187 template<
int LoadMode>
190 return internal::ploadt<PacketScalar, LoadMode>(
m_storage.data() + index);
194 template<
int StoreMode>
197 internal::pstoret<Scalar, PacketScalar, StoreMode>
204 template<
int StoreMode>
207 internal::pstoret<Scalar, PacketScalar, StoreMode>(
m_storage.data() + index, x);
236 #ifdef EIGEN_INITIALIZE_MATRICES_BY_ZERO
239 bool size_changed = size != this->size();
263 #ifdef EIGEN_INITIALIZE_MATRICES_BY_ZERO
264 bool size_changed = size != this->size();
266 if(RowsAtCompileTime == 1)
270 #ifdef EIGEN_INITIALIZE_MATRICES_BY_ZERO
308 template<
typename OtherDerived>
311 const OtherDerived& other = _other.
derived();
313 const Index othersize = other.rows()*other.cols();
314 if(RowsAtCompileTime == 1)
319 else if(ColsAtCompileTime == 1)
324 else resize(other.rows(), other.cols());
338 internal::conservative_resize_like_impl<Derived>::run(*
this, rows, cols);
377 internal::conservative_resize_like_impl<Derived>::run(*
this, size);
389 template<
typename OtherDerived>
392 internal::conservative_resize_like_impl<Derived,OtherDerived>::run(*
this, other);
404 template<
typename OtherDerived>
411 template<
typename OtherDerived>
424 #ifndef EIGEN_PARSED_BY_DOXYGEN
428 :
m_storage(internal::constructor_without_unaligned_array_assert())
443 template<
typename OtherDerived>
448 return this->derived();
452 template<
typename OtherDerived>
456 _check_template_params();
476 {
return MapType(data, size); }
480 {
return MapType(data, rows, cols); }
495 template<
int Outer,
int Inner>
497 {
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, stride); }
498 template<
int Outer,
int Inner>
500 {
return typename StridedMapType<Stride<Outer, Inner> >::type(data, stride); }
501 template<
int Outer,
int Inner>
503 {
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, size, stride); }
504 template<
int Outer,
int Inner>
506 {
return typename StridedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
507 template<
int Outer,
int Inner>
509 {
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
510 template<
int Outer,
int Inner>
512 {
return typename StridedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
514 template<
int Outer,
int Inner>
516 {
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
517 template<
int Outer,
int Inner>
519 {
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
520 template<
int Outer,
int Inner>
522 {
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
523 template<
int Outer,
int Inner>
525 {
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
526 template<
int Outer,
int Inner>
528 {
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
529 template<
int Outer,
int Inner>
531 {
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
550 #ifdef EIGEN_PLAINOBJECTBASE_PLUGIN
551 #include EIGEN_PLAINOBJECTBASE_PLUGIN
562 template<
typename OtherDerived>
565 #ifdef EIGEN_NO_AUTOMATIC_RESIZING
566 eigen_assert((this->size()==0 || (IsVectorAtCompileTime ? (this->size() == other.
size())
568 &&
"Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined");
588 template<
typename OtherDerived>
592 return this->derived();
595 template<
typename OtherDerived>
598 template<
typename OtherDerived>
606 template<
typename OtherDerived>
614 return internal::assign_selector<Derived,OtherDerived,false>::run(this->derived(), other.derived());
617 template<
typename T0,
typename T1>
622 FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
624 && cols >= 0 && (ColsAtCompileTime ==
Dynamic || ColsAtCompileTime == cols));
629 template<
typename T0,
typename T1>
637 template<
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
638 friend struct internal::matrix_swap_impl;
643 template<
typename OtherDerived>
646 enum { SwapPointers = internal::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime==
Dynamic };
647 internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.const_cast_derived());
651 #ifndef EIGEN_PARSED_BY_DOXYGEN
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)
663 INVALID_MATRIX_TEMPLATE_PARAMETERS)
668 enum { ThisConstantIsPrivateInPlainObjectBase };
671 template <
typename Derived,
typename OtherDerived,
bool IsVector>
672 struct internal::conservative_resize_like_impl
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);
697 static void run(DenseBase<Derived>& _this,
const DenseBase<OtherDerived>& other)
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());
716 _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows);
718 _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_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>
735 struct conservative_resize_like_impl<Derived,OtherDerived,true>
737 typedef typename Derived::Index
Index;
738 static void run(DenseBase<Derived>& _this,
Index size)
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);
745 static void run(DenseBase<Derived>& _this,
const DenseBase<OtherDerived>& other)
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>
761 struct matrix_swap_impl
763 static inline void run(MatrixTypeA& a, MatrixTypeB& b)
769 template<
typename MatrixTypeA,
typename MatrixTypeB>
770 struct matrix_swap_impl<MatrixTypeA, MatrixTypeB, true>
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