101 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
102 typedef typename NumTraits<Scalar>::Real
RealScalar;
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;
119#if EIGEN_MAX_ALIGN_BYTES>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);
229 {
return m_storage.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.");
260 #ifdef EIGEN_INITIALIZE_COEFFS
261 Index size = rows*cols;
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
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>
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());
419 template<
typename OtherDerived>
436 template<
typename OtherDerived>
440 _resize_to_match(other);
441 return Base::lazyAssign(other.derived());
444 template<
typename OtherDerived>
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();
521 *
this = other.derived();
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>
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,
726 typename internal::enable_if< (!internal::is_same<Index,Scalar>::value)
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,
763 typename internal::enable_if< (!internal::is_same<Index,Scalar>::value)
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)
871 INVALID_MATRIX_TEMPLATE_PARAMETERS)
874 enum { IsPlainObjectBase = 1 };