11 #ifndef EIGEN_XPRHELPER_H
12 #define EIGEN_XPRHELPER_H
14 #include "../InternalHeaderCheck.h"
22 template <
typename IndexType>
24 const IndexType& idx) {
27 using UnsignedType =
typename make_unsigned<IndexType>::type;
28 return static_cast<UnsignedType
>(idx);
31 template <
typename IndexDest,
typename IndexSrc,
36 struct convert_index_impl {
39 return static_cast<IndexDest
>(idx);
42 template <
typename IndexDest,
typename IndexSrc>
43 struct convert_index_impl<IndexDest, IndexSrc, true, true, true, false> {
48 "Index value is too big for target type");
49 return static_cast<IndexDest
>(idx);
52 template <
typename IndexDest,
typename IndexSrc>
53 struct convert_index_impl<IndexDest, IndexSrc, true, false, true, true> {
58 "Index value is too big for target type");
59 return static_cast<IndexDest
>(idx);
63 template <
typename IndexDest,
typename IndexSrc>
65 return convert_index_impl<IndexDest, IndexSrc>::run(idx);
69 template<
typename T>
struct is_valid_index_type
71 enum { value = internal::is_integral<T>::value || std::is_enum<T>::value
76 template<
typename RowIndices,
typename ColIndices>
77 struct valid_indexed_view_overload {
78 enum { value = !(internal::is_valid_index_type<RowIndices>::value && internal::is_valid_index_type<ColIndices>::value) };
90 template<
typename ExprScalar,
typename T,
bool IsSupported>
91 struct promote_scalar_arg;
93 template<
typename S,
typename T>
94 struct promote_scalar_arg<S,
T,true>
100 template<
typename ExprScalar,
typename T,
typename PromotedType,
101 bool ConvertibleToLiteral = internal::is_convertible<T,PromotedType>::value,
103 struct promote_scalar_arg_unsupported;
106 template<
typename S,
typename T>
107 struct promote_scalar_arg<S,
T,false> : promote_scalar_arg_unsupported<S,T,typename NumTraits<S>::Literal> {};
110 template<
typename S,
typename T,
typename PromotedType>
111 struct promote_scalar_arg_unsupported<S,
T,PromotedType,true,true>
113 typedef PromotedType type;
118 template<
typename ExprScalar,
typename T,
typename PromotedType>
119 struct promote_scalar_arg_unsupported<ExprScalar,
T,PromotedType,false,true>
120 : promote_scalar_arg_unsupported<ExprScalar,T,ExprScalar>
124 template<
typename S,
typename T,
typename PromotedType,
bool ConvertibleToLiteral>
125 struct promote_scalar_arg_unsupported<S,
T,PromotedType,ConvertibleToLiteral,false> {};
128 template<
typename S,
typename T>
129 struct promote_scalar_arg_unsupported<S,
T,S,false,true> {};
132 class no_assignment_operator
135 no_assignment_operator& operator=(
const no_assignment_operator&);
142 template<
typename I1,
typename I2>
143 struct promote_index_type
145 typedef std::conditional_t<(
sizeof(I1)<
sizeof(I2)), I2, I1> type;
152 template<
typename T,
int Value>
class variable_if_dynamic
158 T value() {
return T(Value); }
160 operator T()
const {
return T(Value); }
165 template<
typename T>
class variable_if_dynamic<
T,
Dynamic>
177 template<
typename T,
int Value>
class variable_if_dynamicindex
182 T value() {
return T(Value); }
187 template<
typename T>
class variable_if_dynamicindex<
T,
DynamicIndex>
192 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit variable_if_dynamicindex(
T value) : m_value(value) {}
197 template<
typename T>
struct functor_traits
202 PacketAccess =
false,
207 template<
typename T>
struct packet_traits;
209 template<
typename T>
struct unpacket_traits;
211 template<
int Size,
typename PacketType,
213 struct find_best_packet_helper;
215 template<
int Size,
typename PacketType>
216 struct find_best_packet_helper<Size,PacketType,true>
218 typedef PacketType type;
221 template<
int Size,
typename PacketType>
222 struct find_best_packet_helper<Size,PacketType,false>
224 typedef typename find_best_packet_helper<Size,typename unpacket_traits<PacketType>::half>::type type;
227 template<
typename T,
int Size>
228 struct find_best_packet
230 typedef typename find_best_packet_helper<Size,typename packet_traits<T>::type>::type type;
233 template <
int Size,
typename PacketType,
235 is_same<PacketType,
typename unpacket_traits<PacketType>::half>::value>
236 struct find_packet_by_size_helper;
237 template <
int Size,
typename PacketType>
238 struct find_packet_by_size_helper<Size, PacketType, true> {
239 using type = PacketType;
241 template <
int Size,
typename PacketType>
242 struct find_packet_by_size_helper<Size, PacketType, false> {
243 using type =
typename find_packet_by_size_helper<Size, typename unpacket_traits<PacketType>::half>::type;
246 template <
typename T,
int Size>
247 struct find_packet_by_size {
248 using type =
typename find_packet_by_size_helper<Size, typename packet_traits<T>::type>::type;
251 template <
typename T>
252 struct find_packet_by_size<
T, 1> {
253 using type =
typename unpacket_traits<T>::type;
257 #if EIGEN_MAX_STATIC_ALIGN_BYTES>0
259 if((ArrayBytes % AlignmentBytes) == 0) {
260 return AlignmentBytes;
277 template<
typename T,
int Size>
struct compute_default_alignment {
281 template<
typename T>
struct compute_default_alignment<
T,
Dynamic> {
285 template<
typename Scalar_,
int Rows_,
int Cols_,
290 int MaxRows_ = Rows_,
292 >
class make_proper_matrix_type
295 IsColVector = Cols_==1 && Rows_!=1,
296 IsRowVector = Rows_==1 && Cols_!=1,
302 typedef Matrix<Scalar_, Rows_, Cols_, Options, MaxRows_, MaxCols_> type;
314 if (
rows == 0 ||
cols == 0)
return 0;
319 template<
typename XprType>
struct size_of_xpr_at_compile_time
321 enum { ret =
size_at_compile_time(traits<XprType>::RowsAtCompileTime, traits<XprType>::ColsAtCompileTime) };
328 template<typename T, typename StorageKind = typename traits<T>::StorageKind>
struct plain_matrix_type;
329 template<
typename T,
typename BaseClassType,
int Flags>
struct plain_matrix_type_dense;
330 template<
typename T>
struct plain_matrix_type<
T,Dense>
332 typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind, traits<T>::Flags>::type type;
334 template<
typename T>
struct plain_matrix_type<
T,DiagonalShape>
336 typedef typename T::PlainObject type;
339 template<
typename T>
struct plain_matrix_type<
T,SkewSymmetricShape>
341 typedef typename T::PlainObject type;
344 template<
typename T,
int Flags>
struct plain_matrix_type_dense<
T,MatrixXpr,Flags>
347 traits<T>::RowsAtCompileTime,
348 traits<T>::ColsAtCompileTime,
350 traits<T>::MaxRowsAtCompileTime,
351 traits<T>::MaxColsAtCompileTime
355 template<
typename T,
int Flags>
struct plain_matrix_type_dense<
T,ArrayXpr,Flags>
358 traits<T>::RowsAtCompileTime,
359 traits<T>::ColsAtCompileTime,
361 traits<T>::MaxRowsAtCompileTime,
362 traits<T>::MaxColsAtCompileTime
370 template<typename T, typename StorageKind = typename traits<T>::StorageKind>
struct eval;
372 template<
typename T>
struct eval<
T,Dense>
374 typedef typename plain_matrix_type<T>::type type;
385 template<
typename T>
struct eval<
T,DiagonalShape>
387 typedef typename plain_matrix_type<T>::type type;
390 template<
typename T>
struct eval<
T,SkewSymmetricShape>
392 typedef typename plain_matrix_type<T>::type type;
396 template<
typename Scalar_,
int Rows_,
int Cols_,
int Options_,
int MaxRows_,
int MaxCols_>
397 struct eval<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>, Dense>
399 typedef const Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>& type;
402 template<
typename Scalar_,
int Rows_,
int Cols_,
int Options_,
int MaxRows_,
int MaxCols_>
403 struct eval<Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>, Dense>
405 typedef const Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>& type;
410 template<typename T, typename StorageKind = typename traits<T>::StorageKind>
struct plain_object_eval;
413 struct plain_object_eval<
T,Dense>
415 typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind, evaluator<T>::Flags>::type type;
421 template<
typename T>
struct plain_matrix_type_column_major
423 enum { Rows = traits<T>::RowsAtCompileTime,
424 Cols = traits<T>::ColsAtCompileTime,
425 MaxRows = traits<T>::MaxRowsAtCompileTime,
426 MaxCols = traits<T>::MaxColsAtCompileTime
439 template<
typename T>
struct plain_matrix_type_row_major
441 enum { Rows = traits<T>::RowsAtCompileTime,
442 Cols = traits<T>::ColsAtCompileTime,
443 MaxRows = traits<T>::MaxRowsAtCompileTime,
444 MaxCols = traits<T>::MaxColsAtCompileTime
458 template <
typename T>
461 typedef std::conditional_t<
467 typedef std::conditional_t<
475 template<
typename T1,
typename T2>
476 struct transfer_constness
478 typedef std::conditional_t<
479 bool(internal::is_const<T1>::value),
480 add_const_on_value_type_t<T2>,
500 template<typename T, int n, typename PlainObject = typename plain_object_eval<T>::type>
struct nested_eval
503 ScalarReadCost = NumTraits<typename traits<T>::Scalar>::ReadCost,
504 CoeffReadCost = evaluator<T>::CoeffReadCost,
510 CostEval = (NAsInteger+1) * ScalarReadCost + CoeffReadCost,
511 CostNoEval = NAsInteger * CoeffReadCost,
512 Evaluate = (
int(evaluator<T>::Flags) &
EvalBeforeNestingBit) || (
int(CostEval) < int(CostNoEval))
515 typedef std::conditional_t<Evaluate, PlainObject, typename ref_selector<T>::type> type;
522 return const_cast<T*
>(ptr);
525 template<typename Derived, typename XprKind = typename traits<Derived>::XprKind>
526 struct dense_xpr_base
531 template<
typename Derived>
532 struct dense_xpr_base<Derived, MatrixXpr>
534 typedef MatrixBase<Derived> type;
537 template<
typename Derived>
538 struct dense_xpr_base<Derived, ArrayXpr>
540 typedef ArrayBase<Derived> type;
543 template<typename Derived, typename XprKind = typename traits<Derived>::XprKind,
typename StorageKind =
typename traits<Derived>::StorageKind>
544 struct generic_xpr_base;
546 template<
typename Derived,
typename XprKind>
547 struct generic_xpr_base<Derived, XprKind, Dense>
549 typedef typename dense_xpr_base<Derived,XprKind>::type type;
552 template<
typename XprType,
typename CastType>
struct cast_return_type
554 typedef typename XprType::Scalar CurrentScalarType;
555 typedef remove_all_t<CastType> CastType_;
556 typedef typename CastType_::Scalar NewScalarType;
557 typedef std::conditional_t<is_same<CurrentScalarType,NewScalarType>::value,
558 const XprType&,CastType> type;
561 template <
typename A,
typename B>
struct promote_storage_type;
563 template <
typename A>
struct promote_storage_type<
A,
A>
567 template <
typename A>
struct promote_storage_type<
A, const
A>
571 template <
typename A>
struct promote_storage_type<const
A,
A>
589 template <
typename A,
typename B,
typename Functor>
struct cwise_promote_storage_type;
591 template <
typename A,
typename Functor>
struct cwise_promote_storage_type<
A,
A,Functor> {
typedef A ret; };
592 template <
typename Functor>
struct cwise_promote_storage_type<Dense,Dense,Functor> {
typedef Dense ret; };
593 template <
typename A,
typename Functor>
struct cwise_promote_storage_type<
A,Dense,Functor> {
typedef Dense ret; };
594 template <
typename B,
typename Functor>
struct cwise_promote_storage_type<Dense,
B,Functor> {
typedef Dense ret; };
595 template <
typename Functor>
struct cwise_promote_storage_type<Sparse,Dense,Functor> {
typedef Sparse ret; };
596 template <
typename Functor>
struct cwise_promote_storage_type<Dense,Sparse,Functor> {
typedef Sparse ret; };
598 template <
typename LhsKind,
typename RhsKind,
int LhsOrder,
int RhsOrder>
struct cwise_promote_storage_order {
599 enum { value = LhsOrder };
602 template <
typename LhsKind,
int LhsOrder,
int RhsOrder>
struct cwise_promote_storage_order<LhsKind,Sparse,LhsOrder,RhsOrder> {
enum { value = RhsOrder }; };
603 template <
typename RhsKind,
int LhsOrder,
int RhsOrder>
struct cwise_promote_storage_order<Sparse,RhsKind,LhsOrder,RhsOrder> {
enum { value = LhsOrder }; };
604 template <
int Order>
struct cwise_promote_storage_order<Sparse,Sparse,Order,Order> {
enum { value = Order }; };
621 template <
typename A,
typename B,
int ProductTag>
struct product_promote_storage_type;
623 template <
typename A,
int ProductTag>
struct product_promote_storage_type<
A,
A, ProductTag> {
typedef A ret;};
624 template <
int ProductTag>
struct product_promote_storage_type<Dense, Dense, ProductTag> {
typedef Dense ret;};
625 template <
typename A,
int ProductTag>
struct product_promote_storage_type<
A, Dense, ProductTag> {
typedef Dense ret; };
626 template <
typename B,
int ProductTag>
struct product_promote_storage_type<Dense,
B, ProductTag> {
typedef Dense ret; };
628 template <
typename A,
int ProductTag>
struct product_promote_storage_type<
A, DiagonalShape, ProductTag> {
typedef A ret; };
629 template <
typename B,
int ProductTag>
struct product_promote_storage_type<DiagonalShape,
B, ProductTag> {
typedef B ret; };
630 template <
int ProductTag>
struct product_promote_storage_type<Dense, DiagonalShape, ProductTag> {
typedef Dense ret; };
631 template <
int ProductTag>
struct product_promote_storage_type<DiagonalShape, Dense, ProductTag> {
typedef Dense ret; };
633 template <
typename A,
int ProductTag>
struct product_promote_storage_type<
A, SkewSymmetricShape, ProductTag> {
typedef A ret; };
634 template <
typename B,
int ProductTag>
struct product_promote_storage_type<SkewSymmetricShape,
B, ProductTag> {
typedef B ret; };
635 template <
int ProductTag>
struct product_promote_storage_type<Dense, SkewSymmetricShape, ProductTag> {
typedef Dense ret; };
636 template <
int ProductTag>
struct product_promote_storage_type<SkewSymmetricShape, Dense, ProductTag> {
typedef Dense ret; };
637 template <
int ProductTag>
struct product_promote_storage_type<SkewSymmetricShape, SkewSymmetricShape, ProductTag> {
typedef Dense ret; };
639 template <
typename A,
int ProductTag>
struct product_promote_storage_type<
A, PermutationStorage, ProductTag> {
typedef A ret; };
640 template <
typename B,
int ProductTag>
struct product_promote_storage_type<PermutationStorage,
B, ProductTag> {
typedef B ret; };
641 template <
int ProductTag>
struct product_promote_storage_type<Dense, PermutationStorage, ProductTag> {
typedef Dense ret; };
642 template <
int ProductTag>
struct product_promote_storage_type<PermutationStorage, Dense, ProductTag> {
typedef Dense ret; };
647 template<
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
648 struct plain_row_type
650 typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime,
651 int(ExpressionType::PlainObject::Options) | int(
RowMajor), 1, ExpressionType::MaxColsAtCompileTime> MatrixRowType;
652 typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime,
653 int(ExpressionType::PlainObject::Options) | int(
RowMajor), 1, ExpressionType::MaxColsAtCompileTime> ArrayRowType;
655 typedef std::conditional_t<
656 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
662 template<
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
663 struct plain_col_type
665 typedef Matrix<Scalar, ExpressionType::RowsAtCompileTime, 1,
666 ExpressionType::PlainObject::Options & ~
RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> MatrixColType;
667 typedef Array<Scalar, ExpressionType::RowsAtCompileTime, 1,
668 ExpressionType::PlainObject::Options & ~
RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> ArrayColType;
670 typedef std::conditional_t<
671 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
677 template<
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
678 struct plain_diag_type
682 ExpressionType::MaxColsAtCompileTime)
684 typedef Matrix<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> MatrixDiagType;
685 typedef Array<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> ArrayDiagType;
687 typedef std::conditional_t<
688 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
694 template<
typename Expr,
typename Scalar =
typename Expr::Scalar>
695 struct plain_constant_type
700 Options, traits<Expr>::MaxRowsAtCompileTime,traits<Expr>::MaxColsAtCompileTime> array_type;
703 Options, traits<Expr>::MaxRowsAtCompileTime,traits<Expr>::MaxColsAtCompileTime> matrix_type;
705 typedef CwiseNullaryOp<scalar_constant_op<Scalar>,
const std::conditional_t<is_same< typename traits<Expr>::XprKind, MatrixXpr >::value, matrix_type, array_type> > type;
708 template<
typename ExpressionType>
711 enum { value = (!
bool(is_const<ExpressionType>::value)) &&
712 bool(traits<ExpressionType>::Flags &
LvalueBit) };
715 template<
typename T>
struct is_diagonal
716 {
enum { ret =
false }; };
718 template<
typename T>
struct is_diagonal<DiagonalBase<
T> >
719 {
enum { ret =
true }; };
721 template<
typename T>
struct is_diagonal<DiagonalWrapper<
T> >
722 {
enum { ret =
true }; };
724 template<
typename T,
int S>
struct is_diagonal<DiagonalMatrix<
T,S> >
725 {
enum { ret =
true }; };
728 template<
typename T>
struct is_identity
729 {
enum { value =
false }; };
731 template<
typename T>
struct is_identity<CwiseNullaryOp<
internal::scalar_identity_op<typename T::Scalar>,
T> >
732 {
enum { value =
true }; };
735 template<
typename S1,
typename S2>
struct glue_shapes;
736 template<>
struct glue_shapes<DenseShape,TriangularShape> {
typedef TriangularShape type; };
738 template<
typename T1,
typename T2>
739 struct possibly_same_dense {
740 enum { value = has_direct_access<T1>::ret && has_direct_access<T2>::ret && is_same<typename T1::Scalar,typename T2::Scalar>::value };
743 template<
typename T1,
typename T2>
745 bool is_same_dense(
const T1 &
mat1,
const T2 &mat2, std::enable_if_t<possibly_same_dense<T1,T2>::value> * = 0)
747 return (
mat1.data()==mat2.data()) && (
mat1.innerStride()==mat2.innerStride()) && (
mat1.outerStride()==mat2.outerStride());
750 template<
typename T1,
typename T2>
752 bool is_same_dense(
const T1 &,
const T2 &, std::enable_if_t<!possibly_same_dense<T1,T2>::value> * = 0)
759 template<
typename T,
bool Vectorized=false,
typename EnableIf =
void>
760 struct scalar_div_cost {
764 template<
typename T,
bool Vectorized>
765 struct scalar_div_cost<
std::complex<T>, Vectorized> {
766 enum { value = 2*scalar_div_cost<T>::value
773 template<
bool Vectorized>
774 struct scalar_div_cost<signed long,Vectorized,
std::conditional_t<sizeof(long)==8,void,false_type>> {
enum { value = 24 }; };
775 template<
bool Vectorized>
776 struct scalar_div_cost<unsigned long,Vectorized,
std::conditional_t<sizeof(long)==8,void,false_type>> {
enum { value = 21 }; };
779 #ifdef EIGEN_DEBUG_ASSIGN
780 std::string demangle_traversal(
int t)
789 std::string demangle_unrolling(
int t)
796 std::string demangle_flags(
int f)
850 template<
typename ScalarA,
typename ScalarB,
typename BinaryOp=
internal::scalar_product_op<ScalarA,ScalarB> >
852 #ifndef EIGEN_PARSED_BY_DOXYGEN
854 : internal::scalar_product_traits<ScalarA,ScalarB>
858 template<
typename T,
typename BinaryOp>
864 template <
typename T,
typename BinaryOp>
869 template <
typename T,
typename BinaryOp>
876 template<
typename T,
typename BinaryOp>
883 template<
typename T,
typename BinaryOp>
890 template<
typename BinaryOp>
900 #define EIGEN_CHECK_BINARY_COMPATIBILIY(BINOP,LHS,RHS) \
901 EIGEN_STATIC_ASSERT((Eigen::internal::has_ReturnType<ScalarBinaryOpTraits<LHS, RHS,BINOP> >::value), \
902 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
Array< int, Dynamic, 1 > v
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
#define eigen_internal_assert(x)
#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived)
#define EIGEN_UNUSED_VARIABLE(var)
#define EIGEN_DEVICE_FUNC
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define EIGEN_STATIC_ASSERT(X, MSG)
MatrixXd mat1(size, size)
Eigen::Triplet< double > T
internal::traits< Matrix< Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_ > >::Scalar Scalar
const unsigned int PacketAccessBit
const unsigned int NoPreferredStorageOrderBit
const unsigned int LinearAccessBit
const unsigned int EvalBeforeNestingBit
const unsigned int DirectAccessBit
const unsigned int LvalueBit
const unsigned int RowMajorBit
constexpr unsigned compute_matrix_flags(int Options)
constexpr int size_at_compile_time(int rows, int cols)
make_unsigned< IndexType >::type returnUnsignedIndexValue(const IndexType &idx)
constexpr int min_size_prefer_fixed(A a, B b)
T * const_cast_ptr(const T *ptr)
IndexDest convert_index(const IndexSrc &idx)
bool is_same_dense(const T1 &mat1, const T2 &mat2, std::enable_if_t< possibly_same_dense< T1, T2 >::value > *=0)
constexpr int min_size_prefer_dynamic(A a, B b)
constexpr int compute_default_alignment_helper(int ArrayBytes, int AlignmentBytes)
const unsigned int NestByRefBit
@ InnerVectorizedTraversal
@ LinearVectorizedTraversal
@ SliceVectorizedTraversal
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...