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 \
17 for (Index i = 0; i < base().size(); ++i) coeffRef(i) = Scalar(0);
18#elif defined(EIGEN_INITIALIZE_MATRICES_BY_NAN)
19#define EIGEN_INITIALIZE_COEFFS
20#define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED \
21 for (Index i = 0; i < base().size(); ++i) coeffRef(i) = std::numeric_limits<Scalar>::quiet_NaN();
23#undef EIGEN_INITIALIZE_COEFFS
24#define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
28#include "./InternalHeaderCheck.h"
35template <
int MaxSizeAtCompileTime,
int MaxRowsAtCompileTime,
int MaxColsAtCompileTime>
36struct check_rows_cols_for_overflow {
37 EIGEN_STATIC_ASSERT(MaxRowsAtCompileTime* MaxColsAtCompileTime == MaxSizeAtCompileTime,
38 YOU MADE A PROGRAMMING MISTAKE)
39 template <
typename Index>
40 EIGEN_DEVICE_FUNC
static EIGEN_ALWAYS_INLINE
constexpr void run(
Index,
Index) {}
43template <
int MaxRowsAtCompileTime>
44struct check_rows_cols_for_overflow<
Dynamic, MaxRowsAtCompileTime,
Dynamic> {
45 template <
typename Index>
46 EIGEN_DEVICE_FUNC
static EIGEN_ALWAYS_INLINE
constexpr void run(
Index,
Index cols) {
47 constexpr Index MaxIndex = NumTraits<Index>::highest();
48 bool error = cols > (MaxIndex / MaxRowsAtCompileTime);
49 if (error) throw_std_bad_alloc();
53template <
int MaxColsAtCompileTime>
54struct check_rows_cols_for_overflow<
Dynamic,
Dynamic, MaxColsAtCompileTime> {
55 template <
typename Index>
56 EIGEN_DEVICE_FUNC
static EIGEN_ALWAYS_INLINE
constexpr void run(
Index rows,
Index) {
57 constexpr Index MaxIndex = NumTraits<Index>::highest();
58 bool error = rows > (MaxIndex / MaxColsAtCompileTime);
59 if (error) throw_std_bad_alloc();
65 template <
typename Index>
66 EIGEN_DEVICE_FUNC
static EIGEN_ALWAYS_INLINE
constexpr void run(
Index rows,
Index cols) {
67 constexpr Index MaxIndex = NumTraits<Index>::highest();
68 bool error = cols == 0 ? false : (rows > (MaxIndex / cols));
69 if (error) throw_std_bad_alloc();
74template <
typename Derived,
typename OtherDerived = Derived,
75 bool IsVector = bool(Derived::IsVectorAtCompileTime) && bool(OtherDerived::IsVectorAtCompileTime)>
76struct conservative_resize_like_impl;
78template <
typename MatrixTypeA,
typename MatrixTypeB,
bool SwapPo
inters>
79struct matrix_swap_impl;
94template <
typename Derived>
95class PlainObjectBase :
public internal::dense_xpr_base<Derived>::type {
97 enum { Options = internal::traits<Derived>::Options };
98 typedef typename internal::dense_xpr_base<Derived>::type Base;
100 typedef typename internal::traits<Derived>::StorageKind StorageKind;
101 typedef typename internal::traits<Derived>::Scalar Scalar;
103 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
104 typedef typename NumTraits<Scalar>::Real RealScalar;
105 typedef Derived DenseType;
107 using Base::ColsAtCompileTime;
109 using Base::IsVectorAtCompileTime;
110 using Base::MaxColsAtCompileTime;
111 using Base::MaxRowsAtCompileTime;
112 using Base::MaxSizeAtCompileTime;
113 using Base::RowsAtCompileTime;
114 using Base::SizeAtCompileTime;
120 template <
typename Str
ideType>
121 struct StridedMapType {
124 template <
typename Str
ideType>
125 struct StridedConstMapType {
128 template <
typename Str
ideType>
129 struct StridedAlignedMapType {
132 template <
typename Str
ideType>
133 struct StridedConstAlignedMapType {
138 DenseStorage<Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options> m_storage;
141 enum { NeedsToAlign = (SizeAtCompileTime !=
Dynamic) && (internal::traits<Derived>::Alignment > 0) };
142 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
144 EIGEN_STATIC_ASSERT(internal::check_implication(MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1,
146 INVALID_MATRIX_TEMPLATE_PARAMETERS)
147 EIGEN_STATIC_ASSERT(internal::check_implication(MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1,
149 INVALID_MATRIX_TEMPLATE_PARAMETERS)
150 EIGEN_STATIC_ASSERT((RowsAtCompileTime ==
Dynamic) || (RowsAtCompileTime >= 0), INVALID_MATRIX_TEMPLATE_PARAMETERS)
151 EIGEN_STATIC_ASSERT((ColsAtCompileTime ==
Dynamic) || (ColsAtCompileTime >= 0), INVALID_MATRIX_TEMPLATE_PARAMETERS)
152 EIGEN_STATIC_ASSERT((MaxRowsAtCompileTime ==
Dynamic) || (MaxRowsAtCompileTime >= 0),
153 INVALID_MATRIX_TEMPLATE_PARAMETERS)
154 EIGEN_STATIC_ASSERT((MaxColsAtCompileTime ==
Dynamic) || (MaxColsAtCompileTime >= 0),
155 INVALID_MATRIX_TEMPLATE_PARAMETERS)
156 EIGEN_STATIC_ASSERT((MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime ==
Dynamic),
157 INVALID_MATRIX_TEMPLATE_PARAMETERS)
158 EIGEN_STATIC_ASSERT((MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime ==
Dynamic),
159 INVALID_MATRIX_TEMPLATE_PARAMETERS)
160 EIGEN_STATIC_ASSERT(((Options & (
DontAlign |
RowMajor)) == Options), INVALID_MATRIX_TEMPLATE_PARAMETERS)
162 EIGEN_DEVICE_FUNC Base& base() {
return *
static_cast<Base*
>(
this); }
163 EIGEN_DEVICE_FUNC
const Base& base()
const {
return *
static_cast<const Base*
>(
this); }
165 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Index rows()
const noexcept {
return m_storage.rows(); }
166 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr Index cols()
const noexcept {
return m_storage.cols(); }
172 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr const Scalar&
coeff(
Index rowId,
Index colId)
const {
174 return m_storage.data()[colId + rowId * m_storage.cols()];
176 return m_storage.data()[rowId + colId * m_storage.rows()];
183 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr const Scalar&
coeff(
Index index)
const {
184 return m_storage.data()[index];
193 return m_storage.data()[colId + rowId * m_storage.cols()];
195 return m_storage.data()[rowId + colId * m_storage.rows()];
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);
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:44
constexpr Derived & derived()
Definition EigenBase.h:49
A matrix or vector expression mapping an existing array of data.
Definition Map.h:96
Dense storage base class for matrices and arrays.
Definition PlainObjectBase.h:95
constexpr Scalar & coeffRef(Index index)
Definition PlainObjectBase.h:202
constexpr PlainObjectBase & operator=(PlainObjectBase &&other) noexcept
Move assignment operator.
Definition PlainObjectBase.h:453
constexpr const Scalar & coeff(Index index) const
Definition PlainObjectBase.h:183
PlainObjectBase(const ReturnByValue< OtherDerived > &other)
Copy constructor with in-place evaluation.
Definition PlainObjectBase.h:540
constexpr void resize(NoChange_t, Index cols)
Definition PlainObjectBase.h:326
Derived & lazyAssign(const DenseBase< OtherDerived > &other)
Definition PlainObjectBase.h:435
constexpr Scalar * data()
Definition PlainObjectBase.h:250
constexpr void resize(Index size)
Definition PlainObjectBase.h:301
Derived & setOnes(NoChange_t, Index cols)
Definition CwiseNullaryOp.h:747
void conservativeResizeLike(const DenseBase< OtherDerived > &other)
Definition PlainObjectBase.h:422
Derived & setConstant(NoChange_t, Index cols, const Scalar &val)
Definition CwiseNullaryOp.h:395
constexpr PlainObjectBase(const std::initializer_list< std::initializer_list< Scalar > > &list)
Constructs a Matrix or Array and initializes it by elements given by an initializer list of initializ...
Definition PlainObjectBase.h:489
PlainObjectBase(const Scalar &a0, const Scalar &a1, const Scalar &a2, const Scalar &a3, const ArgTypes &... args)
Construct a row of column vector with fixed size from an arbitrary number of coefficients.
Definition PlainObjectBase.h:473
Derived & setRandom(Index size)
Definition Random.h:147
constexpr const Scalar & coeff(Index rowId, Index colId) const
Definition PlainObjectBase.h:172
Derived & setRandom(NoChange_t, Index cols)
Definition Random.h:185
constexpr Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition PlainObjectBase.h:717
constexpr PlainObjectBase(PlainObjectBase &&)=default
Move constructor.
void conservativeResize(Index rows, Index cols)
Definition PlainObjectBase.h:372
Derived & setZero(Index rows, Index cols)
Definition CwiseNullaryOp.h:583
PlainObjectBase(const DenseBase< OtherDerived > &other)
Definition PlainObjectBase.h:527
void conservativeResize(Index size)
Definition PlainObjectBase.h:408
constexpr const Scalar & coeffRef(Index index) const
Definition PlainObjectBase.h:215
Derived & setOnes(Index size)
Definition CwiseNullaryOp.h:706
Derived & setRandom(Index rows, Index cols)
Definition Random.h:168
constexpr const Scalar & coeffRef(Index rowId, Index colId) const
Definition PlainObjectBase.h:206
void conservativeResize(Index rows, NoChange_t)
Definition PlainObjectBase.h:383
PlainObjectBase(const EigenBase< OtherDerived > &other)
Definition PlainObjectBase.h:534
constexpr void resize(Index rows, NoChange_t)
Definition PlainObjectBase.h:336
void resizeLike(const EigenBase< OtherDerived > &_other)
Definition PlainObjectBase.h:346
Derived & setConstant(Index size, const Scalar &val)
Definition CwiseNullaryOp.h:363
Derived & setOnes(Index rows, NoChange_t)
Definition CwiseNullaryOp.h:735
constexpr PlainObjectBase(const PlainObjectBase &)=default
constexpr const Scalar * data() const
Definition PlainObjectBase.h:247
Derived & setZero(Index size)
Definition CwiseNullaryOp.h:567
Derived & setOnes(Index rows, Index cols)
Definition CwiseNullaryOp.h:722
constexpr Derived & operator=(const PlainObjectBase &other)
Definition PlainObjectBase.h:429
Derived & setConstant(Index rows, NoChange_t, const Scalar &val)
Definition CwiseNullaryOp.h:408
Derived & setRandom(Index rows, NoChange_t)
Definition Random.h:201
constexpr Scalar & coeffRef(Index rowId, Index colId)
Definition PlainObjectBase.h:191
constexpr void resize(Index rows, Index cols)
Definition PlainObjectBase.h:268
Derived & setZero(Index rows, NoChange_t)
Definition CwiseNullaryOp.h:608
Derived & setZero(NoChange_t, Index cols)
Definition CwiseNullaryOp.h:596
Derived & setConstant(Index rows, Index cols, const Scalar &val)
Definition CwiseNullaryOp.h:381
Derived & operator=(const EigenBase< OtherDerived > &other)
Copies the generic expression other into *this.
Definition PlainObjectBase.h:551
void conservativeResize(NoChange_t, Index cols)
Definition PlainObjectBase.h:395
Common base class for compact rotation representations.
Definition RotationBase.h:32
Holds strides information for Map.
Definition Stride.h:55
@ Unaligned
Definition Constants.h:235
@ DontAlign
Definition Constants.h:324
@ RowMajor
Definition Constants.h:320
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
std::enable_if_t< std::is_base_of< DenseBase< std::decay_t< DerivedA > >, std::decay_t< DerivedA > >::value &&std::is_base_of< DenseBase< std::decay_t< DerivedB > >, std::decay_t< DerivedB > >::value, void > swap(DerivedA &&a, DerivedB &&b)
Definition DenseBase.h:667
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82
const int Dynamic
Definition Constants.h:25
Definition Constants.h:537
Definition EigenBase.h:33
constexpr Index cols() const noexcept
Definition EigenBase.h:61
constexpr Derived & derived()
Definition EigenBase.h:49
constexpr Index rows() const noexcept
Definition EigenBase.h:59
constexpr Index size() const noexcept
Definition EigenBase.h:64