200 EIGEN_DEVICE_FUNC
constexpr const Scalar&
coeff(Index rowId, Index colId)
const {
202 return m_storage.data()[colId + rowId * m_storage.cols()];
204 return m_storage.data()[rowId + colId * m_storage.rows()];
212 EIGEN_DEVICE_FUNC
constexpr const Scalar&
coeff(Index index)
const {
return m_storage.data()[index]; }
218 EIGEN_DEVICE_FUNC
constexpr Scalar&
coeffRef(Index rowId, Index colId) {
220 return m_storage.data()[colId + rowId * m_storage.cols()];
222 return m_storage.data()[rowId + colId * m_storage.rows()];
230 EIGEN_DEVICE_FUNC
constexpr Scalar&
coeffRef(Index index) {
return m_storage.data()[index]; }
234 EIGEN_DEVICE_FUNC
constexpr const Scalar&
coeffRef(Index rowId, Index colId)
const {
236 return m_storage.data()[colId + rowId * m_storage.cols()];
238 return m_storage.data()[rowId + colId * m_storage.rows()];
244 EIGEN_DEVICE_FUNC
constexpr const Scalar&
coeffRef(Index index)
const {
return m_storage.data()[index]; }
247 template <
int LoadMode>
248 EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId)
const {
249 return internal::ploadt<PacketScalar, LoadMode>(
250 m_storage.data() + (Flags &
RowMajorBit ? colId + rowId * m_storage.cols() : rowId + colId * m_storage.rows()));
254 template <
int LoadMode>
255 EIGEN_STRONG_INLINE PacketScalar packet(Index index)
const {
256 return internal::ploadt<PacketScalar, LoadMode>(m_storage.data() + index);
260 template <
int StoreMode>
261 EIGEN_STRONG_INLINE
void writePacket(Index rowId, Index colId,
const PacketScalar& val) {
262 internal::pstoret<Scalar, PacketScalar, StoreMode>(
263 m_storage.data() + (Flags &
RowMajorBit ? colId + rowId * m_storage.cols() : rowId + colId * m_storage.rows()),
268 template <
int StoreMode>
269 EIGEN_STRONG_INLINE
void writePacket(Index index,
const PacketScalar& val) {
270 internal::pstoret<Scalar, PacketScalar, StoreMode>(m_storage.data() + index, val);
274 EIGEN_DEVICE_FUNC
constexpr const Scalar*
data()
const {
return m_storage.data(); }
277 EIGEN_DEVICE_FUNC
constexpr Scalar*
data() {
return m_storage.data(); }
295 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr void resize(Index rows, Index cols) {
296 eigen_assert(internal::check_implication(RowsAtCompileTime != Dynamic, rows == RowsAtCompileTime) &&
297 internal::check_implication(ColsAtCompileTime != Dynamic, cols == ColsAtCompileTime) &&
298 internal::check_implication(RowsAtCompileTime == Dynamic && MaxRowsAtCompileTime != Dynamic,
299 rows <= MaxRowsAtCompileTime) &&
300 internal::check_implication(ColsAtCompileTime == Dynamic && MaxColsAtCompileTime != Dynamic,
301 cols <= MaxColsAtCompileTime) &&
302 rows >= 0 && cols >= 0 &&
"Invalid sizes when resizing a matrix or array.");
303#ifndef EIGEN_NO_DEBUG
304 internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime>::run(rows,
307#ifdef EIGEN_INITIALIZE_COEFFS
308 Index size = rows * cols;
309 bool size_changed = size != this->size();
310 m_storage.resize(size, rows, cols);
311 if (size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
313 m_storage.resize(rows * cols, rows, cols);
328 EIGEN_DEVICE_FUNC
constexpr void resize(Index size) {
329 EIGEN_STATIC_ASSERT_VECTOR_ONLY(PlainObjectBase)
330 eigen_assert(((SizeAtCompileTime == Dynamic && (MaxSizeAtCompileTime == Dynamic || size <= MaxSizeAtCompileTime)) ||
331 SizeAtCompileTime == size) &&
333#ifdef EIGEN_INITIALIZE_COEFFS
334 bool size_changed = size != this->size();
336 EIGEN_IF_CONSTEXPR (RowsAtCompileTime == 1) {
337 m_storage.resize(size, 1, size);
339 m_storage.resize(size, size, 1);
341#ifdef EIGEN_INITIALIZE_COEFFS
342 if (size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
354 EIGEN_DEVICE_FUNC
constexpr void resize(NoChange_t, Index cols) {
resize(rows(), cols); }
364 EIGEN_DEVICE_FUNC
constexpr void resize(Index rows, NoChange_t) {
resize(rows, cols()); }
376 template <
typename OtherDerived>
378 const OtherDerived& other = _other.
derived();
379 EIGEN_INTERNAL_ASSERT_VECTOR_IF(IsVectorAtCompileTime, other);
380#ifndef EIGEN_NO_DEBUG
381 internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime>::run(
382 other.rows(), other.cols());
384 const Index othersize = other.rows() * other.cols();
385 EIGEN_IF_CONSTEXPR (RowsAtCompileTime == 1) {
387 }
else EIGEN_IF_CONSTEXPR (ColsAtCompileTime == 1) {
390 resize(other.rows(), other.cols());
404 eigen_assert(internal::check_implication(MaxRowsAtCompileTime != Dynamic, rows <= MaxRowsAtCompileTime) &&
405 internal::check_implication(MaxColsAtCompileTime != Dynamic, cols <= MaxColsAtCompileTime) &&
406 "Invalid sizes when resizing a matrix or array.");
407 internal::conservative_resize_like_impl<Derived>::run(*
this, rows, cols);
443 eigen_assert((MaxSizeAtCompileTime == Dynamic || size <= MaxSizeAtCompileTime) &&
444 "Invalid sizes when resizing a matrix or array.");
445 internal::conservative_resize_like_impl<Derived>::run(*
this, size);
457 template <
typename OtherDerived>
461 (IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime
462 ? MaxSizeAtCompileTime == Dynamic || other.size() <= MaxSizeAtCompileTime
463 : internal::check_implication(MaxRowsAtCompileTime != Dynamic, other.rows() <= MaxRowsAtCompileTime) &&
464 internal::check_implication(MaxColsAtCompileTime != Dynamic,
465 other.cols() <= MaxColsAtCompileTime)) &&
466 "Invalid sizes when resizing a matrix or array.");
467 internal::conservative_resize_like_impl<Derived, OtherDerived>::run(*
this, other);
473 EIGEN_DEVICE_FUNC
constexpr Derived&
operator=(
const PlainObjectBase& other) {
return _set(other); }
476 template <
typename OtherDerived>
478 _resize_to_match(other);
479 return Base::lazyAssign(other.derived());
482 template <
typename OtherDerived>
483 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
operator=(
const ReturnByValue<OtherDerived>& func) {
484 resize(func.rows(), func.cols());
485 return Base::operator=(func);
491 EIGEN_DEVICE_FUNC
constexpr PlainObjectBase() =
default;
495 EIGEN_DEVICE_FUNC
constexpr PlainObjectBase&
operator=(PlainObjectBase&& other)
noexcept {
496 m_storage = std::move(other.m_storage);
502 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase(Index size, Index rows, Index cols)
503 : m_storage(size, rows, cols) {}
514 template <
typename... ArgTypes>
515 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
PlainObjectBase(
const Scalar& a0,
const Scalar& a1,
const Scalar& a2,
516 const Scalar& a3,
const ArgTypes&... args) {
517 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase,
sizeof...(args) + 4);
518 m_storage.data()[0] = a0;
519 m_storage.data()[1] = a1;
520 m_storage.data()[2] = a2;
521 m_storage.data()[3] = a3;
523 auto x = {(m_storage.data()[i++] = args, 0)...};
524 static_cast<void>(x);
531 const std::initializer_list<std::initializer_list<Scalar>>& list) {
532 size_t list_size = 0;
533 if (list.begin() != list.end()) {
534 list_size = list.begin()->size();
538 EIGEN_IF_CONSTEXPR (ColsAtCompileTime == 1) {
539 if (list.size() == 1) {
540 eigen_assert(list_size ==
static_cast<size_t>(RowsAtCompileTime) || RowsAtCompileTime == Dynamic);
541 resize(list_size, ColsAtCompileTime);
542 if (list.begin()->begin() !=
nullptr) {
544 for (
const Scalar& e : *list.begin()) {
552 eigen_assert(list.size() ==
static_cast<size_t>(RowsAtCompileTime) || RowsAtCompileTime == Dynamic);
553 eigen_assert(list_size ==
static_cast<size_t>(ColsAtCompileTime) || ColsAtCompileTime == Dynamic);
554 resize(list.size(), list_size);
557 for (
const std::initializer_list<Scalar>& row : list) {
558 eigen_assert(list_size == row.size());
560 for (
const Scalar& e : row) {
569 template <
typename OtherDerived>
576 template <
typename OtherDerived>
582 template <
typename OtherDerived>
583 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
PlainObjectBase(
const ReturnByValue<OtherDerived>& other) {
585 resize(other.rows(), other.cols());
586 other.evalTo(this->derived());
593 template <
typename OtherDerived>
595 _resize_to_match(other);
596 Base::operator=(other.
derived());
597 return this->derived();
612 EIGEN_DEVICE_FUNC
static inline ConstMapType
Map(
const Scalar*
data) {
return ConstMapType(
data); }
613 EIGEN_DEVICE_FUNC
static inline MapType Map(Scalar*
data) {
return MapType(
data); }
614 EIGEN_DEVICE_FUNC
static inline ConstMapType Map(
const Scalar*
data, Index size) {
return ConstMapType(
data, size); }
615 EIGEN_DEVICE_FUNC
static inline MapType Map(Scalar*
data, Index size) {
return MapType(
data, size); }
616 EIGEN_DEVICE_FUNC
static inline ConstMapType Map(
const Scalar*
data, Index rows, Index cols) {
617 return ConstMapType(
data, rows, cols);
619 EIGEN_DEVICE_FUNC
static inline MapType Map(Scalar*
data, Index rows, Index cols) {
620 return MapType(
data, rows, cols);
623 EIGEN_DEVICE_FUNC
static inline ConstAlignedMapType MapAligned(
const Scalar*
data) {
624 return ConstAlignedMapType(
data);
626 EIGEN_DEVICE_FUNC
static inline AlignedMapType MapAligned(Scalar*
data) {
return AlignedMapType(
data); }
627 EIGEN_DEVICE_FUNC
static inline ConstAlignedMapType MapAligned(
const Scalar*
data, Index size) {
628 return ConstAlignedMapType(
data, size);
630 EIGEN_DEVICE_FUNC
static inline AlignedMapType MapAligned(Scalar*
data, Index size) {
631 return AlignedMapType(
data, size);
633 EIGEN_DEVICE_FUNC
static inline ConstAlignedMapType MapAligned(
const Scalar*
data, Index rows, Index cols) {
634 return ConstAlignedMapType(
data, rows, cols);
636 EIGEN_DEVICE_FUNC
static inline AlignedMapType MapAligned(Scalar*
data, Index rows, Index cols) {
637 return AlignedMapType(
data, rows, cols);
640 template <
int Outer,
int Inner>
641 EIGEN_DEVICE_FUNC
static inline typename StridedConstMapType<Stride<Outer, Inner>>::type Map(
642 const Scalar*
data,
const Stride<Outer, Inner>& stride) {
643 return typename StridedConstMapType<Stride<Outer, Inner>>::type(
data, stride);
645 template <
int Outer,
int Inner>
646 EIGEN_DEVICE_FUNC
static inline typename StridedMapType<Stride<Outer, Inner>>::type Map(
647 Scalar*
data,
const Stride<Outer, Inner>& stride) {
648 return typename StridedMapType<Stride<Outer, Inner>>::type(
data, stride);
650 template <
int Outer,
int Inner>
651 EIGEN_DEVICE_FUNC
static inline typename StridedConstMapType<Stride<Outer, Inner>>::type Map(
652 const Scalar*
data, Index size,
const Stride<Outer, Inner>& stride) {
653 return typename StridedConstMapType<Stride<Outer, Inner>>::type(
data, size, stride);
655 template <
int Outer,
int Inner>
656 EIGEN_DEVICE_FUNC
static inline typename StridedMapType<Stride<Outer, Inner>>::type Map(
657 Scalar*
data, Index size,
const Stride<Outer, Inner>& stride) {
658 return typename StridedMapType<Stride<Outer, Inner>>::type(
data, size, stride);
660 template <
int Outer,
int Inner>
661 EIGEN_DEVICE_FUNC
static inline typename StridedConstMapType<Stride<Outer, Inner>>::type Map(
662 const Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride) {
663 return typename StridedConstMapType<Stride<Outer, Inner>>::type(
data, rows, cols, stride);
665 template <
int Outer,
int Inner>
666 EIGEN_DEVICE_FUNC
static inline typename StridedMapType<Stride<Outer, Inner>>::type Map(
667 Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride) {
668 return typename StridedMapType<Stride<Outer, Inner>>::type(
data, rows, cols, stride);
671 template <
int Outer,
int Inner>
672 EIGEN_DEVICE_FUNC
static inline typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
673 const Scalar*
data,
const Stride<Outer, Inner>& stride) {
674 return typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type(
data, stride);
676 template <
int Outer,
int Inner>
677 EIGEN_DEVICE_FUNC
static inline typename StridedAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
678 Scalar*
data,
const Stride<Outer, Inner>& stride) {
679 return typename StridedAlignedMapType<Stride<Outer, Inner>>::type(
data, stride);
681 template <
int Outer,
int Inner>
682 EIGEN_DEVICE_FUNC
static inline typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
683 const Scalar*
data, Index size,
const Stride<Outer, Inner>& stride) {
684 return typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type(
data, size, stride);
686 template <
int Outer,
int Inner>
687 EIGEN_DEVICE_FUNC
static inline typename StridedAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
688 Scalar*
data, Index size,
const Stride<Outer, Inner>& stride) {
689 return typename StridedAlignedMapType<Stride<Outer, Inner>>::type(
data, size, stride);
691 template <
int Outer,
int Inner>
692 EIGEN_DEVICE_FUNC
static inline typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
693 const Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride) {
694 return typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type(
data, rows, cols, stride);
696 template <
int Outer,
int Inner>
697 EIGEN_DEVICE_FUNC
static inline typename StridedAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
698 Scalar*
data, Index rows, Index cols,
const Stride<Outer, Inner>& stride) {
699 return typename StridedAlignedMapType<Stride<Outer, Inner>>::type(
data, rows, cols, stride);
703 using Base::setConstant;
704 EIGEN_DEVICE_FUNC Derived&
setConstant(Index size,
const Scalar& val);
705 EIGEN_DEVICE_FUNC Derived&
setConstant(Index rows, Index cols,
const Scalar& val);
706 EIGEN_DEVICE_FUNC Derived&
setConstant(NoChange_t, Index cols,
const Scalar& val);
707 EIGEN_DEVICE_FUNC Derived&
setConstant(Index rows, NoChange_t,
const Scalar& val);
710 EIGEN_DEVICE_FUNC Derived&
setZero(Index size);
711 EIGEN_DEVICE_FUNC Derived&
setZero(Index rows, Index cols);
712 EIGEN_DEVICE_FUNC Derived&
setZero(NoChange_t, Index cols);
713 EIGEN_DEVICE_FUNC Derived&
setZero(Index rows, NoChange_t);
716 EIGEN_DEVICE_FUNC Derived&
setOnes(Index size);
717 EIGEN_DEVICE_FUNC Derived&
setOnes(Index rows, Index cols);
718 EIGEN_DEVICE_FUNC Derived&
setOnes(NoChange_t, Index cols);
719 EIGEN_DEVICE_FUNC Derived&
setOnes(Index rows, NoChange_t);
721 using Base::setRandom;
727#ifdef EIGEN_PLAINOBJECTBASE_PLUGIN
728#include EIGEN_PLAINOBJECTBASE_PLUGIN
739 template <
typename OtherDerived>
741#ifdef EIGEN_NO_AUTOMATIC_RESIZING
742 constexpr bool shape_is_proven = IsVectorAtCompileTime ? (internal::vector_dimensions<OtherDerived>::Proven &&
743 internal::matching_sizes<Derived, OtherDerived>::Proven)
744 : internal::matching_shapes<Derived, OtherDerived>::Proven;
745 EIGEN_INTERNAL_SHAPE_ASSERT(
747 (this->size() == 0 ||
748 (IsVectorAtCompileTime ? ((other.
rows() == 1 || other.
cols() == 1) && this->size() == other.
size())
749 : (rows() == other.
rows() && cols() == other.
cols()))) &&
750 "Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined");
752 EIGEN_ONLY_USED_FOR_DEBUG(other);
774 template <
typename OtherDerived>
776 internal::call_assignment(this->derived(), other.derived());
777 return this->derived();
785 template <
typename OtherDerived>
792 internal::call_assignment_no_alias(this->derived(), other.derived(),
793 internal::assign_op<Scalar, typename OtherDerived::Scalar>());
794 return this->derived();
797 template <
typename T0,
typename T1, std::enable_if_t<Base::SizeAtCompileTime != 2, T0>* =
nullptr>
798 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
void _init2(Index rows, Index cols) {
799 EIGEN_STATIC_ASSERT(internal::is_valid_index_type<T0>::value && internal::is_valid_index_type<T1>::value,
800 T0 AND T1 MUST BE INTEGER TYPES)
804 template <
typename T0,
typename T1, std::enable_if_t<Base::SizeAtCompileTime == 2, T0>* =
nullptr>
805 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
void _init2(
const T0& val0,
const T1& val1) {
806 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
807 m_storage.
data()[0] = Scalar(val0);
808 m_storage.
data()[1] = Scalar(val1);
811 template <typename T0, typename T1,
812 std::enable_if_t<(!std::is_same<Index, Scalar>::value) && (std::is_same<T0, Index>::value) &&
813 (std::is_same<T1, Index>::value) && Base::SizeAtCompileTime == 2,
815 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE
void _init2(const Index& val0, const Index& val1) {
816 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
817 m_storage.
data()[0] = Scalar(val0);
818 m_storage.
data()[1] = Scalar(val1);
823 template <typename T,
824 std::enable_if_t<(Base::SizeAtCompileTime != 1 || !std::is_convertible<T, Scalar>::value) &&
825 ((!std::is_same<typename internal::traits<Derived>::XprKind, ArrayXpr>::value ||
826 Base::SizeAtCompileTime == Dynamic)),
828 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE
void _init1(Index size) {
829 EIGEN_STATIC_ASSERT(internal::is_valid_index_type<T>::value, FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
835 template <
typename T,
836 std::enable_if_t<Base::SizeAtCompileTime == 1 && std::is_convertible<T, Scalar>::value,
int> = 0>
837 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
void _init1(
const Scalar& val0) {
838 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
839 m_storage.
data()[0] = val0;
844 template <typename T, std::enable_if_t<(!std::is_same<Index, Scalar>::value) && (std::is_same<Index, T>::value) &&
845 Base::SizeAtCompileTime == 1 && std::is_convertible<T, Scalar>::value,
847 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE
void _init1(const Index& val0) {
848 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
849 m_storage.
data()[0] = Scalar(val0);
853 template <typename T>
854 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE
void _init1(const Scalar*
data) {
855 this->_set_noalias(ConstMapType(
data));
859 template <
typename T,
typename OtherDerived>
860 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
void _init1(
const DenseBase<OtherDerived>& other) {
861 this->_set_noalias(other);
865 template <
typename T>
866 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
void _init1(
const Derived& other) {
867 this->_set_noalias(other);
871 template <
typename T,
typename OtherDerived>
872 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
void _init1(
const EigenBase<OtherDerived>& other) {
873 this->derived() = other;
876 template <
typename T,
typename OtherDerived>
877 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
void _init1(
const ReturnByValue<OtherDerived>& other) {
878 resize(other.rows(), other.cols());
879 other.evalTo(this->derived());
882 template <
typename T,
typename OtherDerived,
int ColsAtCompileTime>
883 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
void _init1(
const RotationBase<OtherDerived, ColsAtCompileTime>& r) {
888 template <
typename T, std::enable_if_t<Base::SizeAtCompileTime != Dynamic && Base::SizeAtCompileTime != 1 &&
889 std::is_convertible<T, Scalar>::value &&
890 std::is_same<typename internal::traits<Derived>::XprKind, ArrayXpr>::value,
892 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
void _init1(
const Scalar& val0) {
893 Base::setConstant(val0);
897 template <
typename T, std::enable_if_t<(!std::is_same<Index, Scalar>::value) && (std::is_same<Index, T>::value) &&
898 Base::SizeAtCompileTime != Dynamic && Base::SizeAtCompileTime != 1 &&
899 std::is_convertible<T, Scalar>::value &&
900 std::is_same<
typename internal::traits<Derived>::XprKind, ArrayXpr>::value,
902 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
void _init1(
const Index& val0) {
903 Base::setConstant(val0);
906 template <
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
907 friend struct internal::matrix_swap_impl;
910#ifndef EIGEN_PARSED_BY_DOXYGEN
915 template <
typename OtherDerived>
916 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void swap(DenseBase<OtherDerived>& other) {
917 enum {SwapPointers = std::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime == Dynamic};
918 internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.derived());
924 template <
typename OtherDerived>
925 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void swap(DenseBase<OtherDerived>
const& other) {
926 Base::swap(other.derived());
929 enum {IsPlainObjectBase = 1};
934 template <
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
935 friend class Eigen::Map;
936 friend class Eigen::Map<Derived,
Unaligned>;
937 friend class Eigen::Map<const Derived,
Unaligned>;
938#if EIGEN_MAX_ALIGN_BYTES > 0
941 friend class Eigen::Map<Derived, AlignedMax>;
942 friend class Eigen::Map<const Derived, AlignedMax>;
948template <
typename Derived,
typename OtherDerived,
bool IsVector>
949struct conservative_resize_like_impl {
951 static constexpr bool IsRelocatable =
952 Derived::MaxSizeAtCompileTime != Dynamic || std::is_trivially_copyable<typename Derived::Scalar>::value;
953#ifdef EIGEN_INITIALIZE_COEFFS
956 static constexpr bool MustInitializeAppended =
true;
958 static constexpr bool MustInitializeAppended =
false;
960 static void run(DenseBase<Derived>& _this, Index rows, Index cols) {
961 if (_this.rows() == rows && _this.cols() == cols)
return;
962 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
964 EIGEN_IF_CONSTEXPR (IsRelocatable) {
965 if (((Derived::IsRowMajor && _this.cols() == cols) ||
966 (!Derived::IsRowMajor && _this.rows() == rows)) &&
967 !(MustInitializeAppended && (Derived::IsRowMajor ? rows > _this.rows() : cols > _this.cols()))) {
968#ifndef EIGEN_NO_DEBUG
969 internal::check_rows_cols_for_overflow<Derived::MaxSizeAtCompileTime, Derived::MaxRowsAtCompileTime,
970 Derived::MaxColsAtCompileTime>::run(rows, cols);
972 _this.derived().m_storage.conservativeResize(rows * cols, rows, cols);
978 Derived tmp(rows, cols);
979 const Index common_rows = numext::mini(rows, _this.rows());
980 const Index common_cols = numext::mini(cols, _this.cols());
981 tmp.block(0, 0, common_rows, common_cols) = _this.block(0, 0, common_rows, common_cols);
982 _this.derived().swap(tmp);
985 static void run(DenseBase<Derived>& _this,
const DenseBase<OtherDerived>& other) {
986 if (_this.rows() == other.rows() && _this.cols() == other.cols())
return;
993 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
994 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(OtherDerived)
996 EIGEN_IF_CONSTEXPR (IsRelocatable) {
997 if ((Derived::IsRowMajor && _this.cols() == other.cols()) ||
998 (!Derived::IsRowMajor &&
999 _this.rows() == other.rows()))
1001 const Index new_rows = other.rows() - _this.rows();
1002 const Index new_cols = other.cols() - _this.cols();
1003 _this.derived().m_storage.conservativeResize(other.size(), other.rows(), other.cols());
1005 _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows);
1006 else if (new_cols > 0)
1007 _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols);
1014 const Index common_rows = numext::mini(tmp.rows(), _this.rows());
1015 const Index common_cols = numext::mini(tmp.cols(), _this.cols());
1016 tmp.block(0, 0, common_rows, common_cols) = _this.block(0, 0, common_rows, common_cols);
1017 _this.derived().swap(tmp);
1022template <
typename Derived,
typename OtherDerived>
1023struct conservative_resize_like_impl<Derived, OtherDerived, true>
1024 : conservative_resize_like_impl<Derived, OtherDerived, false> {
1025 using Base = conservative_resize_like_impl<Derived, OtherDerived, false>;
1026 using Base::IsRelocatable;
1027 using Base::MustInitializeAppended;
1029 static void run(DenseBase<Derived>& _this, Index rows, Index cols) {
1030 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
1031 const Index size = Derived::RowsAtCompileTime == 1 ? cols : rows;
1032 eigen_assert((Derived::RowsAtCompileTime == 1 ? rows == 1 : cols == 1) &&
1033 "Invalid sizes when resizing a vector.");
1037 static void run(DenseBase<Derived>& _this, Index size) {
1038 eigen_assert(size >= 0 &&
"Invalid sizes when resizing a vector.");
1039 if (_this.size() == size)
return;
1040 const Index new_rows = Derived::RowsAtCompileTime == 1 ? 1 : size;
1041 const Index new_cols = Derived::RowsAtCompileTime == 1 ? size : 1;
1042 EIGEN_IF_CONSTEXPR (IsRelocatable) {
1043 if (!(MustInitializeAppended && size > _this.size())) {
1044 _this.derived().m_storage.conservativeResize(size, new_rows, new_cols);
1048 Base::run(_this.derived(), new_rows, new_cols);
1051 static void run(DenseBase<Derived>& _this,
const DenseBase<OtherDerived>& other) {
1052 if (_this.rows() == other.rows() && _this.cols() == other.cols())
return;
1054 const Index num_new_elements = other.size() - _this.size();
1056 const Index new_rows = Derived::RowsAtCompileTime == 1 ? 1 : other.size();
1057 const Index new_cols = Derived::RowsAtCompileTime == 1 ? other.size() : 1;
1058 EIGEN_IF_CONSTEXPR (IsRelocatable)
1059 _this.derived().m_storage.conservativeResize(other.size(), new_rows, new_cols);
1061 Base::run(_this.derived(), new_rows, new_cols);
1063 if (num_new_elements > 0) _this.tail(num_new_elements) = other.tail(num_new_elements);
1067template <
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
1068struct matrix_swap_impl {
1069 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE
void run(MatrixTypeA& a, MatrixTypeB& b) { a.base().swap(b); }
1072template <
typename MatrixTypeA,
typename MatrixTypeB>
1073struct matrix_swap_impl<MatrixTypeA, MatrixTypeB, true> {
1074 EIGEN_DEVICE_FUNC
static inline void run(MatrixTypeA& a, MatrixTypeB& b) {
1075 static_cast<typename MatrixTypeA::Base&
>(a).m_storage.swap(
static_cast<typename MatrixTypeB::Base&
>(b).m_storage);