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 m_storage.resize(rows*cols, rows, cols);
285 eigen_assert(((SizeAtCompileTime == Dynamic && (MaxSizeAtCompileTime==Dynamic || size<=MaxSizeAtCompileTime)) || SizeAtCompileTime == size) && size>=0);
286 #ifdef EIGEN_INITIALIZE_COEFFS
287 bool size_changed = size != this->size();
289 if(RowsAtCompileTime == 1)
290 m_storage.resize(size, 1, size);
292 m_storage.resize(size, size, 1);
293 #ifdef EIGEN_INITIALIZE_COEFFS
294 if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
307 inline void resize(NoChange_t, Index cols)
321 inline void resize(Index rows, NoChange_t)
333 template<
typename OtherDerived>
337 const OtherDerived& other = _other.
derived();
338 internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(other.rows(), other.cols());
339 const Index othersize = other.rows()*other.cols();
340 if(RowsAtCompileTime == 1)
342 eigen_assert(other.rows() == 1 || other.cols() == 1);
345 else if(ColsAtCompileTime == 1)
347 eigen_assert(other.rows() == 1 || other.cols() == 1);
350 else resize(other.rows(), other.cols());
365 internal::conservative_resize_like_impl<Derived>::run(*
this, rows, cols);
407 internal::conservative_resize_like_impl<Derived>::run(*
this, size);
419 template<
typename OtherDerived>
423 internal::conservative_resize_like_impl<Derived,OtherDerived>::run(*
this, other);
436 template<
typename OtherDerived>
440 _resize_to_match(other);
441 return Base::lazyAssign(other.derived());
444 template<
typename OtherDerived>
446 EIGEN_STRONG_INLINE Derived&
operator=(
const ReturnByValue<OtherDerived>& func)
448 resize(func.rows(), func.cols());
449 return Base::operator=(func);
457 EIGEN_STRONG_INLINE PlainObjectBase() : m_storage()
463 #ifndef EIGEN_PARSED_BY_DOXYGEN
467 explicit PlainObjectBase(internal::constructor_without_unaligned_array_assert)
468 : m_storage(
internal::constructor_without_unaligned_array_assert())
474 #ifdef EIGEN_HAVE_RVALUE_REFERENCES
476 PlainObjectBase(PlainObjectBase&& other)
477 : m_storage(
std::move(other.m_storage) )
482 PlainObjectBase&
operator=(PlainObjectBase&& other)
485 swap(m_storage, other.m_storage);
493 : Base(), m_storage(other.m_storage) { }
495 EIGEN_STRONG_INLINE
PlainObjectBase(Index size, Index rows, Index cols)
496 : m_storage(size, rows, cols)
503 template<
typename OtherDerived>
508 _check_template_params();
514 template<
typename OtherDerived>
519 _check_template_params();
524 template<
typename OtherDerived>
528 _check_template_params();
530 resize(other.rows(), other.cols());
531 other.evalTo(this->derived());
538 template<
typename OtherDerived>
542 _resize_to_match(other);
543 Base::operator=(other.
derived());
544 return this->derived();
555 static inline ConstMapType
Map(
const Scalar*
data)
556 {
return ConstMapType(data); }
557 static inline MapType Map(Scalar*
data)
558 {
return MapType(data); }
559 static inline ConstMapType Map(
const Scalar*
data, Index size)
560 {
return ConstMapType(data, size); }
561 static inline MapType Map(Scalar*
data, Index size)
562 {
return MapType(data, size); }
563 static inline ConstMapType Map(
const Scalar*
data, Index rows, Index cols)
564 {
return ConstMapType(data, rows, cols); }
565 static inline MapType Map(Scalar*
data, Index rows, Index cols)
566 {
return MapType(data, rows, cols); }
568 static inline ConstAlignedMapType MapAligned(
const Scalar*
data)
569 {
return ConstAlignedMapType(data); }
570 static inline AlignedMapType MapAligned(Scalar*
data)
571 {
return AlignedMapType(data); }
572 static inline ConstAlignedMapType MapAligned(
const Scalar*
data, Index size)
573 {
return ConstAlignedMapType(data, size); }
574 static inline AlignedMapType MapAligned(Scalar*
data, Index size)
575 {
return AlignedMapType(data, size); }
576 static inline ConstAlignedMapType MapAligned(
const Scalar*
data, Index rows, Index cols)
577 {
return ConstAlignedMapType(data, rows, cols); }
578 static inline AlignedMapType MapAligned(Scalar*
data, Index rows, Index cols)
579 {
return AlignedMapType(data, rows, cols); }
581 template<
int Outer,
int Inner>
582 static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(
const Scalar*
data,
const Stride<Outer, Inner>& stride)
583 {
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, stride); }
584 template<
int Outer,
int Inner>
585 static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar*
data,
const Stride<Outer, Inner>& stride)
586 {
return typename StridedMapType<Stride<Outer, Inner> >::type(data, stride); }
587 template<
int Outer,
int Inner>
588 static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(
const Scalar*
data, Index size,
const Stride<Outer, Inner>& stride)
589 {
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, size, stride); }
590 template<
int Outer,
int Inner>
591 static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar*
data, Index size,
const Stride<Outer, Inner>& stride)
592 {
return typename StridedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
593 template<
int Outer,
int Inner>
594 static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(
const Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride)
595 {
return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
596 template<
int Outer,
int Inner>
597 static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride)
598 {
return typename StridedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
600 template<
int Outer,
int Inner>
601 static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(
const Scalar*
data,
const Stride<Outer, Inner>& stride)
602 {
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
603 template<
int Outer,
int Inner>
604 static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar*
data,
const Stride<Outer, Inner>& stride)
605 {
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
606 template<
int Outer,
int Inner>
607 static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(
const Scalar*
data, Index size,
const Stride<Outer, Inner>& stride)
608 {
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
609 template<
int Outer,
int Inner>
610 static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar*
data, Index size,
const Stride<Outer, Inner>& stride)
611 {
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
612 template<
int Outer,
int Inner>
613 static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(
const Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride)
614 {
return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
615 template<
int Outer,
int Inner>
616 static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride)
617 {
return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
620 using Base::setConstant;
621 EIGEN_DEVICE_FUNC Derived&
setConstant(Index size,
const Scalar& value);
622 EIGEN_DEVICE_FUNC Derived&
setConstant(Index rows, Index cols,
const Scalar& value);
625 EIGEN_DEVICE_FUNC Derived&
setZero(Index size);
626 EIGEN_DEVICE_FUNC Derived&
setZero(Index rows, Index cols);
629 EIGEN_DEVICE_FUNC Derived&
setOnes(Index size);
630 EIGEN_DEVICE_FUNC Derived&
setOnes(Index rows, Index cols);
632 using Base::setRandom;
634 Derived&
setRandom(Index rows, Index cols);
636 #ifdef EIGEN_PLAINOBJECTBASE_PLUGIN
637 #include EIGEN_PLAINOBJECTBASE_PLUGIN
648 template<
typename OtherDerived>
650 EIGEN_STRONG_INLINE
void _resize_to_match(
const EigenBase<OtherDerived>& other)
652 #ifdef EIGEN_NO_AUTOMATIC_RESIZING
653 eigen_assert((this->size()==0 || (IsVectorAtCompileTime ? (this->size() == other.size())
654 : (rows() == other.rows() && cols() == other.cols())))
655 &&
"Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined");
656 EIGEN_ONLY_USED_FOR_DEBUG(other);
678 template<
typename OtherDerived>
682 internal::call_assignment(this->derived(), other.derived());
683 return this->derived();
691 template<
typename OtherDerived>
700 internal::call_assignment_no_alias(this->derived(), other.derived(), internal::assign_op<Scalar>());
701 return this->derived();
704 template<
typename T0,
typename T1>
706 EIGEN_STRONG_INLINE
void _init2(Index rows, Index cols,
typename internal::enable_if<Base::SizeAtCompileTime!=2,T0>::type* = 0)
708 EIGEN_STATIC_ASSERT(
bool(NumTraits<T0>::IsInteger) &&
709 bool(NumTraits<T1>::IsInteger),
710 FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
714 template<typename T0, typename T1>
716 EIGEN_STRONG_INLINE
void _init2(const Scalar& val0, const Scalar& val1, typename
internal::enable_if<Base::SizeAtCompileTime==2,T0>::type* = 0)
718 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
719 m_storage.
data()[0] = val0;
720 m_storage.
data()[1] = val1;
723 template<typename T0, typename T1>
725 EIGEN_STRONG_INLINE
void _init2(const Index& val0, const Index& val1,
727 && (
internal::is_same<T0,Index>::value)
728 && (
internal::is_same<T1,Index>::value)
729 && Base::SizeAtCompileTime==2,T1>::type* = 0)
731 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
732 m_storage.
data()[0] = Scalar(val0);
733 m_storage.
data()[1] = Scalar(val1);
740 EIGEN_STRONG_INLINE
void _init1(Index size, typename
internal::enable_if< (Base::SizeAtCompileTime!=1 || !
internal::is_convertible<T, Scalar>::value)
741 && ((!
internal::is_same<typename
internal::traits<Derived>::XprKind,ArrayXpr>::value || Base::SizeAtCompileTime==Dynamic)),T>::type* = 0)
744 const bool is_integer = NumTraits<T>::IsInteger;
745 EIGEN_STATIC_ASSERT(is_integer,
746 FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
753 EIGEN_STRONG_INLINE
void _init1(const Scalar& val0, typename
internal::enable_if<Base::SizeAtCompileTime==1 &&
internal::is_convertible<T, Scalar>::value,T>::type* = 0)
755 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
756 m_storage.
data()[0] = val0;
762 EIGEN_STRONG_INLINE
void _init1(const Index& val0,
764 && (
internal::is_same<Index,T>::value)
765 && Base::SizeAtCompileTime==1
766 &&
internal::is_convertible<T, Scalar>::value,T*>::type* = 0)
768 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
769 m_storage.
data()[0] = Scalar(val0);
775 EIGEN_STRONG_INLINE
void _init1(const Scalar*
data){
776 this->_set_noalias(ConstMapType(data));
780 template<
typename T,
typename OtherDerived>
782 EIGEN_STRONG_INLINE
void _init1(
const DenseBase<OtherDerived>& other){
783 this->_set_noalias(other);
787 template<
typename T,
typename OtherDerived>
789 EIGEN_STRONG_INLINE
void _init1(
const EigenBase<OtherDerived>& other){
790 this->derived() = other;
793 template<
typename T,
typename OtherDerived>
795 EIGEN_STRONG_INLINE
void _init1(
const ReturnByValue<OtherDerived>& other)
797 resize(other.rows(), other.cols());
798 other.evalTo(this->derived());
801 template<
typename T,
typename OtherDerived,
int ColsAtCompileTime>
803 EIGEN_STRONG_INLINE
void _init1(
const RotationBase<OtherDerived,ColsAtCompileTime>& r)
811 EIGEN_STRONG_INLINE
void _init1(
const Scalar& val0,
812 typename internal::enable_if< Base::SizeAtCompileTime!=Dynamic
813 && Base::SizeAtCompileTime!=1
814 && internal::is_convertible<T, Scalar>::value
815 && internal::is_same<
typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T>::type* = 0)
817 Base::setConstant(val0);
822 EIGEN_STRONG_INLINE
void _init1(
const Index& val0,
823 typename internal::enable_if< (!internal::is_same<Index,Scalar>::value)
824 && (internal::is_same<Index,T>::value)
825 && Base::SizeAtCompileTime!=Dynamic
826 && Base::SizeAtCompileTime!=1
827 && internal::is_convertible<T, Scalar>::value
828 && internal::is_same<
typename internal::traits<Derived>::XprKind,ArrayXpr>::value,T*>::type* = 0)
830 Base::setConstant(val0);
833 template<
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
834 friend struct internal::matrix_swap_impl;
838 #ifndef EIGEN_PARSED_BY_DOXYGEN
843 template<
typename OtherDerived>
845 void swap(DenseBase<OtherDerived> & other)
847 enum { SwapPointers = internal::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime==Dynamic };
848 internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.derived());
854 template<
typename OtherDerived>
856 void swap(DenseBase<OtherDerived>
const & other)
857 { Base::swap(other.derived()); }
860 static EIGEN_STRONG_INLINE
void _check_template_params()
862 EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, (Options&
RowMajor)==RowMajor)
863 && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, (Options&RowMajor)==0)
864 && ((RowsAtCompileTime == Dynamic) || (RowsAtCompileTime >= 0))
865 && ((ColsAtCompileTime == Dynamic) || (ColsAtCompileTime >= 0))
866 && ((MaxRowsAtCompileTime == Dynamic) || (MaxRowsAtCompileTime >= 0))
867 && ((MaxColsAtCompileTime == Dynamic) || (MaxColsAtCompileTime >= 0))
868 && (MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime==Dynamic)
869 && (MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime==Dynamic)
870 && (Options & (
DontAlign|RowMajor)) == Options),
871 INVALID_MATRIX_TEMPLATE_PARAMETERS)
874 enum { IsPlainObjectBase = 1 };
880 template <
typename Derived,
typename OtherDerived,
bool IsVector>
881 struct conservative_resize_like_impl
883 static void run(DenseBase<Derived>& _this, Index rows, Index cols)
885 if (_this.rows() == rows && _this.cols() == cols)
return;
886 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
888 if ( ( Derived::IsRowMajor && _this.cols() == cols) ||
889 (!Derived::IsRowMajor && _this.rows() == rows) )
891 internal::check_rows_cols_for_overflow<Derived::MaxSizeAtCompileTime>::run(rows, cols);
892 _this.derived().m_storage.conservativeResize(rows*cols,rows,cols);
897 typename Derived::PlainObject tmp(rows,cols);
898 const Index common_rows = (std::min)(rows, _this.rows());
899 const Index common_cols = (std::min)(cols, _this.cols());
900 tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols);
901 _this.derived().swap(tmp);
905 static void run(DenseBase<Derived>& _this,
const DenseBase<OtherDerived>& other)
907 if (_this.rows() == other.rows() && _this.cols() == other.cols())
return;
914 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
915 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(OtherDerived)
917 if ( ( Derived::IsRowMajor && _this.cols() == other.cols()) ||
918 (!Derived::IsRowMajor && _this.rows() == other.rows()) )
920 const Index new_rows = other.rows() - _this.rows();
921 const Index new_cols = other.cols() - _this.cols();
922 _this.derived().m_storage.conservativeResize(other.size(),other.rows(),other.cols());
924 _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows);
926 _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols);
931 typename Derived::PlainObject tmp(other);
932 const Index common_rows = (std::min)(tmp.rows(), _this.rows());
933 const Index common_cols = (std::min)(tmp.cols(), _this.cols());
934 tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols);
935 _this.derived().swap(tmp);
942 template <
typename Derived,
typename OtherDerived>
943 struct conservative_resize_like_impl<Derived,OtherDerived,true>
944 : conservative_resize_like_impl<Derived,OtherDerived,false>
946 using conservative_resize_like_impl<Derived,OtherDerived,false>::run;
948 static void run(DenseBase<Derived>& _this, Index size)
950 const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : size;
951 const Index new_cols = Derived::RowsAtCompileTime==1 ? size : 1;
952 _this.derived().m_storage.conservativeResize(size,new_rows,new_cols);
955 static void run(DenseBase<Derived>& _this,
const DenseBase<OtherDerived>& other)
957 if (_this.rows() == other.rows() && _this.cols() == other.cols())
return;
959 const Index num_new_elements = other.size() - _this.size();
961 const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : other.rows();
962 const Index new_cols = Derived::RowsAtCompileTime==1 ? other.cols() : 1;
963 _this.derived().m_storage.conservativeResize(other.size(),new_rows,new_cols);
965 if (num_new_elements > 0)
966 _this.tail(num_new_elements) = other.tail(num_new_elements);
970 template<
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
971 struct matrix_swap_impl
974 static inline void run(MatrixTypeA& a, MatrixTypeB& b)
980 template<
typename MatrixTypeA,
typename MatrixTypeB>
981 struct matrix_swap_impl<MatrixTypeA, MatrixTypeB, true>
984 static inline void run(MatrixTypeA& a, MatrixTypeB& b)
986 static_cast<typename MatrixTypeA::Base&
>(a).m_storage.swap(static_cast<typename MatrixTypeB::Base&>(b).m_storage);
994 #endif // EIGEN_DENSESTORAGEBASE_H
void resize(NoChange_t, Index cols)
Definition: PlainObjectBase.h:307
PlainObjectBase(const ReturnByValue< OtherDerived > &other)
Copy constructor with in-place evaluation.
Definition: PlainObjectBase.h:526
Derived & lazyAssign(const DenseBase< OtherDerived > &other)
Definition: PlainObjectBase.h:438
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:89
void conservativeResize(Index rows, Index cols)
Definition: PlainObjectBase.h:363
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:61
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:252
PlainObjectBase(const DenseBase< OtherDerived > &other)
Definition: PlainObjectBase.h:505
PlainObjectBase(const EigenBase< OtherDerived > &other)
Definition: PlainObjectBase.h:516
PlainObjectBase(const PlainObjectBase &other)
Definition: PlainObjectBase.h:492
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:390
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:520
void resizeLike(const EigenBase< OtherDerived > &_other)
Definition: PlainObjectBase.h:335
Definition: Constants.h:322
void resize(Index rows, NoChange_t)
Definition: PlainObjectBase.h:321
Dense storage base class for matrices and arrays.
Definition: PlainObjectBase.h:88
Derived & operator=(const PlainObjectBase &other)
Definition: PlainObjectBase.h:430
void conservativeResize(Index size)
Definition: PlainObjectBase.h:405
Definition: Eigen_Colamd.h:54
void resize(Index size)
Definition: PlainObjectBase.h:282
Definition: Constants.h:326
void conservativeResizeLike(const DenseBase< OtherDerived > &other)
Definition: PlainObjectBase.h:421
const Scalar * data() const
Definition: PlainObjectBase.h:228
void conservativeResize(Index rows, NoChange_t)
Definition: PlainObjectBase.h:376
Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition: PlainObjectBase.h:680
Derived & operator=(const EigenBase< OtherDerived > &other)
Definition: PlainObjectBase.h:540
Derived & setConstant(Index size, const Scalar &value)
Definition: CwiseNullaryOp.h:352