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
29 template<
int MaxSizeAtCompileTime>
struct check_rows_cols_for_overflow {
30 template<
typename Index>
32 static EIGEN_ALWAYS_INLINE
void run(Index, Index)
37 template<>
struct check_rows_cols_for_overflow<Dynamic> {
38 template<
typename Index>
40 static EIGEN_ALWAYS_INLINE
void run(Index rows, Index cols)
44 Index max_index = (size_t(1) << (8 *
sizeof(Index) - 1)) - 1;
45 bool error = (rows == 0 || cols == 0) ?
false
46 : (rows > max_index / cols);
48 throw_std_bad_alloc();
52 template <
typename Derived,
53 typename OtherDerived = Derived,
54 bool IsVector = bool(Derived::IsVectorAtCompileTime) && bool(OtherDerived::IsVectorAtCompileTime)>
55 struct conservative_resize_like_impl;
57 template<
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
struct matrix_swap_impl;
69 #ifdef EIGEN_PARSED_BY_DOXYGEN
75 template<
typename Derived>
struct dense_xpr_base_dispatcher_for_doxygen;
77 template<
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
int _MaxCols>
78 struct dense_xpr_base_dispatcher_for_doxygen<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
79 :
public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {};
81 template<
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
int _MaxCols>
82 struct dense_xpr_base_dispatcher_for_doxygen<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
83 :
public ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {};
87 template<
typename Derived>
88 class PlainObjectBase :
public internal::dense_xpr_base_dispatcher_for_doxygen<Derived>
90 template<typename Derived>
95 enum { Options = internal::traits<Derived>::Options };
96 typedef typename internal::dense_xpr_base<Derived>::type Base;
98 typedef typename internal::traits<Derived>::StorageKind StorageKind;
99 typedef typename internal::traits<Derived>::Scalar Scalar;
101 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
103 typedef Derived DenseType;
105 using Base::RowsAtCompileTime;
106 using Base::ColsAtCompileTime;
107 using Base::SizeAtCompileTime;
108 using Base::MaxRowsAtCompileTime;
109 using Base::MaxColsAtCompileTime;
110 using Base::MaxSizeAtCompileTime;
111 using Base::IsVectorAtCompileTime;
114 template<
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
friend class Eigen::Map;
117 friend class Eigen::Map<const Derived, Unaligned>;
119 #if EIGEN_MAX_ALIGN_BYTES>0
122 friend class Eigen::Map<const Derived, AlignedMax>;
132 DenseStorage<Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options> m_storage;
135 enum { NeedsToAlign = (SizeAtCompileTime != Dynamic) && (internal::traits<Derived>::Alignment>0) };
136 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
139 Base& base() {
return *
static_cast<Base*
>(
this); }
141 const Base& base()
const {
return *
static_cast<const Base*
>(
this); }
144 EIGEN_STRONG_INLINE Index rows()
const {
return m_storage.rows(); }
146 EIGEN_STRONG_INLINE Index cols()
const {
return m_storage.cols(); }
149 EIGEN_STRONG_INLINE
const Scalar& coeff(Index rowId, Index colId)
const
152 return m_storage.data()[colId + rowId * m_storage.cols()];
154 return m_storage.data()[rowId + colId * m_storage.rows()];
158 EIGEN_STRONG_INLINE
const Scalar& coeff(Index index)
const
160 return m_storage.data()[index];
164 EIGEN_STRONG_INLINE Scalar& coeffRef(Index rowId, Index colId)
167 return m_storage.data()[colId + rowId * m_storage.cols()];
169 return m_storage.data()[rowId + colId * m_storage.rows()];
173 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
175 return m_storage.data()[index];
179 EIGEN_STRONG_INLINE
const Scalar& coeffRef(Index rowId, Index colId)
const
182 return m_storage.data()[colId + rowId * m_storage.cols()];
184 return m_storage.data()[rowId + colId * m_storage.rows()];
188 EIGEN_STRONG_INLINE
const Scalar& coeffRef(Index index)
const
190 return m_storage.data()[index];
194 template<
int LoadMode>
195 EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId)
const
197 return internal::ploadt<PacketScalar, LoadMode>
199 ? colId + rowId * m_storage.cols()
200 : rowId + colId * m_storage.rows()));
204 template<
int LoadMode>
205 EIGEN_STRONG_INLINE PacketScalar packet(Index index)
const
207 return internal::ploadt<PacketScalar, LoadMode>(m_storage.data() + index);
211 template<
int StoreMode>
212 EIGEN_STRONG_INLINE
void writePacket(Index rowId, Index colId,
const PacketScalar& val)
214 internal::pstoret<Scalar, PacketScalar, StoreMode>
216 ? colId + rowId * m_storage.cols()
217 : rowId + colId * m_storage.rows()), val);
221 template<
int StoreMode>
222 EIGEN_STRONG_INLINE
void writePacket(Index index,
const PacketScalar& val)
224 internal::pstoret<Scalar, PacketScalar, StoreMode>(m_storage.data() + index, val);
228 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar *
data()
const
229 {
return m_storage.data(); }
232 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar *
data()
233 {
return m_storage.data(); }
252 EIGEN_STRONG_INLINE
void resize(Index rows, Index cols)
254 eigen_assert( EIGEN_IMPLIES(RowsAtCompileTime!=Dynamic,rows==RowsAtCompileTime)
255 && EIGEN_IMPLIES(ColsAtCompileTime!=Dynamic,cols==ColsAtCompileTime)
256 && EIGEN_IMPLIES(RowsAtCompileTime==Dynamic && MaxRowsAtCompileTime!=Dynamic,rows<=MaxRowsAtCompileTime)
257 && EIGEN_IMPLIES(ColsAtCompileTime==Dynamic && MaxColsAtCompileTime!=Dynamic,cols<=MaxColsAtCompileTime)
258 && rows>=0 && cols>=0 &&
"Invalid sizes when resizing a matrix or array.");
259 internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(rows, cols);
260 #ifdef EIGEN_INITIALIZE_COEFFS
261 Index size = rows*cols;
262 bool size_changed = size != this->size();
263 m_storage.resize(size, rows, cols);
264 if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
266 internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(rows, cols);
267 m_storage.resize(rows*cols, rows, cols);
286 eigen_assert(((SizeAtCompileTime == Dynamic && (MaxSizeAtCompileTime==Dynamic || size<=MaxSizeAtCompileTime)) || SizeAtCompileTime == size) && size>=0);
287 #ifdef EIGEN_INITIALIZE_COEFFS
288 bool size_changed = size != this->size();
290 if(RowsAtCompileTime == 1)
291 m_storage.resize(size, 1, size);
293 m_storage.resize(size, size, 1);
294 #ifdef EIGEN_INITIALIZE_COEFFS
295 if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
308 inline void resize(NoChange_t, Index cols)
322 inline void resize(Index rows, NoChange_t)
334 template<
typename OtherDerived>
338 const OtherDerived& other = _other.
derived();
339 internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(other.rows(), other.cols());
340 const Index othersize = other.rows()*other.cols();
341 if(RowsAtCompileTime == 1)
343 eigen_assert(other.rows() == 1 || other.cols() == 1);
346 else if(ColsAtCompileTime == 1)
348 eigen_assert(other.rows() == 1 || other.cols() == 1);
351 else resize(other.rows(), other.cols());
366 internal::conservative_resize_like_impl<Derived>::run(*
this, rows, cols);
408 internal::conservative_resize_like_impl<Derived>::run(*
this, size);
420 template<
typename OtherDerived>
424 internal::conservative_resize_like_impl<Derived,OtherDerived>::run(*
this, other);
437 template<
typename OtherDerived>
441 _resize_to_match(other);
442 return Base::lazyAssign(other.derived());
445 template<
typename OtherDerived>
447 EIGEN_STRONG_INLINE Derived&
operator=(
const ReturnByValue<OtherDerived>& func)
449 resize(func.rows(), func.cols());
450 return Base::operator=(func);
454 EIGEN_STRONG_INLINE PlainObjectBase() : m_storage()
460 #ifndef EIGEN_PARSED_BY_DOXYGEN
464 explicit PlainObjectBase(internal::constructor_without_unaligned_array_assert)
465 : m_storage(
internal::constructor_without_unaligned_array_assert())
471 #ifdef EIGEN_HAVE_RVALUE_REFERENCES
473 PlainObjectBase(PlainObjectBase&& other)
474 : m_storage(
std::move(other.m_storage) )
479 PlainObjectBase&
operator=(PlainObjectBase&& other)
482 swap(m_storage, other.m_storage);
490 : Base(), m_storage(other.m_storage) { }
492 EIGEN_STRONG_INLINE
PlainObjectBase(Index size, Index rows, Index cols)
493 : m_storage(size, rows, cols)
501 template<
typename OtherDerived>
505 _resize_to_match(other);
506 Base::operator=(other.
derived());
507 return this->derived();
511 template<
typename OtherDerived>
516 _check_template_params();
522 template<
typename OtherDerived>
527 _check_template_params();
532 template<
typename OtherDerived>
536 _check_template_params();
538 resize(other.rows(), other.cols());
539 other.evalTo(this->derived());
550 static inline ConstMapType
Map(
const Scalar*
data)
551 {
return ConstMapType(data); }
552 static inline MapType Map(Scalar*
data)
553 {
return MapType(data); }
554 static inline ConstMapType Map(
const Scalar*
data, Index size)
555 {
return ConstMapType(data, size); }
556 static inline MapType Map(Scalar*
data, Index size)
557 {
return MapType(data, size); }
558 static inline ConstMapType Map(
const Scalar*
data, Index rows, Index cols)
559 {
return ConstMapType(data, rows, cols); }
560 static inline MapType Map(Scalar*
data, Index rows, Index cols)
561 {
return MapType(data, rows, cols); }
563 static inline ConstAlignedMapType MapAligned(
const Scalar*
data)
564 {
return ConstAlignedMapType(data); }
565 static inline AlignedMapType MapAligned(Scalar*
data)
566 {
return AlignedMapType(data); }
567 static inline ConstAlignedMapType MapAligned(
const Scalar*
data, Index size)
568 {
return ConstAlignedMapType(data, size); }
569 static inline AlignedMapType MapAligned(Scalar*
data, Index size)
570 {
return AlignedMapType(data, size); }
571 static inline ConstAlignedMapType MapAligned(
const Scalar*
data, Index rows, Index cols)
572 {
return ConstAlignedMapType(data, rows, cols); }
573 static inline AlignedMapType MapAligned(Scalar*
data, Index rows, Index cols)
574 {
return AlignedMapType(data, rows, cols); }
576 template<
int Outer,
int Inner>
577 static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(
const Scalar*
data,
const Stride<Outer, Inner>& stride)
578 {
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, stride); }
579 template<
int Outer,
int Inner>
580 static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar*
data,
const Stride<Outer, Inner>& stride)
581 {
return typename StridedMapType<Stride<Outer, Inner> >::type(data, stride); }
582 template<
int Outer,
int Inner>
583 static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(
const Scalar*
data, Index size,
const Stride<Outer, Inner>& stride)
584 {
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, size, stride); }
585 template<
int Outer,
int Inner>
586 static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar*
data, Index size,
const Stride<Outer, Inner>& stride)
587 {
return typename StridedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
588 template<
int Outer,
int Inner>
589 static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(
const Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride)
590 {
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
591 template<
int Outer,
int Inner>
592 static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride)
593 {
return typename StridedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
595 template<
int Outer,
int Inner>
596 static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(
const Scalar*
data,
const Stride<Outer, Inner>& stride)
597 {
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
598 template<
int Outer,
int Inner>
599 static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar*
data,
const Stride<Outer, Inner>& stride)
600 {
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
601 template<
int Outer,
int Inner>
602 static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(
const Scalar*
data, Index size,
const Stride<Outer, Inner>& stride)
603 {
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
604 template<
int Outer,
int Inner>
605 static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar*
data, Index size,
const Stride<Outer, Inner>& stride)
606 {
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
607 template<
int Outer,
int Inner>
608 static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(
const Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride)
609 {
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
610 template<
int Outer,
int Inner>
611 static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride)
612 {
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
615 using Base::setConstant;
616 EIGEN_DEVICE_FUNC Derived&
setConstant(Index size,
const Scalar& value);
617 EIGEN_DEVICE_FUNC Derived&
setConstant(Index rows, Index cols,
const Scalar& value);
620 EIGEN_DEVICE_FUNC Derived&
setZero(Index size);
621 EIGEN_DEVICE_FUNC Derived&
setZero(Index rows, Index cols);
624 EIGEN_DEVICE_FUNC Derived&
setOnes(Index size);
625 EIGEN_DEVICE_FUNC Derived&
setOnes(Index rows, Index cols);
627 using Base::setRandom;
629 Derived&
setRandom(Index rows, Index cols);
631 #ifdef EIGEN_PLAINOBJECTBASE_PLUGIN
632 #include EIGEN_PLAINOBJECTBASE_PLUGIN
643 template<
typename OtherDerived>
645 EIGEN_STRONG_INLINE
void _resize_to_match(
const EigenBase<OtherDerived>& other)
647 #ifdef EIGEN_NO_AUTOMATIC_RESIZING
648 eigen_assert((this->size()==0 || (IsVectorAtCompileTime ? (this->size() == other.size())
649 : (rows() == other.rows() && cols() == other.cols())))
650 &&
"Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined");
651 EIGEN_ONLY_USED_FOR_DEBUG(other);
673 template<
typename OtherDerived>
677 internal::call_assignment(this->derived(), other.derived());
678 return this->derived();
686 template<
typename OtherDerived>
695 internal::call_assignment_no_alias(this->derived(), other.derived(), internal::assign_op<Scalar>());
696 return this->derived();
699 template<
typename T0,
typename T1>
701 EIGEN_STRONG_INLINE
void _init2(Index rows, Index cols,
typename internal::enable_if<Base::SizeAtCompileTime!=2,T0>::type* = 0)
703 EIGEN_STATIC_ASSERT(
bool(NumTraits<T0>::IsInteger) &&
704 bool(NumTraits<T1>::IsInteger),
705 FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
709 template<typename T0, typename T1>
711 EIGEN_STRONG_INLINE
void _init2(const Scalar& val0, const Scalar& val1, typename
internal::enable_if<Base::SizeAtCompileTime==2,T0>::type* = 0)
713 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
714 m_storage.
data()[0] = val0;
715 m_storage.
data()[1] = val1;
718 template<typename T0, typename T1>
720 EIGEN_STRONG_INLINE
void _init2(const Index& val0, const Index& val1,
722 && (
internal::is_same<T0,Index>::value)
723 && (
internal::is_same<T1,Index>::value)
724 && Base::SizeAtCompileTime==2,T1>::type* = 0)
726 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
727 m_storage.
data()[0] = Scalar(val0);
728 m_storage.
data()[1] = Scalar(val1);
735 EIGEN_STRONG_INLINE
void _init1(Index size, typename
internal::enable_if< (Base::SizeAtCompileTime!=1 || !
internal::is_convertible<T, Scalar>::value)
736 && ((!
internal::is_same<typename
internal::traits<Derived>::XprKind,ArrayXpr>::value || Base::SizeAtCompileTime==Dynamic)),T>::type* = 0)
739 const bool is_integer = NumTraits<T>::IsInteger;
740 EIGEN_STATIC_ASSERT(is_integer,
741 FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
748 EIGEN_STRONG_INLINE
void _init1(const Scalar& val0, typename
internal::enable_if<Base::SizeAtCompileTime==1 &&
internal::is_convertible<T, Scalar>::value,T>::type* = 0)
750 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
751 m_storage.
data()[0] = val0;
757 EIGEN_STRONG_INLINE
void _init1(const Index& val0,
759 && (
internal::is_same<Index,T>::value)
760 && Base::SizeAtCompileTime==1
761 &&
internal::is_convertible<T, Scalar>::value,T*>::type* = 0)
763 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
764 m_storage.
data()[0] = Scalar(val0);
770 EIGEN_STRONG_INLINE
void _init1(const Scalar*
data){
771 this->_set_noalias(ConstMapType(data));
775 template<
typename T,
typename OtherDerived>
777 EIGEN_STRONG_INLINE
void _init1(
const DenseBase<OtherDerived>& other){
778 this->_set_noalias(other);
782 template<
typename T,
typename OtherDerived>
784 EIGEN_STRONG_INLINE
void _init1(
const EigenBase<OtherDerived>& other){
785 this->derived() = other;
788 template<
typename T,
typename OtherDerived>
790 EIGEN_STRONG_INLINE
void _init1(
const ReturnByValue<OtherDerived>& other)
792 resize(other.rows(), other.cols());
793 other.evalTo(this->derived());
796 template<
typename T,
typename OtherDerived,
int ColsAtCompileTime>
798 EIGEN_STRONG_INLINE
void _init1(
const RotationBase<OtherDerived,ColsAtCompileTime>& r)
806 EIGEN_STRONG_INLINE
void _init1(
const Scalar& val0,
807 typename internal::enable_if< Base::SizeAtCompileTime!=Dynamic
808 && Base::SizeAtCompileTime!=1
809 && internal::is_convertible<T, Scalar>::value
810 && internal::is_same<
typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T>::type* = 0)
812 Base::setConstant(val0);
817 EIGEN_STRONG_INLINE
void _init1(
const Index& val0,
818 typename internal::enable_if< (!internal::is_same<Index,Scalar>::value)
819 && (internal::is_same<Index,T>::value)
820 && Base::SizeAtCompileTime!=Dynamic
821 && Base::SizeAtCompileTime!=1
822 && internal::is_convertible<T, Scalar>::value
823 && internal::is_same<
typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T*>::type* = 0)
825 Base::setConstant(val0);
828 template<
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
829 friend struct internal::matrix_swap_impl;
833 #ifndef EIGEN_PARSED_BY_DOXYGEN
838 template<
typename OtherDerived>
840 void swap(DenseBase<OtherDerived> & other)
842 enum { SwapPointers = internal::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime==Dynamic };
843 internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.derived());
849 template<
typename OtherDerived>
851 void swap(DenseBase<OtherDerived>
const & other)
852 { Base::swap(other.derived()); }
855 static EIGEN_STRONG_INLINE
void _check_template_params()
857 EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, (Options&
RowMajor)==RowMajor)
858 && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, (Options&RowMajor)==0)
859 && ((RowsAtCompileTime == Dynamic) || (RowsAtCompileTime >= 0))
860 && ((ColsAtCompileTime == Dynamic) || (ColsAtCompileTime >= 0))
861 && ((MaxRowsAtCompileTime == Dynamic) || (MaxRowsAtCompileTime >= 0))
862 && ((MaxColsAtCompileTime == Dynamic) || (MaxColsAtCompileTime >= 0))
863 && (MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime==Dynamic)
864 && (MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime==Dynamic)
865 && (Options & (
DontAlign|RowMajor)) == Options),
866 INVALID_MATRIX_TEMPLATE_PARAMETERS)
869 enum { IsPlainObjectBase = 1 };
875 template <
typename Derived,
typename OtherDerived,
bool IsVector>
876 struct conservative_resize_like_impl
878 static void run(DenseBase<Derived>& _this, Index rows, Index cols)
880 if (_this.rows() == rows && _this.cols() == cols)
return;
881 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
883 if ( ( Derived::IsRowMajor && _this.cols() == cols) ||
884 (!Derived::IsRowMajor && _this.rows() == rows) )
886 internal::check_rows_cols_for_overflow<Derived::MaxSizeAtCompileTime>::run(rows, cols);
887 _this.derived().m_storage.conservativeResize(rows*cols,rows,cols);
892 typename Derived::PlainObject tmp(rows,cols);
893 const Index common_rows = (std::min)(rows, _this.rows());
894 const Index common_cols = (std::min)(cols, _this.cols());
895 tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols);
896 _this.derived().swap(tmp);
900 static void run(DenseBase<Derived>& _this,
const DenseBase<OtherDerived>& other)
902 if (_this.rows() == other.rows() && _this.cols() == other.cols())
return;
909 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
910 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(OtherDerived)
912 if ( ( Derived::IsRowMajor && _this.cols() == other.cols()) ||
913 (!Derived::IsRowMajor && _this.rows() == other.rows()) )
915 const Index new_rows = other.rows() - _this.rows();
916 const Index new_cols = other.cols() - _this.cols();
917 _this.derived().m_storage.conservativeResize(other.size(),other.rows(),other.cols());
919 _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows);
921 _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols);
926 typename Derived::PlainObject tmp(other);
927 const Index common_rows = (std::min)(tmp.rows(), _this.rows());
928 const Index common_cols = (std::min)(tmp.cols(), _this.cols());
929 tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols);
930 _this.derived().swap(tmp);
937 template <
typename Derived,
typename OtherDerived>
938 struct conservative_resize_like_impl<Derived,OtherDerived,true>
939 : conservative_resize_like_impl<Derived,OtherDerived,false>
941 using conservative_resize_like_impl<Derived,OtherDerived,false>::run;
943 static void run(DenseBase<Derived>& _this, Index size)
945 const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : size;
946 const Index new_cols = Derived::RowsAtCompileTime==1 ? size : 1;
947 _this.derived().m_storage.conservativeResize(size,new_rows,new_cols);
950 static void run(DenseBase<Derived>& _this,
const DenseBase<OtherDerived>& other)
952 if (_this.rows() == other.rows() && _this.cols() == other.cols())
return;
954 const Index num_new_elements = other.size() - _this.size();
956 const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : other.rows();
957 const Index new_cols = Derived::RowsAtCompileTime==1 ? other.cols() : 1;
958 _this.derived().m_storage.conservativeResize(other.size(),new_rows,new_cols);
960 if (num_new_elements > 0)
961 _this.tail(num_new_elements) = other.tail(num_new_elements);
965 template<
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
966 struct matrix_swap_impl
969 static inline void run(MatrixTypeA& a, MatrixTypeB& b)
975 template<
typename MatrixTypeA,
typename MatrixTypeB>
976 struct matrix_swap_impl<MatrixTypeA, MatrixTypeB, true>
979 static inline void run(MatrixTypeA& a, MatrixTypeB& b)
981 static_cast<typename MatrixTypeA::Base&
>(a).m_storage.swap(static_cast<typename MatrixTypeB::Base&>(b).m_storage);
989 #endif // EIGEN_DENSESTORAGEBASE_H
void resize(NoChange_t, Index cols)
Definition: PlainObjectBase.h:308
Definition: Constants.h:314
PlainObjectBase(const ReturnByValue< OtherDerived > &other)
Copy constructor with in-place evaluation.
Definition: PlainObjectBase.h:534
Derived & lazyAssign(const DenseBase< OtherDerived > &other)
Definition: PlainObjectBase.h:439
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:89
void conservativeResize(Index rows, Index cols)
Definition: PlainObjectBase.h:364
Derived & setRandom(Index size)
Definition: Random.h:152
Definition: StdDeque.h:58
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:107
Derived & derived()
Definition: EigenBase.h:44
const unsigned int RowMajorBit
Definition: Constants.h:53
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:252
Definition: Constants.h:318
PlainObjectBase(const DenseBase< OtherDerived > &other)
Definition: PlainObjectBase.h:513
PlainObjectBase(const EigenBase< OtherDerived > &other)
Definition: PlainObjectBase.h:524
PlainObjectBase(const PlainObjectBase &other)
Definition: PlainObjectBase.h:489
Definition: EigenBase.h:28
Scalar * data()
Definition: PlainObjectBase.h:232
Derived & setOnes(Index size)
Definition: CwiseNullaryOp.h:646
void conservativeResize(NoChange_t, Index cols)
Definition: PlainObjectBase.h:391
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:520
void resizeLike(const EigenBase< OtherDerived > &_other)
Definition: PlainObjectBase.h:336
void resize(Index rows, NoChange_t)
Definition: PlainObjectBase.h:322
Dense storage base class for matrices and arrays.
Definition: PlainObjectBase.h:88
Derived & operator=(const PlainObjectBase &other)
Definition: PlainObjectBase.h:431
void conservativeResize(Index size)
Definition: PlainObjectBase.h:406
Definition: Eigen_Colamd.h:54
void resize(Index size)
Definition: PlainObjectBase.h:283
void conservativeResizeLike(const DenseBase< OtherDerived > &other)
Definition: PlainObjectBase.h:422
const Scalar * data() const
Definition: PlainObjectBase.h:228
void conservativeResize(Index rows, NoChange_t)
Definition: PlainObjectBase.h:377
Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition: PlainObjectBase.h:675
Derived & operator=(const EigenBase< OtherDerived > &other)
Definition: PlainObjectBase.h:503
Derived & setConstant(Index size, const Scalar &value)
Definition: CwiseNullaryOp.h:352