11 #ifndef EIGEN_XPRHELPER_H 12 #define EIGEN_XPRHELPER_H 15 #include "../InternalHeaderCheck.h" 22 template <
typename IndexType>
23 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
typename make_unsigned<IndexType>::type returnUnsignedIndexValue(
24 const IndexType& idx) {
25 EIGEN_STATIC_ASSERT((NumTraits<IndexType>::IsInteger), THIS FUNCTION IS FOR INTEGER TYPES)
26 eigen_internal_assert(idx >= 0 &&
"Index value is negative and target type is unsigned");
27 using UnsignedType =
typename make_unsigned<IndexType>::type;
28 return static_cast<UnsignedType
>(idx);
31 template <typename IndexDest, typename IndexSrc, bool IndexDestIsInteger = NumTraits<IndexDest>::IsInteger,
32 bool IndexDestIsSigned = NumTraits<IndexDest>::IsSigned,
33 bool IndexSrcIsInteger = NumTraits<IndexSrc>::IsInteger,
34 bool IndexSrcIsSigned = NumTraits<IndexSrc>::IsSigned>
35 struct convert_index_impl {
36 static inline EIGEN_DEVICE_FUNC IndexDest run(
const IndexSrc& idx) {
37 eigen_internal_assert(idx <= NumTraits<IndexDest>::highest() &&
"Index value is too big for target type");
38 return static_cast<IndexDest
>(idx);
41 template <
typename IndexDest,
typename IndexSrc>
42 struct convert_index_impl<IndexDest, IndexSrc, true, true, true, false> {
45 static inline EIGEN_DEVICE_FUNC IndexDest run(
const IndexSrc& idx) {
46 eigen_internal_assert(idx <= returnUnsignedIndexValue(NumTraits<IndexDest>::highest()) &&
47 "Index value is too big for target type");
48 return static_cast<IndexDest
>(idx);
51 template <
typename IndexDest,
typename IndexSrc>
52 struct convert_index_impl<IndexDest, IndexSrc, true, false, true, true> {
55 static inline EIGEN_DEVICE_FUNC IndexDest run(
const IndexSrc& idx) {
56 eigen_internal_assert(returnUnsignedIndexValue(idx) <= NumTraits<IndexDest>::highest() &&
57 "Index value is too big for target type");
58 return static_cast<IndexDest
>(idx);
62 template <
typename IndexDest,
typename IndexSrc>
63 EIGEN_DEVICE_FUNC
inline IndexDest convert_index(
const IndexSrc& idx) {
64 return convert_index_impl<IndexDest, IndexSrc>::run(idx);
69 struct is_valid_index_type {
70 enum { value = internal::is_integral<T>::value || std::is_enum<T>::value };
74 template <
typename RowIndices,
typename ColIndices>
75 struct valid_indexed_view_overload {
77 value = !(internal::is_valid_index_type<RowIndices>::value && internal::is_valid_index_type<ColIndices>::value)
95 template <
typename ExprScalar,
typename T,
bool IsSupported>
96 struct promote_scalar_arg;
98 template <
typename S,
typename T>
99 struct promote_scalar_arg<S, T, true> {
104 template <
typename ExprScalar,
typename T,
typename PromotedType,
105 bool ConvertibleToLiteral = internal::is_convertible<T, PromotedType>::value,
106 bool IsSafe = NumTraits<T>::IsInteger || !NumTraits<PromotedType>::IsInteger>
107 struct promote_scalar_arg_unsupported;
110 template <
typename S,
typename T>
111 struct promote_scalar_arg<S, T, false> : promote_scalar_arg_unsupported<S, T, typename NumTraits<S>::Literal> {};
114 template <
typename S,
typename T,
typename PromotedType>
115 struct promote_scalar_arg_unsupported<S, T, PromotedType, true, true> {
116 typedef PromotedType type;
121 template <
typename ExprScalar,
typename T,
typename PromotedType>
122 struct promote_scalar_arg_unsupported<ExprScalar, T, PromotedType, false, true>
123 : promote_scalar_arg_unsupported<ExprScalar, T, ExprScalar> {};
126 template <
typename S,
typename T,
typename PromotedType,
bool ConvertibleToLiteral>
127 struct promote_scalar_arg_unsupported<S, T, PromotedType, ConvertibleToLiteral, false> {};
130 template <
typename S,
typename T>
131 struct promote_scalar_arg_unsupported<S, T, S, false, true> {};
134 class no_assignment_operator {
136 no_assignment_operator& operator=(
const no_assignment_operator&);
139 EIGEN_DEFAULT_COPY_CONSTRUCTOR(no_assignment_operator)
140 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(no_assignment_operator)
144 template <
typename I1,
typename I2>
145 struct promote_index_type {
146 typedef std::conditional_t<(sizeof(I1) < sizeof(I2)), I2, I1> type;
153 template <
typename T,
int Value>
154 class variable_if_dynamic {
156 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(variable_if_dynamic)
157 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit variable_if_dynamic(T v) {
158 EIGEN_ONLY_USED_FOR_DEBUG(v);
159 eigen_assert(v == T(Value));
161 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE constexpr T value() {
return T(Value); }
162 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr
operator T()
const {
return T(Value); }
163 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T v)
const {
164 EIGEN_ONLY_USED_FOR_DEBUG(v);
165 eigen_assert(v == T(Value));
169 template <
typename T>
170 class variable_if_dynamic<T,
Dynamic> {
174 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit variable_if_dynamic(T value = 0) noexcept : m_value(value) {}
175 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T value()
const {
return m_value; }
176 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
operator T()
const {
return m_value; }
177 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T value) { m_value = value; }
182 template <
typename T,
int Value>
183 class variable_if_dynamicindex {
185 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit variable_if_dynamicindex(T v) {
186 EIGEN_ONLY_USED_FOR_DEBUG(v);
187 eigen_assert(v == T(Value));
189 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE constexpr T value() {
return T(Value); }
190 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T) {}
193 template <
typename T>
196 EIGEN_DEVICE_FUNC variable_if_dynamicindex() { eigen_assert(
false); }
199 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit variable_if_dynamicindex(T value) : m_value(value) {}
200 EIGEN_DEVICE_FUNC T EIGEN_STRONG_INLINE value()
const {
return m_value; }
201 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T value) { m_value = value; }
204 template <
typename T>
205 struct functor_traits {
206 enum { Cost = 10, PacketAccess =
false, IsRepeatable =
false };
210 template <
typename Xpr>
211 struct nested_functor_cost {
212 static constexpr
Index Cost =
static_cast<Index>(functor_traits<Xpr>::Cost);
215 template <
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
216 struct nested_functor_cost<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>> {
217 static constexpr
Index Cost = 1;
220 template <
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
221 struct nested_functor_cost<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>> {
222 static constexpr
Index Cost = 1;
226 template <
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
227 struct nested_functor_cost<Map<PlainObjectType, MapOptions, StrideType>> : nested_functor_cost<PlainObjectType> {};
229 template <
typename Func,
typename Xpr>
230 struct nested_functor_cost<CwiseUnaryOp<Func, Xpr>> {
231 using XprCleaned = remove_all_t<Xpr>;
232 using FuncCleaned = remove_all_t<Func>;
233 static constexpr
Index Cost = nested_functor_cost<FuncCleaned>::Cost + nested_functor_cost<XprCleaned>::Cost;
236 template <
typename Func,
typename Xpr>
237 struct nested_functor_cost<CwiseNullaryOp<Func, Xpr>> {
238 using XprCleaned = remove_all_t<Xpr>;
239 using FuncCleaned = remove_all_t<Func>;
240 static constexpr
Index Cost = nested_functor_cost<FuncCleaned>::Cost + nested_functor_cost<XprCleaned>::Cost;
243 template <
typename Func,
typename LhsXpr,
typename RhsXpr>
244 struct nested_functor_cost<CwiseBinaryOp<Func, LhsXpr, RhsXpr>> {
245 using LhsXprCleaned = remove_all_t<LhsXpr>;
246 using RhsXprCleaned = remove_all_t<RhsXpr>;
247 using FuncCleaned = remove_all_t<Func>;
248 static constexpr
Index Cost = nested_functor_cost<FuncCleaned>::Cost + nested_functor_cost<LhsXprCleaned>::Cost +
249 nested_functor_cost<RhsXprCleaned>::Cost;
252 template <
typename Func,
typename LhsXpr,
typename M
idXpr,
typename RhsXpr>
253 struct nested_functor_cost<CwiseTernaryOp<Func, LhsXpr, MidXpr, RhsXpr>> {
254 using LhsXprCleaned = remove_all_t<LhsXpr>;
255 using MidXprCleaned = remove_all_t<MidXpr>;
256 using RhsXprCleaned = remove_all_t<RhsXpr>;
257 using FuncCleaned = remove_all_t<Func>;
258 static constexpr
Index Cost = nested_functor_cost<FuncCleaned>::Cost + nested_functor_cost<LhsXprCleaned>::Cost +
259 nested_functor_cost<MidXprCleaned>::Cost + nested_functor_cost<RhsXprCleaned>::Cost;
262 template <
typename Xpr>
263 struct functor_cost {
264 static constexpr
Index Cost = plain_enum_max(nested_functor_cost<Xpr>::Cost, 1);
267 template <
typename T>
268 struct packet_traits;
270 template <
typename T>
271 struct unpacket_traits;
273 template <
int Size,
typename PacketType,
274 bool Stop = Size ==
Dynamic || (Size % unpacket_traits<PacketType>::size) == 0 ||
275 is_same<PacketType,
typename unpacket_traits<PacketType>::half>::value>
276 struct find_best_packet_helper;
278 template <
int Size,
typename PacketType>
279 struct find_best_packet_helper<Size, PacketType, true> {
280 typedef PacketType type;
283 template <
int Size,
typename PacketType>
284 struct find_best_packet_helper<Size, PacketType, false> {
285 typedef typename find_best_packet_helper<Size, typename unpacket_traits<PacketType>::half>::type type;
288 template <
typename T,
int Size>
289 struct find_best_packet {
290 typedef typename find_best_packet_helper<Size, typename packet_traits<T>::type>::type type;
293 template <
int Size,
typename PacketType,
294 bool Stop = (Size == unpacket_traits<PacketType>::size) ||
295 is_same<PacketType,
typename unpacket_traits<PacketType>::half>::value>
296 struct find_packet_by_size_helper;
297 template <
int Size,
typename PacketType>
298 struct find_packet_by_size_helper<Size, PacketType, true> {
299 using type = PacketType;
301 template <
int Size,
typename PacketType>
302 struct find_packet_by_size_helper<Size, PacketType, false> {
303 using type =
typename find_packet_by_size_helper<Size, typename unpacket_traits<PacketType>::half>::type;
306 template <
typename T,
int Size>
307 struct find_packet_by_size {
308 using type =
typename find_packet_by_size_helper<Size, typename packet_traits<T>::type>::type;
309 static constexpr
bool value = (Size == unpacket_traits<type>::size);
311 template <
typename T>
312 struct find_packet_by_size<T, 1> {
313 using type =
typename unpacket_traits<T>::type;
314 static constexpr
bool value = (unpacket_traits<type>::size == 1);
317 #if EIGEN_MAX_STATIC_ALIGN_BYTES > 0 318 constexpr
int compute_default_alignment_helper(
int ArrayBytes,
int AlignmentBytes) {
319 if ((ArrayBytes % AlignmentBytes) == 0) {
320 return AlignmentBytes;
321 }
else if (EIGEN_MIN_ALIGN_BYTES < AlignmentBytes) {
322 return compute_default_alignment_helper(ArrayBytes, AlignmentBytes / 2);
330 constexpr
int compute_default_alignment_helper(
int ArrayBytes,
int AlignmentBytes) {
331 EIGEN_UNUSED_VARIABLE(ArrayBytes);
332 EIGEN_UNUSED_VARIABLE(AlignmentBytes);
337 template <
typename T,
int Size>
338 struct compute_default_alignment {
339 enum { value = compute_default_alignment_helper(Size *
sizeof(T), EIGEN_MAX_STATIC_ALIGN_BYTES) };
342 template <
typename T>
343 struct compute_default_alignment<T,
Dynamic> {
344 enum { value = EIGEN_MAX_ALIGN_BYTES };
347 template <
typename Scalar_,
int Rows_,
int Cols_,
349 : (Cols_ == 1 && Rows_ != 1) ?
ColMajor 350 : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION),
351 int MaxRows_ = Rows_,
int MaxCols_ = Cols_>
352 class make_proper_matrix_type {
354 IsColVector = Cols_ == 1 && Rows_ != 1,
355 IsRowVector = Rows_ == 1 && Cols_ != 1,
362 typedef Matrix<Scalar_, Rows_, Cols_, Options, MaxRows_, MaxCols_> type;
365 constexpr
unsigned compute_matrix_flags(
int Options) {
373 constexpr
int size_at_compile_time(
int rows,
int cols) {
374 if (rows == 0 || cols == 0)
return 0;
379 template <
typename XprType>
380 struct size_of_xpr_at_compile_time {
381 enum { ret = size_at_compile_time(traits<XprType>::RowsAtCompileTime, traits<XprType>::ColsAtCompileTime) };
388 template <typename T, typename StorageKind = typename traits<T>::StorageKind>
389 struct plain_matrix_type;
390 template <
typename T,
typename BaseClassType,
int Flags>
391 struct plain_matrix_type_dense;
392 template <
typename T>
393 struct plain_matrix_type<T, Dense> {
394 typedef typename plain_matrix_type_dense<T, typename traits<T>::XprKind, traits<T>::Flags>::type type;
396 template <
typename T>
397 struct plain_matrix_type<T, DiagonalShape> {
398 typedef typename T::PlainObject type;
401 template <
typename T>
402 struct plain_matrix_type<T, SkewSymmetricShape> {
403 typedef typename T::PlainObject type;
406 template <
typename T,
int Flags>
407 struct plain_matrix_type_dense<T, MatrixXpr, Flags> {
408 typedef Matrix<typename traits<T>::Scalar, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime,
410 traits<T>::MaxColsAtCompileTime>
414 template <
typename T,
int Flags>
415 struct plain_matrix_type_dense<T, ArrayXpr, Flags> {
416 typedef Array<typename traits<T>::Scalar, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime,
418 traits<T>::MaxColsAtCompileTime>
426 template <typename T, typename StorageKind = typename traits<T>::StorageKind>
429 template <
typename T>
430 struct eval<T, Dense> {
431 typedef typename plain_matrix_type<T>::type type;
442 template <
typename T>
443 struct eval<T, DiagonalShape> {
444 typedef typename plain_matrix_type<T>::type type;
447 template <
typename T>
448 struct eval<T, SkewSymmetricShape> {
449 typedef typename plain_matrix_type<T>::type type;
453 template <
typename Scalar_,
int Rows_,
int Cols_,
int Options_,
int MaxRows_,
int MaxCols_>
454 struct eval<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>, Dense> {
455 typedef const Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>& type;
458 template <
typename Scalar_,
int Rows_,
int Cols_,
int Options_,
int MaxRows_,
int MaxCols_>
459 struct eval<Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>, Dense> {
460 typedef const Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>& type;
464 template <typename T, typename StorageKind = typename traits<T>::StorageKind>
465 struct plain_object_eval;
467 template <
typename T>
468 struct plain_object_eval<T, Dense> {
469 typedef typename plain_matrix_type_dense<T, typename traits<T>::XprKind, evaluator<T>::Flags>::type type;
474 template <
typename T>
475 struct plain_matrix_type_column_major {
477 Rows = traits<T>::RowsAtCompileTime,
478 Cols = traits<T>::ColsAtCompileTime,
479 MaxRows = traits<T>::MaxRowsAtCompileTime,
480 MaxCols = traits<T>::MaxColsAtCompileTime
482 typedef Matrix<typename traits<T>::Scalar, Rows, Cols, (MaxRows == 1 && MaxCols != 1) ?
RowMajor :
ColMajor, MaxRows,
489 template <
typename T>
490 struct plain_matrix_type_row_major {
492 Rows = traits<T>::RowsAtCompileTime,
493 Cols = traits<T>::ColsAtCompileTime,
494 MaxRows = traits<T>::MaxRowsAtCompileTime,
495 MaxCols = traits<T>::MaxColsAtCompileTime
497 typedef Matrix<typename traits<T>::Scalar, Rows, Cols, (MaxCols == 1 && MaxRows != 1) ?
ColMajor :
RowMajor, MaxRows,
505 template <
typename T>
506 struct ref_selector {
507 typedef std::conditional_t<bool(traits<T>::Flags& NestByRefBit), T
const&,
const T> type;
509 typedef std::conditional_t<bool(traits<T>::Flags& NestByRefBit), T&, T> non_const_type;
513 template <
typename T1,
typename T2>
514 struct transfer_constness {
515 typedef std::conditional_t<bool(internal::is_const<T1>::value), add_const_on_value_type_t<T2>, T2> type;
532 template <typename T, int n, typename PlainObject = typename plain_object_eval<T>::type>
535 ScalarReadCost = NumTraits<typename traits<T>::Scalar>::ReadCost,
537 evaluator<T>::CoeffReadCost,
544 CostEval = (NAsInteger + 1) * ScalarReadCost + CoeffReadCost,
545 CostNoEval =
int(NAsInteger) * int(CoeffReadCost),
546 Evaluate = (int(evaluator<T>::Flags) &
EvalBeforeNestingBit) || (
int(CostEval) < int(CostNoEval))
549 typedef std::conditional_t<Evaluate, PlainObject, typename ref_selector<T>::type> type;
552 template <
typename T>
553 EIGEN_DEVICE_FUNC
inline T* const_cast_ptr(
const T* ptr) {
554 return const_cast<T*
>(ptr);
557 template <typename Derived, typename XprKind = typename traits<Derived>::XprKind>
558 struct dense_xpr_base {
563 template <
typename Derived>
564 struct dense_xpr_base<Derived, MatrixXpr> {
565 typedef MatrixBase<Derived> type;
568 template <
typename Derived>
569 struct dense_xpr_base<Derived, ArrayXpr> {
570 typedef ArrayBase<Derived> type;
573 template <typename Derived, typename XprKind = typename traits<Derived>::XprKind,
574 typename StorageKind =
typename traits<Derived>::StorageKind>
575 struct generic_xpr_base;
577 template <
typename Derived,
typename XprKind>
578 struct generic_xpr_base<Derived, XprKind, Dense> {
579 typedef typename dense_xpr_base<Derived, XprKind>::type type;
582 template <
typename XprType,
typename CastType>
583 struct cast_return_type {
584 typedef typename XprType::Scalar CurrentScalarType;
585 typedef remove_all_t<CastType> CastType_;
586 typedef typename CastType_::Scalar NewScalarType;
587 typedef std::conditional_t<is_same<CurrentScalarType, NewScalarType>::value,
const XprType&, CastType> type;
590 template <
typename A,
typename B>
591 struct promote_storage_type;
593 template <
typename A>
594 struct promote_storage_type<A, A> {
597 template <
typename A>
598 struct promote_storage_type<A, const A> {
601 template <
typename A>
602 struct promote_storage_type<const A, A> {
619 template <
typename A,
typename B,
typename Functor>
620 struct cwise_promote_storage_type;
622 template <
typename A,
typename Functor>
623 struct cwise_promote_storage_type<A, A, Functor> {
626 template <
typename Functor>
627 struct cwise_promote_storage_type<Dense, Dense, Functor> {
630 template <
typename A,
typename Functor>
631 struct cwise_promote_storage_type<A, Dense, Functor> {
634 template <
typename B,
typename Functor>
635 struct cwise_promote_storage_type<Dense, B, Functor> {
638 template <
typename Functor>
639 struct cwise_promote_storage_type<Sparse, Dense, Functor> {
642 template <
typename Functor>
643 struct cwise_promote_storage_type<Dense, Sparse, Functor> {
647 template <
typename LhsKind,
typename RhsKind,
int LhsOrder,
int RhsOrder>
648 struct cwise_promote_storage_order {
649 enum { value = LhsOrder };
652 template <
typename LhsKind,
int LhsOrder,
int RhsOrder>
653 struct cwise_promote_storage_order<LhsKind, Sparse, LhsOrder, RhsOrder> {
654 enum { value = RhsOrder };
656 template <
typename RhsKind,
int LhsOrder,
int RhsOrder>
657 struct cwise_promote_storage_order<Sparse, RhsKind, LhsOrder, RhsOrder> {
658 enum { value = LhsOrder };
661 struct cwise_promote_storage_order<Sparse, Sparse, Order, Order> {
662 enum { value = Order };
679 template <
typename A,
typename B,
int ProductTag>
680 struct product_promote_storage_type;
682 template <
typename A,
int ProductTag>
683 struct product_promote_storage_type<A, A, ProductTag> {
686 template <
int ProductTag>
687 struct product_promote_storage_type<Dense, Dense, ProductTag> {
690 template <
typename A,
int ProductTag>
691 struct product_promote_storage_type<A, Dense, ProductTag> {
694 template <
typename B,
int ProductTag>
695 struct product_promote_storage_type<Dense, B, ProductTag> {
699 template <
typename A,
int ProductTag>
700 struct product_promote_storage_type<A, DiagonalShape, ProductTag> {
703 template <
typename B,
int ProductTag>
704 struct product_promote_storage_type<DiagonalShape, B, ProductTag> {
707 template <
int ProductTag>
708 struct product_promote_storage_type<Dense, DiagonalShape, ProductTag> {
711 template <
int ProductTag>
712 struct product_promote_storage_type<DiagonalShape, Dense, ProductTag> {
716 template <
typename A,
int ProductTag>
717 struct product_promote_storage_type<A, SkewSymmetricShape, ProductTag> {
720 template <
typename B,
int ProductTag>
721 struct product_promote_storage_type<SkewSymmetricShape, B, ProductTag> {
724 template <
int ProductTag>
725 struct product_promote_storage_type<Dense, SkewSymmetricShape, ProductTag> {
728 template <
int ProductTag>
729 struct product_promote_storage_type<SkewSymmetricShape, Dense, ProductTag> {
732 template <
int ProductTag>
733 struct product_promote_storage_type<SkewSymmetricShape, SkewSymmetricShape, ProductTag> {
737 template <
typename A,
int ProductTag>
738 struct product_promote_storage_type<A, PermutationStorage, ProductTag> {
741 template <
typename B,
int ProductTag>
742 struct product_promote_storage_type<PermutationStorage, B, ProductTag> {
745 template <
int ProductTag>
746 struct product_promote_storage_type<Dense, PermutationStorage, ProductTag> {
749 template <
int ProductTag>
750 struct product_promote_storage_type<PermutationStorage, Dense, ProductTag> {
757 template <
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
758 struct plain_row_type {
759 typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime,
760 int(ExpressionType::PlainObject::Options) | int(
RowMajor), 1, ExpressionType::MaxColsAtCompileTime>
762 typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime, int(ExpressionType::PlainObject::Options) | int(
RowMajor),
763 1, ExpressionType::MaxColsAtCompileTime>
766 typedef std::conditional_t<is_same<typename traits<ExpressionType>::XprKind, MatrixXpr>::value, MatrixRowType,
771 template <
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
772 struct plain_col_type {
773 typedef Matrix<Scalar, ExpressionType::RowsAtCompileTime, 1, ExpressionType::PlainObject::Options & ~
RowMajor,
774 ExpressionType::MaxRowsAtCompileTime, 1>
776 typedef Array<Scalar, ExpressionType::RowsAtCompileTime, 1, ExpressionType::PlainObject::Options & ~
RowMajor,
777 ExpressionType::MaxRowsAtCompileTime, 1>
780 typedef std::conditional_t<is_same<typename traits<ExpressionType>::XprKind, MatrixXpr>::value, MatrixColType,
785 template <
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
786 struct plain_diag_type {
788 diag_size = internal::min_size_prefer_dynamic(ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime),
789 max_diag_size = min_size_prefer_fixed(ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime)
791 typedef Matrix<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1>
793 typedef Array<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> ArrayDiagType;
795 typedef std::conditional_t<is_same<typename traits<ExpressionType>::XprKind, MatrixXpr>::value, MatrixDiagType,
800 template <
typename Expr,
typename Scalar =
typename Expr::Scalar>
801 struct plain_constant_type {
804 typedef Array<Scalar, traits<Expr>::RowsAtCompileTime, traits<Expr>::ColsAtCompileTime, Options,
805 traits<Expr>::MaxRowsAtCompileTime, traits<Expr>::MaxColsAtCompileTime>
808 typedef Matrix<Scalar, traits<Expr>::RowsAtCompileTime, traits<Expr>::ColsAtCompileTime, Options,
809 traits<Expr>::MaxRowsAtCompileTime, traits<Expr>::MaxColsAtCompileTime>
812 typedef CwiseNullaryOp<
813 scalar_constant_op<Scalar>,
814 const std::conditional_t<is_same<typename traits<Expr>::XprKind, MatrixXpr>::value, matrix_type, array_type>>
818 template <
typename ExpressionType>
820 enum { value = (!bool(is_const<ExpressionType>::value)) &&
bool(traits<ExpressionType>::Flags &
LvalueBit) };
823 template <
typename T>
825 enum { ret =
false };
828 template <
typename T>
829 struct is_diagonal<DiagonalBase<T>> {
833 template <
typename T>
834 struct is_diagonal<DiagonalWrapper<T>> {
838 template <
typename T,
int S>
839 struct is_diagonal<DiagonalMatrix<T, S>> {
843 template <
typename T>
845 enum { value =
false };
848 template <
typename T>
849 struct is_identity<CwiseNullaryOp<internal::scalar_identity_op<typename T::Scalar>, T>> {
850 enum { value =
true };
853 template <
typename S1,
typename S2>
856 struct glue_shapes<DenseShape, TriangularShape> {
857 typedef TriangularShape type;
860 template <
typename T1,
typename T2>
861 struct possibly_same_dense {
863 value = has_direct_access<T1>::ret && has_direct_access<T2>::ret &&
864 is_same<typename T1::Scalar, typename T2::Scalar>::value
868 template <
typename T1,
typename T2>
869 EIGEN_DEVICE_FUNC
bool is_same_dense(
const T1& mat1,
const T2& mat2,
870 std::enable_if_t<possibly_same_dense<T1, T2>::value>* = 0) {
871 return (mat1.data() == mat2.data()) && (mat1.innerStride() == mat2.innerStride()) &&
872 (mat1.outerStride() == mat2.outerStride());
875 template <
typename T1,
typename T2>
876 EIGEN_DEVICE_FUNC
bool is_same_dense(
const T1&,
const T2&, std::enable_if_t<!possibly_same_dense<T1, T2>::value>* = 0) {
882 template <
typename T,
bool Vectorized = false,
typename EnableIf =
void>
883 struct scalar_div_cost {
884 enum { value = 8 * NumTraits<T>::MulCost };
887 template <
typename T,
bool Vectorized>
888 struct scalar_div_cost<T, Vectorized,
std::enable_if_t<NumTraits<T>::IsComplex>> {
889 using RealScalar =
typename NumTraits<T>::Real;
892 2 * scalar_div_cost<RealScalar>::value + 6 * NumTraits<RealScalar>::MulCost + 3 * NumTraits<RealScalar>::AddCost
896 template <
bool Vectorized>
897 struct scalar_div_cost<signed long, Vectorized,
std::conditional_t<sizeof(long) == 8, void, false_type>> {
900 template <
bool Vectorized>
901 struct scalar_div_cost<unsigned long, Vectorized,
std::conditional_t<sizeof(long) == 8, void, false_type>> {
905 #ifdef EIGEN_DEBUG_ASSIGN 906 std::string demangle_traversal(
int t) {
907 if (t == DefaultTraversal)
return "DefaultTraversal";
908 if (t == LinearTraversal)
return "LinearTraversal";
909 if (t == InnerVectorizedTraversal)
return "InnerVectorizedTraversal";
910 if (t == LinearVectorizedTraversal)
return "LinearVectorizedTraversal";
911 if (t == SliceVectorizedTraversal)
return "SliceVectorizedTraversal";
914 std::string demangle_unrolling(
int t) {
915 if (t == NoUnrolling)
return "NoUnrolling";
916 if (t == InnerUnrolling)
return "InnerUnrolling";
917 if (t == CompleteUnrolling)
return "CompleteUnrolling";
920 std::string demangle_flags(
int f) {
927 if (f & NestByRefBit) res +=
" | NestByRef";
934 template <
typename XprType>
935 struct is_block_xpr : std::false_type {};
937 template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
938 struct is_block_xpr<Block<XprType, BlockRows, BlockCols, InnerPanel>> : std::true_type {};
940 template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
941 struct is_block_xpr<const Block<XprType, BlockRows, BlockCols, InnerPanel>> : std::true_type {};
944 template <
typename XprType>
945 struct block_xpr_helper {
946 using BaseType = XprType;
950 static constexpr
bool is_inner_panel(
bool inner_panel) {
return inner_panel; }
953 template <typename T = XprType, typename EnableIf = std::enable_if_t<!std::is_const<T>::value>>
954 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BaseType& base(XprType& xpr) {
957 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
const BaseType& base(
const XprType& xpr) {
return xpr; }
958 static constexpr EIGEN_ALWAYS_INLINE
Index row(
const XprType& ,
Index r) {
return r; }
959 static constexpr EIGEN_ALWAYS_INLINE
Index col(
const XprType& ,
Index c) {
return c; }
962 template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
963 struct block_xpr_helper<Block<XprType, BlockRows, BlockCols, InnerPanel>> {
964 using BlockXprType = Block<XprType, BlockRows, BlockCols, InnerPanel>;
966 using NestedXprHelper = block_xpr_helper<XprType>;
967 using BaseType =
typename NestedXprHelper::BaseType;
971 static constexpr
bool is_inner_panel(
bool inner_panel) {
return InnerPanel && inner_panel; }
974 template <typename T = XprType, typename EnableIf = std::enable_if_t<!std::is_const<T>::value>>
975 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BaseType& base(BlockXprType& xpr) {
976 return NestedXprHelper::base(xpr.nestedExpression());
978 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
const BaseType& base(
const BlockXprType& xpr) {
979 return NestedXprHelper::base(xpr.nestedExpression());
981 static constexpr EIGEN_ALWAYS_INLINE
Index row(
const BlockXprType& xpr,
Index r) {
982 return xpr.startRow() + NestedXprHelper::row(xpr.nestedExpression(), r);
984 static constexpr EIGEN_ALWAYS_INLINE
Index col(
const BlockXprType& xpr,
Index c) {
985 return xpr.startCol() + NestedXprHelper::col(xpr.nestedExpression(), c);
989 template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
990 struct block_xpr_helper<const Block<XprType, BlockRows, BlockCols, InnerPanel>>
991 : block_xpr_helper<Block<XprType, BlockRows, BlockCols, InnerPanel>> {};
993 template <
typename XprType>
994 struct is_matrix_base_xpr : std::is_base_of<MatrixBase<remove_all_t<XprType>>, remove_all_t<XprType>> {};
996 template <
typename XprType>
997 struct is_permutation_base_xpr : std::is_base_of<PermutationBase<remove_all_t<XprType>>, remove_all_t<XprType>> {};
1041 template <
typename ScalarA,
typename ScalarB,
typename BinaryOp =
internal::scalar_product_op<ScalarA, ScalarB>>
1043 #ifndef EIGEN_PARSED_BY_DOXYGEN
1045 : internal::scalar_product_traits<ScalarA, ScalarB>
1046 #endif // EIGEN_PARSED_BY_DOXYGEN 1050 template <
typename T,
typename BinaryOp>
1052 typedef T ReturnType;
1055 template <
typename T,
typename BinaryOp>
1056 struct ScalarBinaryOpTraits<T, typename NumTraits<
std::enable_if_t<NumTraits<T>::IsComplex, T>>::Real, BinaryOp> {
1057 typedef T ReturnType;
1059 template <
typename T,
typename BinaryOp>
1060 struct ScalarBinaryOpTraits<typename NumTraits<
std::enable_if_t<NumTraits<T>::IsComplex, T>>::Real, T, BinaryOp> {
1061 typedef T ReturnType;
1065 template <
typename T,
typename BinaryOp>
1066 struct ScalarBinaryOpTraits<T, void, BinaryOp> {
1067 typedef T ReturnType;
1071 template <
typename T,
typename BinaryOp>
1072 struct ScalarBinaryOpTraits<void, T, BinaryOp> {
1073 typedef T ReturnType;
1077 template <
typename BinaryOp>
1078 struct ScalarBinaryOpTraits<void, void, BinaryOp> {
1079 typedef void ReturnType;
1086 #define EIGEN_CHECK_BINARY_COMPATIBILIY(BINOP, LHS, RHS) \ 1087 EIGEN_STATIC_ASSERT( \ 1088 (Eigen::internal::has_ReturnType<ScalarBinaryOpTraits<LHS, RHS, BINOP>>::value), \ 1089 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) 1093 #endif // EIGEN_XPRHELPER_H Definition: Constants.h:318
const int HugeCost
Definition: Constants.h:48
const unsigned int DirectAccessBit
Definition: Constants.h:159
const unsigned int LvalueBit
Definition: Constants.h:148
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
const int DynamicIndex
Definition: Constants.h:30
Definition: BFloat16.h:231
const unsigned int RowMajorBit
Definition: Constants.h:70
const unsigned int PacketAccessBit
Definition: Constants.h:97
Definition: Constants.h:322
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
Definition: Constants.h:320
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:1042
const int Dynamic
Definition: Constants.h:25
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:74
const unsigned int LinearAccessBit
Definition: Constants.h:133
const unsigned int NoPreferredStorageOrderBit
Definition: Constants.h:182