202 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Scalar&
coeffRef(
Index index) {
return m_storage.data()[index]; }
206 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr const Scalar&
coeffRef(
Index rowId,
Index colId)
const {
208 return m_storage.data()[colId + rowId * m_storage.cols()];
210 return m_storage.data()[rowId + colId * m_storage.rows()];
215 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr const Scalar&
coeffRef(
Index index)
const {
216 return m_storage.data()[index];
220 template <
int LoadMode>
221 EIGEN_STRONG_INLINE PacketScalar packet(
Index rowId,
Index colId)
const {
222 return internal::ploadt<PacketScalar, LoadMode>(
223 m_storage.data() + (Flags &
RowMajorBit ? colId + rowId * m_storage.cols() : rowId + colId * m_storage.rows()));
227 template <
int LoadMode>
228 EIGEN_STRONG_INLINE PacketScalar packet(Index index)
const {
229 return internal::ploadt<PacketScalar, LoadMode>(m_storage.data() + index);
233 template <
int StoreMode>
234 EIGEN_STRONG_INLINE
void writePacket(
Index rowId,
Index colId,
const PacketScalar& val) {
235 internal::pstoret<Scalar, PacketScalar, StoreMode>(
236 m_storage.data() + (Flags &
RowMajorBit ? colId + rowId * m_storage.cols() : rowId + colId * m_storage.rows()),
241 template <
int StoreMode>
242 EIGEN_STRONG_INLINE
void writePacket(
Index index,
const PacketScalar& val) {
243 internal::pstoret<Scalar, PacketScalar, StoreMode>(m_storage.data() + index, val);
247 EIGEN_DEVICE_FUNC
constexpr const Scalar*
data()
const {
return m_storage.data(); }
250 EIGEN_DEVICE_FUNC
constexpr Scalar*
data() {
return m_storage.data(); }
269 eigen_assert(internal::check_implication(RowsAtCompileTime !=
Dynamic, rows == RowsAtCompileTime) &&
270 internal::check_implication(ColsAtCompileTime !=
Dynamic, cols == ColsAtCompileTime) &&
271 internal::check_implication(RowsAtCompileTime ==
Dynamic && MaxRowsAtCompileTime !=
Dynamic,
272 rows <= MaxRowsAtCompileTime) &&
273 internal::check_implication(ColsAtCompileTime ==
Dynamic && MaxColsAtCompileTime !=
Dynamic,
274 cols <= MaxColsAtCompileTime) &&
275 rows >= 0 && cols >= 0 &&
"Invalid sizes when resizing a matrix or array.");
276#ifndef EIGEN_NO_DEBUG
277 internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime>::run(rows,
280#ifdef EIGEN_INITIALIZE_COEFFS
281 Index size = rows * cols;
282 bool size_changed = size != this->size();
283 m_storage.resize(size, rows, cols);
284 if (size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
286 m_storage.resize(rows * cols, rows, cols);
302 EIGEN_STATIC_ASSERT_VECTOR_ONLY(PlainObjectBase)
303 eigen_assert(((SizeAtCompileTime ==
Dynamic && (MaxSizeAtCompileTime ==
Dynamic || size <= MaxSizeAtCompileTime)) ||
304 SizeAtCompileTime == size) &&
306#ifdef EIGEN_INITIALIZE_COEFFS
307 bool size_changed = size != this->size();
309 if (RowsAtCompileTime == 1)
310 m_storage.resize(size, 1, size);
312 m_storage.resize(size, size, 1);
313#ifdef EIGEN_INITIALIZE_COEFFS
314 if (size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
345 template <
typename OtherDerived>
347 const OtherDerived& other = _other.
derived();
348#ifndef EIGEN_NO_DEBUG
349 internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime>::run(
350 other.rows(), other.cols());
352 const Index othersize = other.rows() * other.cols();
353 if (RowsAtCompileTime == 1) {
354 eigen_assert(other.rows() == 1 || other.cols() == 1);
356 }
else if (ColsAtCompileTime == 1) {
357 eigen_assert(other.rows() == 1 || other.cols() == 1);
360 resize(other.rows(), other.cols());
373 internal::conservative_resize_like_impl<Derived>::run(*
this, rows, cols);
409 internal::conservative_resize_like_impl<Derived>::run(*
this, size);
421 template <
typename OtherDerived>
423 internal::conservative_resize_like_impl<Derived, OtherDerived>::run(*
this, other);
429 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Derived&
operator=(
const PlainObjectBase& other) {
434 template <
typename OtherDerived>
436 _resize_to_match(other);
437 return Base::lazyAssign(other.derived());
440 template <
typename OtherDerived>
441 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
operator=(
const ReturnByValue<OtherDerived>& func) {
442 resize(func.rows(), func.cols());
443 return Base::operator=(func);
449 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr PlainObjectBase() =
default;
451 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr PlainObjectBase(PlainObjectBase&&) =
default;
453 EIGEN_DEVICE_FUNC
constexpr PlainObjectBase&
operator=(PlainObjectBase&& other)
noexcept {
454 m_storage = std::move(other.m_storage);
459 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr PlainObjectBase(
const PlainObjectBase&) =
default;
460 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase(
Index size,
Index rows,
Index cols)
461 : m_storage(size, rows, cols) {}
472 template <
typename... ArgTypes>
473 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
PlainObjectBase(
const Scalar& a0,
const Scalar& a1,
const Scalar& a2,
474 const Scalar& a3,
const ArgTypes&... args)
476 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase,
sizeof...(args) + 4);
477 m_storage.data()[0] = a0;
478 m_storage.data()[1] = a1;
479 m_storage.data()[2] = a2;
480 m_storage.data()[3] = a3;
482 auto x = {(m_storage.data()[i++] = args, 0)...};
483 static_cast<void>(x);
490 const std::initializer_list<std::initializer_list<Scalar>>& list)
492 size_t list_size = 0;
493 if (list.begin() != list.end()) {
494 list_size = list.begin()->size();
498 if (ColsAtCompileTime == 1 && list.size() == 1) {
499 eigen_assert(list_size == static_cast<size_t>(RowsAtCompileTime) || RowsAtCompileTime == Dynamic);
500 resize(list_size, ColsAtCompileTime);
501 if (list.begin()->begin() != nullptr) {
503 for (const Scalar& e : *list.begin()) {
504 coeffRef(index++) = e;
508 eigen_assert(list.size() ==
static_cast<size_t>(RowsAtCompileTime) || RowsAtCompileTime ==
Dynamic);
509 eigen_assert(list_size ==
static_cast<size_t>(ColsAtCompileTime) || ColsAtCompileTime ==
Dynamic);
510 resize(list.size(), list_size);
513 for (
const std::initializer_list<Scalar>& row : list) {
514 eigen_assert(list_size == row.size());
516 for (
const Scalar& e : row) {
526 template <
typename OtherDerived>
533 template <
typename OtherDerived>
539 template <
typename OtherDerived>
540 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
PlainObjectBase(
const ReturnByValue<OtherDerived>& other) {
542 resize(other.rows(), other.cols());
543 other.evalTo(this->derived());
550 template <
typename OtherDerived>
552 _resize_to_match(other);
553 Base::operator=(other.
derived());
554 return this->derived();
569 static inline ConstMapType
Map(
const Scalar* data) {
return ConstMapType(data); }
570 static inline MapType Map(Scalar* data) {
return MapType(data); }
571 static inline ConstMapType
Map(
const Scalar* data,
Index size) {
return ConstMapType(data, size); }
572 static inline MapType
Map(
Scalar* data,
Index size) {
return MapType(data, size); }
573 static inline ConstMapType
Map(
const Scalar* data,
Index rows,
Index cols) {
return ConstMapType(data, rows, cols); }
574 static inline MapType
Map(
Scalar* data,
Index rows,
Index cols) {
return MapType(data, rows, cols); }
576 static inline ConstAlignedMapType MapAligned(
const Scalar* data) {
return ConstAlignedMapType(data); }
577 static inline AlignedMapType MapAligned(
Scalar* data) {
return AlignedMapType(data); }
578 static inline ConstAlignedMapType MapAligned(
const Scalar* data,
Index size) {
579 return ConstAlignedMapType(data, size);
581 static inline AlignedMapType MapAligned(
Scalar* data,
Index size) {
return AlignedMapType(data, size); }
582 static inline ConstAlignedMapType MapAligned(
const Scalar* data,
Index rows,
Index cols) {
583 return ConstAlignedMapType(data, rows, cols);
585 static inline AlignedMapType MapAligned(
Scalar* data,
Index rows,
Index cols) {
586 return AlignedMapType(data, rows, cols);
589 template <
int Outer,
int Inner>
590 static inline typename StridedConstMapType<Stride<Outer, Inner>>::type
Map(
const Scalar* data,
592 return typename StridedConstMapType<Stride<Outer, Inner>>::type(data, stride);
594 template <
int Outer,
int Inner>
595 static inline typename StridedMapType<Stride<Outer, Inner>>::type
Map(
Scalar* data,
597 return typename StridedMapType<Stride<Outer, Inner>>::type(data, stride);
599 template <
int Outer,
int Inner>
600 static inline typename StridedConstMapType<Stride<Outer, Inner>>::type
Map(
const Scalar* data,
Index size,
602 return typename StridedConstMapType<Stride<Outer, Inner>>::type(data, size, stride);
604 template <
int Outer,
int Inner>
605 static inline typename StridedMapType<Stride<Outer, Inner>>::type
Map(
Scalar* data,
Index size,
607 return typename StridedMapType<Stride<Outer, Inner>>::type(data, size, stride);
609 template <
int Outer,
int Inner>
610 static inline typename StridedConstMapType<Stride<Outer, Inner>>::type
Map(
const Scalar* data,
Index rows,
Index cols,
612 return typename StridedConstMapType<Stride<Outer, Inner>>::type(data, rows, cols, stride);
614 template <
int Outer,
int Inner>
615 static inline typename StridedMapType<Stride<Outer, Inner>>::type
Map(
Scalar* data,
Index rows,
Index cols,
617 return typename StridedMapType<Stride<Outer, Inner>>::type(data, rows, cols, stride);
620 template <
int Outer,
int Inner>
621 static inline typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
623 return typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type(data, stride);
625 template <
int Outer,
int Inner>
626 static inline typename StridedAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
628 return typename StridedAlignedMapType<Stride<Outer, Inner>>::type(data, stride);
630 template <
int Outer,
int Inner>
631 static inline typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
633 return typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type(data, size, stride);
635 template <
int Outer,
int Inner>
636 static inline typename StridedAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
638 return typename StridedAlignedMapType<Stride<Outer, Inner>>::type(data, size, stride);
640 template <
int Outer,
int Inner>
641 static inline typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
643 return typename StridedConstAlignedMapType<Stride<Outer, Inner>>::type(data, rows, cols, stride);
645 template <
int Outer,
int Inner>
646 static inline typename StridedAlignedMapType<Stride<Outer, Inner>>::type MapAligned(
648 return typename StridedAlignedMapType<Stride<Outer, Inner>>::type(data, rows, cols, stride);
652 using Base::setConstant;
670 using Base::setRandom;
676#ifdef EIGEN_PLAINOBJECTBASE_PLUGIN
677#include EIGEN_PLAINOBJECTBASE_PLUGIN
688 template <
typename OtherDerived>
690#ifdef EIGEN_NO_AUTOMATIC_RESIZING
691 eigen_assert((this->size() == 0 || (IsVectorAtCompileTime ? (this->size() == other.
size())
692 : (rows() == other.
rows() && cols() == other.
cols()))) &&
693 "Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined");
694 EIGEN_ONLY_USED_FOR_DEBUG(other);
716 template <
typename OtherDerived>
718 internal::call_assignment(this->derived(), other.derived());
719 return this->derived();
727 template <
typename OtherDerived>
734 internal::call_assignment_no_alias(this->derived(), other.derived(),
735 internal::assign_op<Scalar, typename OtherDerived::Scalar>());
736 return this->derived();
739 template <
typename T0,
typename T1>
740 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init2(Index rows, Index cols,
741 std::enable_if_t<Base::SizeAtCompileTime != 2, T0>* = 0) {
742 EIGEN_STATIC_ASSERT(internal::is_valid_index_type<T0>::value && internal::is_valid_index_type<T1>::value,
743 T0 AND T1 MUST BE INTEGER TYPES)
747 template <
typename T0,
typename T1>
748 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init2(
const T0& val0,
const T1& val1,
749 std::enable_if_t<Base::SizeAtCompileTime == 2, T0>* = 0) {
751 m_storage.data()[0] =
Scalar(val0);
752 m_storage.data()[1] =
Scalar(val1);
755 template <typename T0, typename T1>
756 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init2(
758 std::enable_if_t<(!internal::is_same<
Index,
Scalar>::value) && (internal::is_same<T0,
Index>::value) &&
759 (internal::is_same<T1,
Index>::value) && Base::SizeAtCompileTime == 2,
762 m_storage.data()[0] =
Scalar(val0);
763 m_storage.data()[1] =
Scalar(val1);
768 template <typename T>
769 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init1(
771 std::enable_if_t<(Base::SizeAtCompileTime != 1 || !internal::is_convertible<T,
Scalar>::value) &&
772 ((!internal::is_same<typename internal::traits<Derived>::XprKind,
ArrayXpr>::value ||
773 Base::SizeAtCompileTime ==
Dynamic)),
776 const bool is_integer_alike = internal::is_valid_index_type<T>::value;
777 EIGEN_UNUSED_VARIABLE(is_integer_alike);
778 EIGEN_STATIC_ASSERT(is_integer_alike, FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
784 template <
typename T>
785 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init1(
787 std::enable_if_t<Base::SizeAtCompileTime == 1 && internal::is_convertible<T, Scalar>::value, T>* = 0) {
789 m_storage.data()[0] = val0;
794 template <typename T>
795 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init1(
797 std::enable_if_t<(!internal::is_same<
Index,
Scalar>::value) && (internal::is_same<
Index, T>::value) &&
798 Base::SizeAtCompileTime == 1 && internal::is_convertible<T,
Scalar>::value,
801 m_storage.data()[0] =
Scalar(val0);
805 template <typename T>
806 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init1(const
Scalar* data) {
807 this->_set_noalias(ConstMapType(data));
811 template <
typename T,
typename OtherDerived>
813 this->_set_noalias(other);
817 template <
typename T>
818 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init1(
const Derived& other) {
819 this->_set_noalias(other);
823 template <
typename T,
typename OtherDerived>
825 this->derived() = other;
828 template <
typename T,
typename OtherDerived>
829 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init1(
const ReturnByValue<OtherDerived>& other) {
830 resize(other.rows(), other.cols());
831 other.evalTo(this->derived());
834 template <
typename T,
typename OtherDerived,
int ColsAtCompileTime>
840 template <
typename T>
841 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init1(
843 std::enable_if_t<Base::SizeAtCompileTime !=
Dynamic && Base::SizeAtCompileTime != 1 &&
844 internal::is_convertible<T, Scalar>::value &&
845 internal::is_same<
typename internal::traits<Derived>::XprKind,
ArrayXpr>::value,
847 Base::setConstant(val0);
851 template <
typename T>
852 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void _init1(
854 std::enable_if_t<(!internal::is_same<Index, Scalar>::value) && (internal::is_same<Index, T>::value) &&
855 Base::SizeAtCompileTime !=
Dynamic && Base::SizeAtCompileTime != 1 &&
856 internal::is_convertible<T, Scalar>::value &&
857 internal::is_same<
typename internal::traits<Derived>::XprKind,
ArrayXpr>::value,
859 Base::setConstant(val0);
862 template <
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
863 friend struct internal::matrix_swap_impl;
866#ifndef EIGEN_PARSED_BY_DOXYGEN
871 template <
typename OtherDerived>
873 enum {SwapPointers = internal::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime ==
Dynamic};
874 internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.derived());
880 template <
typename OtherDerived>
882 Base::swap(other.derived());
885 enum {IsPlainObjectBase = 1};
890 template <
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
891 friend class Eigen::Map;
892 friend class Eigen::Map<Derived,
Unaligned>;
893 friend class Eigen::Map<const Derived,
Unaligned>;
894#if EIGEN_MAX_ALIGN_BYTES > 0
897 friend class Eigen::Map<Derived, AlignedMax>;
898 friend class Eigen::Map<const Derived, AlignedMax>;
904template <
typename Derived,
typename OtherDerived,
bool IsVector>
905struct conservative_resize_like_impl {
906 static constexpr bool IsRelocatable = std::is_trivially_copyable<typename Derived::Scalar>::value;
907 static void run(DenseBase<Derived>& _this,
Index rows,
Index cols) {
908 if (_this.rows() == rows && _this.cols() == cols)
return;
909 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
912 ((Derived::IsRowMajor && _this.cols() == cols) ||
913 (!Derived::IsRowMajor && _this.rows() == rows)))
915#ifndef EIGEN_NO_DEBUG
916 internal::check_rows_cols_for_overflow<Derived::MaxSizeAtCompileTime, Derived::MaxRowsAtCompileTime,
917 Derived::MaxColsAtCompileTime>::run(rows, cols);
919 _this.derived().m_storage.conservativeResize(rows * cols, rows, cols);
922 Derived tmp(rows, cols);
923 const Index common_rows = numext::mini(rows, _this.rows());
924 const Index common_cols = numext::mini(cols, _this.cols());
925 tmp.block(0, 0, common_rows, common_cols) = _this.block(0, 0, common_rows, common_cols);
926 _this.derived().swap(tmp);
930 static void run(DenseBase<Derived>& _this,
const DenseBase<OtherDerived>& other) {
931 if (_this.rows() == other.rows() && _this.cols() == other.cols())
return;
938 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived)
939 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(OtherDerived)
942 ((Derived::IsRowMajor && _this.cols() == other.cols()) ||
943 (!Derived::IsRowMajor &&
944 _this.rows() == other.rows())))
946 const Index new_rows = other.rows() - _this.rows();
947 const Index new_cols = other.cols() - _this.cols();
948 _this.derived().m_storage.conservativeResize(other.size(), other.rows(), other.cols());
950 _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows);
951 else if (new_cols > 0)
952 _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols);
956 const Index common_rows = numext::mini(tmp.rows(), _this.rows());
957 const Index common_cols = numext::mini(tmp.cols(), _this.cols());
958 tmp.block(0, 0, common_rows, common_cols) = _this.block(0, 0, common_rows, common_cols);
959 _this.derived().swap(tmp);
966template <
typename Derived,
typename OtherDerived>
967struct conservative_resize_like_impl<Derived, OtherDerived, true>
968 : conservative_resize_like_impl<Derived, OtherDerived, false> {
969 typedef conservative_resize_like_impl<Derived, OtherDerived, false> Base;
970 using Base::IsRelocatable;
973 static void run(DenseBase<Derived>& _this,
Index size) {
974 const Index new_rows = Derived::RowsAtCompileTime == 1 ? 1 : size;
975 const Index new_cols = Derived::RowsAtCompileTime == 1 ? size : 1;
977 _this.derived().m_storage.conservativeResize(size, new_rows, new_cols);
979 Base::run(_this.derived(), new_rows, new_cols);
982 static void run(DenseBase<Derived>& _this,
const DenseBase<OtherDerived>& other) {
983 if (_this.rows() == other.rows() && _this.cols() == other.cols())
return;
985 const Index num_new_elements = other.size() - _this.size();
987 const Index new_rows = Derived::RowsAtCompileTime == 1 ? 1 : other.rows();
988 const Index new_cols = Derived::RowsAtCompileTime == 1 ? other.cols() : 1;
990 _this.derived().m_storage.conservativeResize(other.size(), new_rows, new_cols);
992 Base::run(_this.derived(), new_rows, new_cols);
994 if (num_new_elements > 0) _this.tail(num_new_elements) = other.tail(num_new_elements);
998template <
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
999struct matrix_swap_impl {
1000 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE
void run(MatrixTypeA& a, MatrixTypeB& b) { a.base().swap(b); }
1003template <
typename MatrixTypeA,
typename MatrixTypeB>
1004struct matrix_swap_impl<MatrixTypeA, MatrixTypeB, true> {
1005 EIGEN_DEVICE_FUNC
static inline void run(MatrixTypeA& a, MatrixTypeB& b) {
1006 static_cast<typename MatrixTypeA::Base&
>(a).m_storage.swap(
static_cast<typename MatrixTypeB::Base&
>(b).m_storage);