12#ifndef EIGEN_XPRHELPER_H
13#define EIGEN_XPRHELPER_H
16#include "../InternalHeaderCheck.h"
23template <
typename IndexType>
24EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::make_unsigned_t<IndexType> returnUnsignedIndexValue(
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 = std::make_unsigned_t<IndexType>;
28 return static_cast<UnsignedType
>(idx);
31template <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>
35struct 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);
41template <
typename IndexDest,
typename IndexSrc>
42struct 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);
51template <
typename IndexDest,
typename IndexSrc>
52struct 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);
62template <
typename IndexDest,
typename IndexSrc>
63EIGEN_DEVICE_FUNC
inline IndexDest convert_index(
const IndexSrc& idx) {
64 return convert_index_impl<IndexDest, IndexSrc>::run(idx);
68template <
typename RowIndices,
typename ColIndices>
69struct valid_indexed_view_overload : bool_constant<!(internal::is_valid_index_type<RowIndices>::value &&
70 internal::is_valid_index_type<ColIndices>::value)> {};
72template <
typename T,
typename =
void>
73struct is_eigen_expression : std::false_type {};
77struct is_eigen_expression<T, void_t<decltype(std::declval<const T&>().derived()),
78 typename traits<typename shape_expression<T>::type>::StorageKind>>
79 : std::is_convertible<const remove_all_t<T>*, const EigenBase<typename shape_expression<T>::type>*> {};
95template <
typename ExprScalar,
typename T,
bool IsSupported>
96struct promote_scalar_arg;
98template <
typename S,
typename T>
99struct promote_scalar_arg<S, T, true> {
104template <
typename ExprScalar,
typename T,
typename PromotedType,
105 bool ConvertibleToLiteral = std::is_convertible<T, PromotedType>::value,
106 bool IsSafe = NumTraits<T>::IsInteger || !NumTraits<PromotedType>::IsInteger>
107struct promote_scalar_arg_unsupported;
110template <
typename S,
typename T>
111struct promote_scalar_arg<S, T, false> : promote_scalar_arg_unsupported<S, T, typename NumTraits<S>::Literal> {};
114template <
typename S,
typename T,
typename PromotedType>
115struct promote_scalar_arg_unsupported<S, T, PromotedType, true, true> {
116 using type = PromotedType;
121template <
typename ExprScalar,
typename T,
typename PromotedType>
122struct promote_scalar_arg_unsupported<ExprScalar, T, PromotedType, false, true>
123 : promote_scalar_arg_unsupported<ExprScalar, T, ExprScalar> {};
126template <
typename S,
typename T,
typename PromotedType,
bool ConvertibleToLiteral>
127struct promote_scalar_arg_unsupported<S, T, PromotedType, ConvertibleToLiteral, false> {};
130template <
typename S,
typename T>
131struct promote_scalar_arg_unsupported<S, T, S, false, true> {};
134class no_assignment_operator {
135 no_assignment_operator& operator=(
const no_assignment_operator&) =
delete;
138 EIGEN_DEFAULT_COPY_CONSTRUCTOR(no_assignment_operator)
139 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(no_assignment_operator)
143template <
typename I1,
typename I2>
144struct promote_index_type {
145 using type = std::conditional_t<(
sizeof(I1) <
sizeof(I2)), I2, I1>;
152template <
typename T,
int Value>
153class variable_if_dynamic {
155 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
explicit variable_if_dynamic(T v)
noexcept {
156 EIGEN_ONLY_USED_FOR_DEBUG(v);
157 eigen_plain_assert(v == T(Value));
159 EIGEN_DEVICE_FUNC
static constexpr T value() {
return T(Value); }
160 EIGEN_DEVICE_FUNC
constexpr operator T()
const {
return T(Value); }
161 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T v)
const {
162 EIGEN_ONLY_USED_FOR_DEBUG(v);
163 eigen_assert(v == T(Value));
168class variable_if_dynamic<T, Dynamic> {
172 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
explicit variable_if_dynamic(T value = 0) noexcept : m_value(value) {}
173 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE T value()
const {
return m_value; }
174 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
operator T()
const {
return m_value; }
175 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T value) { m_value = value; }
180template <
typename T,
int Value>
181class variable_if_dynamicindex {
183 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
explicit variable_if_dynamicindex(T v) {
184 EIGEN_ONLY_USED_FOR_DEBUG(v);
185 eigen_assert(v == T(Value));
187 EIGEN_DEVICE_FUNC
static constexpr T value() {
return T(Value); }
188 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr void setValue(T) {}
192class variable_if_dynamicindex<T, DynamicIndex> {
194 EIGEN_DEVICE_FUNC variable_if_dynamicindex() { eigen_assert(
false); }
197 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
explicit variable_if_dynamicindex(T value) : m_value(value) {}
198 EIGEN_DEVICE_FUNC
constexpr T EIGEN_STRONG_INLINE value()
const {
return m_value; }
199 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T value) { m_value = value; }
203struct functor_traits {
204 enum { Cost = 10, PacketAccess =
false, IsRepeatable =
false };
212template <
typename Func>
213struct functor_is_commutative : std::false_type {};
216template <
typename Xpr>
217struct nested_functor_cost {
218 static constexpr Index Cost =
static_cast<Index
>(functor_traits<Xpr>::Cost);
221template <
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
222struct nested_functor_cost<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>> {
223 static constexpr Index Cost = 1;
226template <
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
227struct nested_functor_cost<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>> {
228 static constexpr Index Cost = 1;
232template <
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
233struct nested_functor_cost<Map<PlainObjectType, MapOptions, StrideType>> : nested_functor_cost<PlainObjectType> {};
235template <
typename Func,
typename Xpr>
236struct nested_functor_cost<CwiseUnaryOp<Func, Xpr>> {
237 using XprCleaned = remove_all_t<Xpr>;
238 using FuncCleaned = remove_all_t<Func>;
239 static constexpr Index Cost = nested_functor_cost<FuncCleaned>::Cost + nested_functor_cost<XprCleaned>::Cost;
242template <
typename Func,
typename Xpr>
243struct nested_functor_cost<CwiseNullaryOp<Func, Xpr>> {
244 using XprCleaned = remove_all_t<Xpr>;
245 using FuncCleaned = remove_all_t<Func>;
246 static constexpr Index Cost = nested_functor_cost<FuncCleaned>::Cost + nested_functor_cost<XprCleaned>::Cost;
249template <
typename Func,
typename LhsXpr,
typename RhsXpr>
250struct nested_functor_cost<CwiseBinaryOp<Func, LhsXpr, RhsXpr>> {
251 using LhsXprCleaned = remove_all_t<LhsXpr>;
252 using RhsXprCleaned = remove_all_t<RhsXpr>;
253 using FuncCleaned = remove_all_t<Func>;
254 static constexpr Index Cost = nested_functor_cost<FuncCleaned>::Cost + nested_functor_cost<LhsXprCleaned>::Cost +
255 nested_functor_cost<RhsXprCleaned>::Cost;
258template <
typename Func,
typename LhsXpr,
typename M
idXpr,
typename RhsXpr>
259struct nested_functor_cost<CwiseTernaryOp<Func, LhsXpr, MidXpr, RhsXpr>> {
260 using LhsXprCleaned = remove_all_t<LhsXpr>;
261 using MidXprCleaned = remove_all_t<MidXpr>;
262 using RhsXprCleaned = remove_all_t<RhsXpr>;
263 using FuncCleaned = remove_all_t<Func>;
264 static constexpr Index Cost = nested_functor_cost<FuncCleaned>::Cost + nested_functor_cost<LhsXprCleaned>::Cost +
265 nested_functor_cost<MidXprCleaned>::Cost + nested_functor_cost<RhsXprCleaned>::Cost;
268template <
typename Xpr>
270 static constexpr Index Cost = plain_enum_max(nested_functor_cost<Xpr>::Cost, 1);
277struct unpacket_traits;
279template <
int Size,
typename PacketType,
280 bool Stop = Size == Dynamic || (Size % unpacket_traits<PacketType>::size) == 0 ||
281 std::is_same<PacketType,
typename unpacket_traits<PacketType>::half>::value>
282struct find_best_packet_helper;
284template <
int Size,
typename PacketType>
285struct find_best_packet_helper<Size, PacketType, true> {
286 using type = PacketType;
289template <
int Size,
typename PacketType>
290struct find_best_packet_helper<Size, PacketType, false> {
291 using type =
typename find_best_packet_helper<Size, typename unpacket_traits<PacketType>::half>::type;
294template <
typename T,
int Size>
295struct find_best_packet {
296 using type =
typename find_best_packet_helper<Size, typename packet_traits<T>::type>::type;
301template <
int Size,
typename PacketType,
302 bool Stop = Size == Dynamic || Size >= unpacket_traits<PacketType>::size ||
303 std::is_same<PacketType, typename unpacket_traits<PacketType>::half>::value>
304struct find_largest_packet_helper;
306template <
int Size,
typename PacketType>
307struct find_largest_packet_helper<Size, PacketType, true> {
308 using type = PacketType;
311template <
int Size,
typename PacketType>
312struct find_largest_packet_helper<Size, PacketType, false> {
313 using type =
typename find_largest_packet_helper<Size, typename unpacket_traits<PacketType>::half>::type;
316template <
typename T,
int Size>
317struct find_largest_packet {
318 using type =
typename find_largest_packet_helper<Size, typename packet_traits<T>::type>::type;
336template <
typename T,
int Size>
337struct find_assign_linear_packet {
339 using best_type =
typename find_best_packet<T, Size>::type;
340 using largest_type =
typename find_largest_packet<T, Size>::type;
344 template <
typename P>
345 static constexpr int ops() {
346 constexpr int sz = unpacket_traits<P>::size;
347 return Size == Dynamic ? 0 : Size / sz + Size % sz;
351 using type = std::conditional_t<(ops<largest_type>() < ops<best_type>()), largest_type, best_type>;
354template <
int Size,
typename PacketType,
355 bool Stop = (Size == unpacket_traits<PacketType>::size) ||
356 std::is_same<PacketType,
typename unpacket_traits<PacketType>::half>::value>
357struct find_packet_by_size_helper;
358template <
int Size,
typename PacketType>
359struct find_packet_by_size_helper<Size, PacketType, true> {
360 using type = PacketType;
362template <
int Size,
typename PacketType>
363struct find_packet_by_size_helper<Size, PacketType, false> {
364 using type =
typename find_packet_by_size_helper<Size, typename unpacket_traits<PacketType>::half>::type;
367template <
typename T,
int Size>
368struct find_packet_by_size {
369 using type =
typename find_packet_by_size_helper<Size, typename packet_traits<T>::type>::type;
370 static constexpr bool value = (Size == unpacket_traits<type>::size);
373struct find_packet_by_size<T, 1> {
374 using type =
typename unpacket_traits<T>::type;
375 static constexpr bool value = (unpacket_traits<type>::size == 1);
378#if EIGEN_MAX_STATIC_ALIGN_BYTES > 0
379constexpr int compute_default_alignment_helper(
int ArrayBytes,
int AlignmentBytes) {
380 if ((ArrayBytes % AlignmentBytes) == 0) {
381 return AlignmentBytes;
382 }
else if (EIGEN_MIN_ALIGN_BYTES < AlignmentBytes) {
383 return compute_default_alignment_helper(ArrayBytes, AlignmentBytes / 2);
391constexpr int compute_default_alignment_helper(
int ArrayBytes,
int AlignmentBytes) {
392 EIGEN_UNUSED_VARIABLE(ArrayBytes);
393 EIGEN_UNUSED_VARIABLE(AlignmentBytes);
398template <
typename T,
int Size>
399struct compute_default_alignment
400 : std::integral_constant<int, compute_default_alignment_helper(Size * sizeof(T), EIGEN_MAX_STATIC_ALIGN_BYTES)> {};
403struct compute_default_alignment<T, Dynamic> : std::integral_constant<int, EIGEN_MAX_ALIGN_BYTES> {};
405template <
typename Scalar_,
int Rows_,
int Cols_,
407 : (Cols_ == 1 && Rows_ != 1) ?
ColMajor
408 : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION),
409 int MaxRows_ = Rows_,
int MaxCols_ = Cols_>
410struct make_proper_matrix_type {
412 static constexpr bool IsColVector = Cols_ == 1 && Rows_ != 1;
413 static constexpr bool IsRowVector = Rows_ == 1 && Cols_ != 1;
414 static constexpr int Options = IsColVector ? (Options_ |
ColMajor) & ~
RowMajor
419 using type = Matrix<Scalar_, Rows_, Cols_, Options, MaxRows_, MaxCols_>;
422constexpr unsigned compute_matrix_flags(
int Options) {
430template <
typename XprType>
431struct size_of_xpr_at_compile_time
432 : std::integral_constant<int, size_at_compile_time(traits<XprType>::RowsAtCompileTime,
433 traits<XprType>::ColsAtCompileTime)> {};
439template <typename T, typename StorageKind = typename traits<T>::StorageKind>
440struct plain_matrix_type;
447struct plain_object_options {
448 static constexpr int value = int(traits<T>::Options);
450template <
typename PlainObjectType,
int Options,
typename Str
ideType>
451struct plain_object_options<Ref<PlainObjectType, Options, StrideType>> : plain_object_options<PlainObjectType> {};
455struct is_ref : std::false_type {};
456template <
typename PlainObjectType,
int Options,
typename Str
ideType>
457struct is_ref<Ref<PlainObjectType, Options, StrideType>> : std::true_type {};
459template <
typename T,
typename BaseClassType,
int Flags>
460struct plain_matrix_type_dense;
462struct plain_matrix_type<T, Dense> {
463 using type =
typename plain_matrix_type_dense<T, typename traits<T>::XprKind, traits<T>::Flags>::type;
466struct plain_matrix_type<T, DiagonalShape> {
467 using type =
typename T::PlainObject;
471struct plain_matrix_type<T, SkewSymmetricShape> {
472 using type =
typename T::PlainObject;
475template <
typename T,
int Flags>
476struct plain_matrix_type_dense<T, MatrixXpr, Flags> {
477 using type = Matrix<typename traits<T>::Scalar, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime,
479 traits<T>::MaxColsAtCompileTime>;
482template <
typename T,
int Flags>
483struct plain_matrix_type_dense<T, ArrayXpr, Flags> {
484 using type = Array<typename traits<T>::Scalar, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime,
486 traits<T>::MaxColsAtCompileTime>;
493template <typename T, typename StorageKind = typename traits<T>::StorageKind>
497struct eval<T, Dense> {
498 using type =
typename plain_matrix_type<T>::type;
502struct eval<T, DiagonalShape> {
503 using type =
typename plain_matrix_type<T>::type;
507struct eval<T, SkewSymmetricShape> {
508 using type =
typename plain_matrix_type<T>::type;
512template <
typename Scalar_,
int Rows_,
int Cols_,
int Options_,
int MaxRows_,
int MaxCols_>
513struct eval<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>, Dense> {
514 using type =
const Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>&;
517template <
typename Scalar_,
int Rows_,
int Cols_,
int Options_,
int MaxRows_,
int MaxCols_>
518struct eval<Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>, Dense> {
519 using type =
const Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>&;
523template <typename T, typename StorageKind = typename traits<T>::StorageKind>
524struct plain_object_eval;
527struct plain_object_eval<T, Dense> {
528 using type =
typename plain_matrix_type_dense<T, typename traits<T>::XprKind, evaluator<T>::Flags>::type;
534struct plain_matrix_type_column_major {
535 static constexpr int Rows = traits<T>::RowsAtCompileTime;
536 static constexpr int Cols = traits<T>::ColsAtCompileTime;
537 static constexpr int MaxRows = traits<T>::MaxRowsAtCompileTime;
538 static constexpr int MaxCols = traits<T>::MaxColsAtCompileTime;
539 using type = Matrix<typename traits<T>::Scalar, Rows, Cols, (MaxRows == 1 && MaxCols != 1) ?
RowMajor :
ColMajor,
546struct plain_matrix_type_row_major {
547 static constexpr int Rows = traits<T>::RowsAtCompileTime;
548 static constexpr int Cols = traits<T>::ColsAtCompileTime;
549 static constexpr int MaxRows = traits<T>::MaxRowsAtCompileTime;
550 static constexpr int MaxCols = traits<T>::MaxColsAtCompileTime;
551 using type = Matrix<typename traits<T>::Scalar, Rows, Cols, (MaxCols == 1 && MaxRows != 1) ?
ColMajor :
RowMajor,
560 using type = std::conditional_t<bool(traits<T>::Flags& NestByRefBit), T
const&,
const T>;
562 using non_const_type = std::conditional_t<bool(traits<T>::Flags& NestByRefBit), T&, T>;
579template <typename T, int n, typename PlainObject = typename plain_object_eval<T>::type>
582 ScalarReadCost = NumTraits<typename traits<T>::Scalar>::ReadCost,
584 evaluator<T>::CoeffReadCost,
590 NAsInteger = n == Dynamic ? HugeCost : n,
591 CostEval = (NAsInteger + 1) * ScalarReadCost + CoeffReadCost,
592 CostNoEval =
int(NAsInteger) * int(CoeffReadCost),
593 Evaluate = (int(evaluator<T>::Flags) &
EvalBeforeNestingBit) || (
int(CostEval) <
int(CostNoEval))
596 using type = std::conditional_t<Evaluate, PlainObject, typename ref_selector<T>::type>;
599template <typename Derived, typename XprKind = typename traits<Derived>::XprKind>
600struct dense_xpr_base {
605template <
typename Derived>
606struct dense_xpr_base<Derived, MatrixXpr> {
607 using type = MatrixBase<Derived>;
610template <
typename Derived>
611struct dense_xpr_base<Derived, ArrayXpr> {
612 using type = ArrayBase<Derived>;
615template <typename Derived, typename XprKind = typename traits<Derived>::XprKind,
616 typename StorageKind =
typename traits<Derived>::StorageKind>
617struct generic_xpr_base;
619template <
typename Derived,
typename XprKind>
620struct generic_xpr_base<Derived, XprKind, Dense> {
621 using type =
typename dense_xpr_base<Derived, XprKind>::type;
624template <
typename XprType,
typename CastType>
625struct cast_return_type {
626 using CurrentScalarType =
typename XprType::Scalar;
627 using CastType_ = remove_all_t<CastType>;
628 using NewScalarType =
typename CastType_::Scalar;
629 using type = std::conditional_t<std::is_same<CurrentScalarType, NewScalarType>::value,
const XprType&, CastType>;
632template <
typename A,
typename B>
633struct promote_storage_type;
636struct promote_storage_type<A, A> {
640struct promote_storage_type<A, const A> {
644struct promote_storage_type<const A, A> {
661template <
typename A,
typename B,
typename Functor>
662struct cwise_promote_storage_type;
664template <
typename A,
typename Functor>
665struct cwise_promote_storage_type<A, A, Functor> {
668template <
typename Functor>
669struct cwise_promote_storage_type<Dense, Dense, Functor> {
672template <
typename A,
typename Functor>
673struct cwise_promote_storage_type<A, Dense, Functor> {
676template <
typename B,
typename Functor>
677struct cwise_promote_storage_type<Dense, B, Functor> {
680template <
typename Functor>
681struct cwise_promote_storage_type<Sparse, Dense, Functor> {
684template <
typename Functor>
685struct cwise_promote_storage_type<Dense, Sparse, Functor> {
689template <
typename LhsKind,
typename RhsKind,
int LhsOrder,
int RhsOrder>
690struct cwise_promote_storage_order : std::integral_constant<int, LhsOrder> {};
692template <
typename LhsKind,
int LhsOrder,
int RhsOrder>
693struct cwise_promote_storage_order<LhsKind, Sparse, LhsOrder, RhsOrder> : std::integral_constant<int, RhsOrder> {};
694template <
typename RhsKind,
int LhsOrder,
int RhsOrder>
695struct cwise_promote_storage_order<Sparse, RhsKind, LhsOrder, RhsOrder> : std::integral_constant<int, LhsOrder> {};
697struct cwise_promote_storage_order<Sparse, Sparse, Order, Order> : std::integral_constant<int, Order> {};
713template <
typename A,
typename B,
int ProductTag>
714struct product_promote_storage_type;
716template <
typename A,
int ProductTag>
717struct product_promote_storage_type<A, A, ProductTag> {
720template <
int ProductTag>
721struct product_promote_storage_type<Dense, Dense, ProductTag> {
724template <
typename A,
int ProductTag>
725struct product_promote_storage_type<A, Dense, ProductTag> {
728template <
typename B,
int ProductTag>
729struct product_promote_storage_type<Dense, B, ProductTag> {
733template <
typename A,
int ProductTag>
734struct product_promote_storage_type<A, DiagonalShape, ProductTag> {
737template <
typename B,
int ProductTag>
738struct product_promote_storage_type<DiagonalShape, B, ProductTag> {
741template <
int ProductTag>
742struct product_promote_storage_type<Dense, DiagonalShape, ProductTag> {
745template <
int ProductTag>
746struct product_promote_storage_type<DiagonalShape, Dense, ProductTag> {
750template <
typename A,
int ProductTag>
751struct product_promote_storage_type<A, SkewSymmetricShape, ProductTag> {
754template <
typename B,
int ProductTag>
755struct product_promote_storage_type<SkewSymmetricShape, B, ProductTag> {
758template <
int ProductTag>
759struct product_promote_storage_type<Dense, SkewSymmetricShape, ProductTag> {
762template <
int ProductTag>
763struct product_promote_storage_type<SkewSymmetricShape, Dense, ProductTag> {
766template <
int ProductTag>
767struct product_promote_storage_type<SkewSymmetricShape, SkewSymmetricShape, ProductTag> {
772template <
int ProductTag>
773struct product_promote_storage_type<SkewSymmetricShape, DiagonalShape, ProductTag> {
776template <
int ProductTag>
777struct product_promote_storage_type<DiagonalShape, SkewSymmetricShape, ProductTag> {
781template <
typename A,
int ProductTag>
782struct product_promote_storage_type<A, PermutationStorage, ProductTag> {
785template <
typename B,
int ProductTag>
786struct product_promote_storage_type<PermutationStorage, B, ProductTag> {
789template <
int ProductTag>
790struct product_promote_storage_type<Dense, PermutationStorage, ProductTag> {
793template <
int ProductTag>
794struct product_promote_storage_type<PermutationStorage, Dense, ProductTag> {
801template <
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
802struct plain_row_type {
803 using MatrixRowType =
804 Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime, int(ExpressionType::PlainObject::Options) | int(
RowMajor), 1,
805 ExpressionType::MaxColsAtCompileTime>;
807 Array<Scalar, 1, ExpressionType::ColsAtCompileTime, int(ExpressionType::PlainObject::Options) | int(
RowMajor), 1,
808 ExpressionType::MaxColsAtCompileTime>;
810 using type = std::conditional_t<std::is_same<typename traits<ExpressionType>::XprKind, MatrixXpr>::value,
811 MatrixRowType, ArrayRowType>;
814template <
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
815struct plain_col_type {
816 using MatrixColType =
817 Matrix<Scalar, ExpressionType::RowsAtCompileTime, 1, ExpressionType::PlainObject::Options & ~RowMajor,
818 ExpressionType::MaxRowsAtCompileTime, 1>;
819 using ArrayColType = Array<Scalar, ExpressionType::RowsAtCompileTime, 1,
820 ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1>;
822 using type = std::conditional_t<std::is_same<typename traits<ExpressionType>::XprKind, MatrixXpr>::value,
823 MatrixColType, ArrayColType>;
826template <
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
827struct plain_diag_type {
828 static constexpr int diag_size =
829 internal::min_size_prefer_dynamic(ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime);
830 static constexpr int max_diag_size =
831 min_size_prefer_fixed(ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime);
832 using MatrixDiagType =
833 Matrix<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1>;
834 using ArrayDiagType = Array<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1>;
836 using type = std::conditional_t<std::is_same<typename traits<ExpressionType>::XprKind, MatrixXpr>::value,
837 MatrixDiagType, ArrayDiagType>;
840template <
typename Expr,
typename Scalar =
typename Expr::Scalar>
841struct plain_constant_type {
844 using array_type = Array<Scalar, traits<Expr>::RowsAtCompileTime, traits<Expr>::ColsAtCompileTime, Options,
845 traits<Expr>::MaxRowsAtCompileTime, traits<Expr>::MaxColsAtCompileTime>;
847 using matrix_type = Matrix<Scalar, traits<Expr>::RowsAtCompileTime, traits<Expr>::ColsAtCompileTime, Options,
848 traits<Expr>::MaxRowsAtCompileTime, traits<Expr>::MaxColsAtCompileTime>;
850 using type = CwiseNullaryOp<scalar_constant_op<Scalar>,
851 const std::conditional_t<std::is_same<typename traits<Expr>::XprKind, MatrixXpr>::value,
852 matrix_type, array_type>>;
855template <
typename ExpressionType>
856struct is_lvalue : bool_constant<(!bool(std::is_const<ExpressionType>::value)) &&
857 bool((traits<ExpressionType>::Flags & LvalueBit))> {};
860struct is_diagonal : std::false_type {};
863struct is_diagonal<DiagonalBase<T>> : std::true_type {};
866struct is_diagonal<DiagonalWrapper<T>> : std::true_type {};
868template <
typename T,
int S>
869struct is_diagonal<DiagonalMatrix<T, S>> : std::true_type {};
872struct is_identity : std::false_type {};
875struct is_identity<CwiseNullaryOp<internal::scalar_identity_op<typename T::Scalar>, T>> : std::true_type {};
877template <
typename S1,
typename S2>
880struct glue_shapes<DenseShape, TriangularShape> {
881 using type = TriangularShape;
884template <
typename T1,
typename T2>
885struct possibly_same_dense : bool_constant<has_direct_access<T1>::value && has_direct_access<T2>::value &&
886 std::is_same<typename T1::Scalar, typename T2::Scalar>::value> {};
888template <typename T1, typename T2, std::enable_if_t<possibly_same_dense<T1, T2>::value,
int> = 0>
889EIGEN_DEVICE_FUNC
bool is_same_dense(
const T1& mat1,
const T2& mat2) {
890 return (mat1.data() == mat2.data()) && (mat1.innerStride() == mat2.innerStride()) &&
891 (mat1.outerStride() == mat2.outerStride());
894template <typename T1, typename T2, std::enable_if_t<!possibly_same_dense<T1, T2>::value,
int> = 0>
895EIGEN_DEVICE_FUNC
bool is_same_dense(
const T1&,
const T2&) {
901template <
typename T,
bool Vectorized = false,
typename EnableIf =
void>
902struct scalar_div_cost : std::integral_constant<int, 8 * NumTraits<T>::MulCost> {};
904template <
typename T,
bool Vectorized>
905struct scalar_div_cost<T, Vectorized, std::enable_if_t<NumTraits<T>::IsComplex>>
906 : std::integral_constant<int, 2 * scalar_div_cost<typename NumTraits<T>::Real>::value +
907 6 * NumTraits<typename NumTraits<T>::Real>::MulCost +
908 3 * NumTraits<typename NumTraits<T>::Real>::AddCost> {};
910template <
bool Vectorized>
911struct scalar_div_cost<signed long, Vectorized, std::conditional_t<sizeof(long) == 8, void, std::false_type>>
912 : std::integral_constant<int, 24> {};
913template <
bool Vectorized>
914struct scalar_div_cost<unsigned long, Vectorized, std::conditional_t<sizeof(long) == 8, void, std::false_type>>
915 : std::integral_constant<int, 21> {};
917#ifdef EIGEN_DEBUG_ASSIGN
918std::string demangle_traversal(
int t) {
919 if (t == DefaultTraversal)
return "DefaultTraversal";
920 if (t == LinearTraversal)
return "LinearTraversal";
921 if (t == InnerVectorizedTraversal)
return "InnerVectorizedTraversal";
922 if (t == LinearVectorizedTraversal)
return "LinearVectorizedTraversal";
923 if (t == SliceVectorizedTraversal)
return "SliceVectorizedTraversal";
926std::string demangle_unrolling(
int t) {
927 if (t == NoUnrolling)
return "NoUnrolling";
928 if (t == InnerUnrolling)
return "InnerUnrolling";
929 if (t == CompleteUnrolling)
return "CompleteUnrolling";
932std::string demangle_flags(
int f) {
939 if (f & NestByRefBit) res +=
" | NestByRef";
946template <
typename XprType>
947struct is_block_xpr : std::false_type {};
949template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
950struct is_block_xpr<Block<XprType, BlockRows, BlockCols, InnerPanel>> : std::true_type {};
952template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
953struct is_block_xpr<const Block<XprType, BlockRows, BlockCols, InnerPanel>> : std::true_type {};
956template <
typename XprType>
957struct block_xpr_helper {
958 using BaseType = XprType;
962 static constexpr bool is_inner_panel(
bool inner_panel) {
return inner_panel; }
965 template <typename T = XprType, typename EnableIf = std::enable_if_t<!std::is_const<T>::value>>
966 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BaseType& base(XprType& xpr) {
969 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
const BaseType& base(
const XprType& xpr) {
return xpr; }
970 static constexpr EIGEN_ALWAYS_INLINE Index row(
const XprType& , Index r) {
return r; }
971 static constexpr EIGEN_ALWAYS_INLINE Index col(
const XprType& , Index c) {
return c; }
974template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
975struct block_xpr_helper<Block<XprType, BlockRows, BlockCols, InnerPanel>> {
976 using BlockXprType = Block<XprType, BlockRows, BlockCols, InnerPanel>;
978 using NestedXprHelper = block_xpr_helper<XprType>;
979 using BaseType =
typename NestedXprHelper::BaseType;
983 static constexpr bool is_inner_panel(
bool inner_panel) {
984 return NestedXprHelper::is_inner_panel(InnerPanel && inner_panel);
988 template <typename T = XprType, typename EnableIf = std::enable_if_t<!std::is_const<T>::value>>
989 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE BaseType& base(BlockXprType& xpr) {
990 return NestedXprHelper::base(xpr.nestedExpression());
992 static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
const BaseType& base(
const BlockXprType& xpr) {
993 return NestedXprHelper::base(xpr.nestedExpression());
995 static constexpr EIGEN_ALWAYS_INLINE Index row(
const BlockXprType& xpr, Index r) {
996 return xpr.startRow() + NestedXprHelper::row(xpr.nestedExpression(), r);
998 static constexpr EIGEN_ALWAYS_INLINE Index col(
const BlockXprType& xpr, Index c) {
999 return xpr.startCol() + NestedXprHelper::col(xpr.nestedExpression(), c);
1003template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1004struct block_xpr_helper<const Block<XprType, BlockRows, BlockCols, InnerPanel>>
1005 : block_xpr_helper<Block<XprType, BlockRows, BlockCols, InnerPanel>> {};
1007template <
typename XprType>
1008struct is_matrix_base_xpr : std::is_base_of<MatrixBase<remove_all_t<XprType>>, remove_all_t<XprType>> {};
1010template <
typename XprType>
1011struct is_permutation_base_xpr : std::is_base_of<PermutationBase<remove_all_t<XprType>>, remove_all_t<XprType>> {};
1074template <
typename ScalarA,
typename ScalarB,
typename BinaryOp =
internal::scalar_product_op<ScalarA, ScalarB>>
1076#ifndef EIGEN_PARSED_BY_DOXYGEN
1078 : internal::scalar_product_traits<ScalarA, ScalarB>
1083template <
typename T,
typename BinaryOp>
1085 using ReturnType = T;
1088template <
typename T,
typename BinaryOp>
1089struct ScalarBinaryOpTraits<T, typename NumTraits<std::enable_if_t<NumTraits<T>::IsComplex, T>>::Real, BinaryOp> {
1090 using ReturnType = T;
1092template <
typename T,
typename BinaryOp>
1094 using ReturnType = T;
1098template <
typename T,
typename BinaryOp>
1100 using ReturnType = T;
1104template <
typename T,
typename BinaryOp>
1106 using ReturnType = T;
1110template <
typename BinaryOp>
1112 using ReturnType = void;
1119#define EIGEN_CHECK_BINARY_COMPATIBILITY(BINOP, LHS, RHS) \
1120 EIGEN_STATIC_ASSERT( \
1121 (Eigen::internal::has_ReturnType<ScalarBinaryOpTraits<LHS, RHS, BINOP>>::value), \
1122 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
1127template <
typename T,
typename Derived,
typename XprKind>
1128struct has_generic_scalar_binary_ops
1129 : bool_constant<std::is_same<XprKind, ArrayXpr>::value
1130 ? std::is_convertible<const remove_all_t<T>*, const ArrayBase<Derived>*>::value
1131 : (std::is_convertible<const remove_all_t<T>*, const MatrixBase<Derived>*>::value ||
1132 std::is_convertible<const remove_all_t<T>*, const SparseMatrixBase<Derived>*>::value)> {};
1134namespace scalar_pow_adl {
1137template <
bool Inspect,
typename Lhs,
typename Rhs,
typename =
void>
1138struct is_supported : std::false_type {};
1139template <
typename Lhs,
typename Rhs>
1140struct is_supported<true, Lhs, Rhs,
1141 void_t<typename ScalarBinaryOpTraits<Lhs, Rhs, scalar_pow_op<Lhs, Rhs>>::ReturnType,
1142 decltype(pow(std::declval<const Lhs&>(), std::declval<const Rhs&>()))>>
1143 : std::is_convertible<decltype(pow(std::declval<const Lhs&>(), std::declval<const Rhs&>())),
1144 typename ScalarBinaryOpTraits<Lhs, Rhs, scalar_pow_op<Lhs, Rhs>>::ReturnType> {};
1147template <
typename Scalar,
typename T,
template <
typename,
typename>
class BinaryOp,
bool ScalarOnLeft>
1148using scalar_expression_binary_traits =
1149 std::conditional_t<ScalarOnLeft, ScalarBinaryOpTraits<T, Scalar, BinaryOp<T, Scalar>>,
1150 ScalarBinaryOpTraits<Scalar, T, BinaryOp<Scalar, T>>>;
1152template <
typename Expr,
typename T,
template <
typename,
typename>
class BinaryOp,
bool ScalarOnLeft,
typename =
void>
1153struct has_competing_expression_binary_op : std::false_type {};
1155template <
typename Expr,
typename T,
template <
typename,
typename>
class BinaryOp,
bool ScalarOnLeft>
1156struct has_competing_expression_binary_op<
1157 Expr, T, BinaryOp, ScalarOnLeft,
1158 void_t<decltype(std::declval<const T&>().derived()), typename traits<typename shape_expression<T>::type>::Scalar,
1159 typename traits<typename shape_expression<T>::type>::XprKind,
1160 decltype(traits<typename shape_expression<T>::type>::RowsAtCompileTime),
1161 decltype(traits<typename shape_expression<T>::type>::ColsAtCompileTime),
1162 typename scalar_expression_binary_traits<typename traits<Expr>::Scalar, T, BinaryOp,
1163 ScalarOnLeft>::ReturnType>> {
1164 using Other =
typename shape_expression<T>::type;
1165 using Scalar =
typename traits<Expr>::Scalar;
1166 using XprKind =
typename traits<Expr>::XprKind;
1167 using Lhs = std::conditional_t<ScalarOnLeft, Other, Expr>;
1168 using Rhs = std::conditional_t<ScalarOnLeft, Expr, Other>;
1169 using LhsScalar =
typename traits<Lhs>::Scalar;
1170 using RhsScalar =
typename traits<Rhs>::Scalar;
1171 using LhsShape = compile_time_shape<Lhs>;
1172 using RhsShape = compile_time_shape<Rhs>;
1173 using Op = BinaryOp<LhsScalar, RhsScalar>;
1174 static constexpr bool IsArray = std::is_same<XprKind, ArrayXpr>::value;
1175 static constexpr bool HasExpressionOverload = has_generic_scalar_binary_ops<Expr, Expr, XprKind>::value &&
1176 has_generic_scalar_binary_ops<T, Other, XprKind>::value;
1177 static constexpr bool ProductSizeMatches =
1178 dimension_relation<LhsShape::Cols, RhsShape::Rows, LhsShape::MaxCols, RhsShape::MaxRows>::Compatible;
1179 static constexpr bool ArraySizeMatches =
1180 dimension_relation<LhsShape::Rows, RhsShape::Rows, LhsShape::MaxRows, RhsShape::MaxRows>::Compatible &&
1181 dimension_relation<LhsShape::Cols, RhsShape::Cols, LhsShape::MaxCols, RhsShape::MaxCols>::Compatible;
1182 using OppositeLhs = std::conditional_t<ScalarOnLeft, typename traits<Other>::Scalar, Expr>;
1183 using OppositeRhs = std::conditional_t<ScalarOnLeft, Expr, typename traits<Other>::Scalar>;
1186 static constexpr bool HasOppositeScalarOverload =
1187 has_ReturnType<ScalarBinaryOpTraits<OppositeLhs, OppositeRhs, BinaryOp<OppositeLhs, OppositeRhs>>>::value;
1189 static constexpr bool Competing = HasExpressionOverload && !is_eigen_expression<Scalar>::value &&
1190 std::is_same<XprKind, typename traits<Other>::XprKind>::value &&
1191 (IsArray ? ArraySizeMatches : ProductSizeMatches) &&
1192 (IsArray || std::is_same<Op, scalar_product_op<LhsScalar, RhsScalar>>::value) &&
1193 has_ReturnType<ScalarBinaryOpTraits<LhsScalar, RhsScalar, Op>>::value;
1194 static constexpr bool IsPow = std::is_same<Op, scalar_pow_op<LhsScalar, RhsScalar>>::value;
1195 using ScalarLhs = std::conditional_t<ScalarOnLeft, T, Scalar>;
1196 using ScalarRhs = std::conditional_t<ScalarOnLeft, Scalar, T>;
1197 using ScalarPower = scalar_pow_adl::is_supported<(Competing && IsPow), ScalarLhs, ScalarRhs>;
1198 static constexpr bool value = Competing && (IsPow ? !ScalarPower::value : HasOppositeScalarOverload);
1201template <
typename T>
1202using expression_binary_base_t =
typename shape_expression<T>::type::StorageBaseType;
1206template <
typename Lhs,
typename Rhs,
template <
typename,
typename>
class BinaryOp,
typename OwnerBase,
typename =
void>
1207struct has_ambiguous_expression_binary_op : std::false_type {};
1209template <
typename Lhs,
typename Rhs,
template <
typename,
typename>
class BinaryOp,
typename OwnerBase>
1210struct has_ambiguous_expression_binary_op<Lhs, Rhs, BinaryOp, OwnerBase,
1211 void_t<expression_binary_base_t<Lhs>, expression_binary_base_t<Rhs>>>
1213 std::is_same<OwnerBase, expression_binary_base_t<Rhs>>::value &&
1214 std::is_convertible<const Rhs*, const OwnerBase*>::value &&
1215 !std::is_same<remove_all_t<Lhs>, expression_binary_base_t<Lhs>>::value &&
1216 !std::is_same<remove_all_t<Rhs>, expression_binary_base_t<Rhs>>::value &&
1217 has_competing_expression_binary_op<typename shape_expression<Lhs>::type, Rhs, BinaryOp, false>::value &&
1218 has_competing_expression_binary_op<typename shape_expression<Rhs>::type, Lhs, BinaryOp, true>::value> {
1219 static constexpr bool DenseSparse =
1220 std::is_same<typename traits<typename shape_expression<Lhs>::type>::StorageKind, Dense>::value &&
1221 std::is_same<typename traits<typename shape_expression<Rhs>::type>::StorageKind, Sparse>::value;
1224template <
template <
typename,
typename>
class BinaryOp,
bool DenseSparse>
1225struct expression_binary_op {
1226 template <
typename Lhs,
typename Rhs>
1227 EIGEN_DEVICE_FUNC
static constexpr EIGEN_STRONG_INLINE
auto run(
const Lhs& lhs,
const Rhs& rhs)
1228 -> CwiseBinaryOp<BinaryOp<typename Lhs::Scalar, typename Rhs::Scalar>,
const typename shape_expression<Lhs>::type,
1229 const typename shape_expression<Rhs>::type> {
1230 return {lhs.derived(), rhs.derived()};
1235struct expression_binary_op<scalar_product_op, false> {
1236 template <
typename Lhs,
typename Rhs>
1237 EIGEN_DEVICE_FUNC
static constexpr EIGEN_STRONG_INLINE
auto run(
const Lhs& lhs,
const Rhs& rhs)
1238 ->
decltype(lhs.operator*(rhs)) {
1239 return lhs.operator*(rhs);
1244struct expression_binary_op<scalar_product_op, true> {
1245 template <
typename Lhs,
typename Rhs>
1246 EIGEN_DEVICE_FUNC
static constexpr EIGEN_STRONG_INLINE
auto run(
const Lhs& lhs,
const Rhs& rhs)
1247 ->
decltype(operator*(lhs, rhs)) {
1248 return operator*(lhs, rhs);
@ ColMajor
Definition Constants.h:319
@ RowMajor
Definition Constants.h:321
@ AutoAlign
Definition Constants.h:323
constexpr unsigned int NoPreferredStorageOrderBit
Definition Constants.h:183
constexpr unsigned int PacketAccessBit
Definition Constants.h:98
constexpr unsigned int DirectAccessBit
Definition Constants.h:160
constexpr unsigned int EvalBeforeNestingBit
Definition Constants.h:75
constexpr unsigned int LinearAccessBit
Definition Constants.h:134
constexpr unsigned int LvalueBit
Definition Constants.h:149
constexpr unsigned int RowMajorBit
Definition Constants.h:71
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:267
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition XprHelper.h:1080