11 #ifndef EIGEN_XPRHELPER_H 12 #define EIGEN_XPRHELPER_H 17 #if EIGEN_COMP_GNUC && !EIGEN_GNUC_AT(4,3) 18 #define EIGEN_EMPTY_STRUCT_CTOR(X) \ 19 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE X() {} \ 20 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE X(const X& ) {} 22 #define EIGEN_EMPTY_STRUCT_CTOR(X) 27 typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex;
35 typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE
Index;
39 template<
typename IndexDest,
typename IndexSrc>
41 inline IndexDest convert_index(
const IndexSrc& idx) {
44 return IndexDest(idx);
57 template<
typename ExprScalar,
typename T,
bool IsSupported>
58 struct promote_scalar_arg;
60 template<
typename S,
typename T>
61 struct promote_scalar_arg<S,T,true>
67 template<
typename ExprScalar,
typename T,
typename PromotedType,
68 bool ConvertibleToLiteral = internal::is_convertible<T,PromotedType>::value,
70 struct promote_scalar_arg_unsupported;
73 template<
typename S,
typename T>
74 struct promote_scalar_arg<S,T,false> : promote_scalar_arg_unsupported<S,T,typename NumTraits<S>::Literal> {};
77 template<
typename S,
typename T,
typename PromotedType>
78 struct promote_scalar_arg_unsupported<S,T,PromotedType,true,true>
80 typedef PromotedType type;
85 template<
typename ExprScalar,
typename T,
typename PromotedType>
86 struct promote_scalar_arg_unsupported<ExprScalar,T,PromotedType,false,true>
87 : promote_scalar_arg_unsupported<ExprScalar,T,ExprScalar>
91 template<
typename S,
typename T,
typename PromotedType,
bool ConvertibleToLiteral>
92 struct promote_scalar_arg_unsupported<S,T,PromotedType,ConvertibleToLiteral,false> {};
95 template<
typename S,
typename T>
96 struct promote_scalar_arg_unsupported<S,T,S,false,true> {};
99 class no_assignment_operator
102 no_assignment_operator& operator=(
const no_assignment_operator&);
106 template<
typename I1,
typename I2>
107 struct promote_index_type
109 typedef typename conditional<(sizeof(I1)<sizeof(I2)), I2, I1>::type type;
116 template<
typename T,
int Value>
class variable_if_dynamic
119 EIGEN_EMPTY_STRUCT_CTOR(variable_if_dynamic)
120 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit variable_if_dynamic(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); eigen_assert(v == T(Value)); }
121 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE T value() {
return T(Value); }
122 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T) {}
125 template<
typename T>
class variable_if_dynamic<T, Dynamic>
128 EIGEN_DEVICE_FUNC variable_if_dynamic() { eigen_assert(
false); }
130 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit variable_if_dynamic(T value) : m_value(value) {}
131 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T value()
const {
return m_value; }
132 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T value) { m_value = value; }
137 template<
typename T,
int Value>
class variable_if_dynamicindex
140 EIGEN_EMPTY_STRUCT_CTOR(variable_if_dynamicindex)
141 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit variable_if_dynamicindex(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); eigen_assert(v == T(Value)); }
142 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE T value() {
return T(Value); }
143 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T) {}
146 template<
typename T>
class variable_if_dynamicindex<T, DynamicIndex>
149 EIGEN_DEVICE_FUNC variable_if_dynamicindex() { eigen_assert(
false); }
151 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit variable_if_dynamicindex(T value) : m_value(value) {}
152 EIGEN_DEVICE_FUNC T EIGEN_STRONG_INLINE value()
const {
return m_value; }
153 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void setValue(T value) { m_value = value; }
156 template<
typename T>
struct functor_traits
161 PacketAccess =
false,
166 template<
typename T>
struct packet_traits;
168 template<
typename T>
struct unpacket_traits
179 template<
int Size,
typename PacketType,
180 bool Stop = Size==Dynamic || (Size%unpacket_traits<PacketType>::size)==0 || is_same<PacketType,
typename unpacket_traits<PacketType>::half>::value>
181 struct find_best_packet_helper;
183 template<
int Size,
typename PacketType>
184 struct find_best_packet_helper<Size,PacketType,true>
186 typedef PacketType type;
189 template<
int Size,
typename PacketType>
190 struct find_best_packet_helper<Size,PacketType,false>
192 typedef typename find_best_packet_helper<Size,typename unpacket_traits<PacketType>::half>::type type;
195 template<
typename T,
int Size>
196 struct find_best_packet
198 typedef typename find_best_packet_helper<Size,typename packet_traits<T>::type>::type type;
201 #if EIGEN_MAX_STATIC_ALIGN_BYTES>0 202 template<
int ArrayBytes,
int AlignmentBytes,
203 bool Match = bool((ArrayBytes%AlignmentBytes)==0),
204 bool TryHalf = bool(AlignmentBytes>EIGEN_MIN_ALIGN_BYTES) >
205 struct compute_default_alignment_helper
210 template<
int ArrayBytes,
int AlignmentBytes,
bool TryHalf>
211 struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, true, TryHalf>
213 enum { value = AlignmentBytes };
216 template<
int ArrayBytes,
int AlignmentBytes>
217 struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, false, true>
220 enum { value = compute_default_alignment_helper<ArrayBytes, AlignmentBytes/2>::value };
225 template<
int ArrayBytes,
int AlignmentBytes>
226 struct compute_default_alignment_helper
232 template<
typename T,
int Size>
struct compute_default_alignment {
233 enum { value = compute_default_alignment_helper<Size*sizeof(T),EIGEN_MAX_STATIC_ALIGN_BYTES>::value };
236 template<
typename T>
struct compute_default_alignment<T,Dynamic> {
237 enum { value = EIGEN_MAX_ALIGN_BYTES };
240 template<
typename _Scalar,
int _Rows,
int _Cols,
244 : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ),
245 int _MaxRows = _Rows,
247 >
class make_proper_matrix_type
250 IsColVector = _Cols==1 && _Rows!=1,
251 IsRowVector = _Rows==1 && _Cols!=1,
260 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
261 class compute_matrix_flags
271 template<
int _Rows,
int _Cols>
struct size_at_compile_time
273 enum { ret = (_Rows==Dynamic || _Cols==
Dynamic) ? Dynamic : _Rows * _Cols };
276 template<
typename XprType>
struct size_of_xpr_at_compile_time
278 enum { ret = size_at_compile_time<traits<XprType>::RowsAtCompileTime,traits<XprType>::ColsAtCompileTime>::ret };
285 template<typename T, typename StorageKind = typename traits<T>::StorageKind>
struct plain_matrix_type;
286 template<
typename T,
typename BaseClassType,
int Flags>
struct plain_matrix_type_dense;
287 template<
typename T>
struct plain_matrix_type<T,Dense>
289 typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind, traits<T>::Flags>::type type;
291 template<
typename T>
struct plain_matrix_type<T,DiagonalShape>
293 typedef typename T::PlainObject type;
296 template<
typename T,
int Flags>
struct plain_matrix_type_dense<T,MatrixXpr,Flags>
299 traits<T>::RowsAtCompileTime,
300 traits<T>::ColsAtCompileTime,
302 traits<T>::MaxRowsAtCompileTime,
303 traits<T>::MaxColsAtCompileTime
307 template<
typename T,
int Flags>
struct plain_matrix_type_dense<T,ArrayXpr,Flags>
310 traits<T>::RowsAtCompileTime,
311 traits<T>::ColsAtCompileTime,
313 traits<T>::MaxRowsAtCompileTime,
314 traits<T>::MaxColsAtCompileTime
322 template<typename T, typename StorageKind = typename traits<T>::StorageKind>
struct eval;
324 template<
typename T>
struct eval<T,Dense>
326 typedef typename plain_matrix_type<T>::type type;
337 template<
typename T>
struct eval<T,DiagonalShape>
339 typedef typename plain_matrix_type<T>::type type;
343 template<
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
int _MaxCols>
344 struct eval<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
349 template<
typename _Scalar,
int _Rows,
int _Cols,
int _Options,
int _MaxRows,
int _MaxCols>
350 struct eval<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
357 template<typename T, typename StorageKind = typename traits<T>::StorageKind>
struct plain_object_eval;
360 struct plain_object_eval<T,Dense>
362 typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind, evaluator<T>::Flags>::type type;
368 template<
typename T>
struct plain_matrix_type_column_major
370 enum { Rows = traits<T>::RowsAtCompileTime,
371 Cols = traits<T>::ColsAtCompileTime,
372 MaxRows = traits<T>::MaxRowsAtCompileTime,
373 MaxCols = traits<T>::MaxColsAtCompileTime
386 template<
typename T>
struct plain_matrix_type_row_major
388 enum { Rows = traits<T>::RowsAtCompileTime,
389 Cols = traits<T>::ColsAtCompileTime,
390 MaxRows = traits<T>::MaxRowsAtCompileTime,
391 MaxCols = traits<T>::MaxColsAtCompileTime
405 template <
typename T>
408 typedef typename conditional<
409 bool(traits<T>::Flags & NestByRefBit),
414 typedef typename conditional<
415 bool(traits<T>::Flags & NestByRefBit),
418 >::type non_const_type;
422 template<
typename T1,
typename T2>
423 struct transfer_constness
425 typedef typename conditional<
426 bool(internal::is_const<T1>::value),
427 typename internal::add_const_on_value_type<T2>::type,
447 template<typename T, int n, typename PlainObject = typename plain_object_eval<T>::type>
struct nested_eval
451 CoeffReadCost = evaluator<T>::CoeffReadCost,
456 NAsInteger = n == Dynamic ?
HugeCost : n,
457 CostEval = (NAsInteger+1) * ScalarReadCost + CoeffReadCost,
458 CostNoEval = NAsInteger * CoeffReadCost
461 typedef typename conditional<
463 (
int(CostEval) < int(CostNoEval)) ),
465 typename ref_selector<T>::type
471 inline T* const_cast_ptr(
const T* ptr)
473 return const_cast<T*
>(ptr);
476 template<typename Derived, typename XprKind = typename traits<Derived>::XprKind>
477 struct dense_xpr_base
482 template<
typename Derived>
483 struct dense_xpr_base<Derived, MatrixXpr>
488 template<
typename Derived>
489 struct dense_xpr_base<Derived, ArrayXpr>
494 template<typename Derived, typename XprKind = typename traits<Derived>::XprKind,
typename StorageKind =
typename traits<Derived>::StorageKind>
495 struct generic_xpr_base;
497 template<
typename Derived,
typename XprKind>
498 struct generic_xpr_base<Derived, XprKind, Dense>
500 typedef typename dense_xpr_base<Derived,XprKind>::type type;
503 template<
typename XprType,
typename CastType>
struct cast_return_type
505 typedef typename XprType::Scalar CurrentScalarType;
506 typedef typename remove_all<CastType>::type _CastType;
507 typedef typename _CastType::Scalar NewScalarType;
508 typedef typename conditional<is_same<CurrentScalarType,NewScalarType>::value,
509 const XprType&,CastType>::type type;
512 template <
typename A,
typename B>
struct promote_storage_type;
514 template <
typename A>
struct promote_storage_type<A,A>
518 template <
typename A>
struct promote_storage_type<A, const A>
522 template <
typename A>
struct promote_storage_type<const A, A>
540 template <
typename A,
typename B,
typename Functor>
struct cwise_promote_storage_type;
542 template <
typename A,
typename Functor>
struct cwise_promote_storage_type<A,A,Functor> {
typedef A ret; };
543 template <
typename Functor>
struct cwise_promote_storage_type<Dense,Dense,Functor> {
typedef Dense ret; };
544 template <
typename A,
typename Functor>
struct cwise_promote_storage_type<A,Dense,Functor> {
typedef Dense ret; };
545 template <
typename B,
typename Functor>
struct cwise_promote_storage_type<Dense,B,Functor> {
typedef Dense ret; };
546 template <
typename Functor>
struct cwise_promote_storage_type<Sparse,Dense,Functor> {
typedef Sparse ret; };
547 template <
typename Functor>
struct cwise_promote_storage_type<Dense,Sparse,Functor> {
typedef Sparse ret; };
563 template <
typename A,
typename B,
int ProductTag>
struct product_promote_storage_type;
565 template <
typename A,
int ProductTag>
struct product_promote_storage_type<A, A, ProductTag> {
typedef A ret;};
566 template <
int ProductTag>
struct product_promote_storage_type<Dense, Dense, ProductTag> {
typedef Dense ret;};
567 template <
typename A,
int ProductTag>
struct product_promote_storage_type<A, Dense, ProductTag> {
typedef Dense ret; };
568 template <
typename B,
int ProductTag>
struct product_promote_storage_type<Dense, B, ProductTag> {
typedef Dense ret; };
570 template <
typename A,
int ProductTag>
struct product_promote_storage_type<A, DiagonalShape, ProductTag> {
typedef A ret; };
571 template <
typename B,
int ProductTag>
struct product_promote_storage_type<DiagonalShape, B, ProductTag> {
typedef B ret; };
572 template <
int ProductTag>
struct product_promote_storage_type<Dense, DiagonalShape, ProductTag> {
typedef Dense ret; };
573 template <
int ProductTag>
struct product_promote_storage_type<DiagonalShape, Dense, ProductTag> {
typedef Dense ret; };
575 template <
typename A,
int ProductTag>
struct product_promote_storage_type<A, PermutationStorage, ProductTag> {
typedef A ret; };
576 template <
typename B,
int ProductTag>
struct product_promote_storage_type<PermutationStorage, B, ProductTag> {
typedef B ret; };
577 template <
int ProductTag>
struct product_promote_storage_type<Dense, PermutationStorage, ProductTag> {
typedef Dense ret; };
578 template <
int ProductTag>
struct product_promote_storage_type<PermutationStorage, Dense, ProductTag> {
typedef Dense ret; };
583 template<
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
584 struct plain_row_type
586 typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime,
587 ExpressionType::PlainObject::Options |
RowMajor, 1, ExpressionType::MaxColsAtCompileTime> MatrixRowType;
588 typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime,
589 ExpressionType::PlainObject::Options |
RowMajor, 1, ExpressionType::MaxColsAtCompileTime> ArrayRowType;
591 typedef typename conditional<
592 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
598 template<
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
599 struct plain_col_type
601 typedef Matrix<Scalar, ExpressionType::RowsAtCompileTime, 1,
602 ExpressionType::PlainObject::Options & ~
RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> MatrixColType;
603 typedef Array<Scalar, ExpressionType::RowsAtCompileTime, 1,
604 ExpressionType::PlainObject::Options & ~
RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> ArrayColType;
606 typedef typename conditional<
607 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
613 template<
typename ExpressionType,
typename Scalar =
typename ExpressionType::Scalar>
614 struct plain_diag_type
616 enum { diag_size = EIGEN_SIZE_MIN_PREFER_DYNAMIC(ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime),
617 max_diag_size = EIGEN_SIZE_MIN_PREFER_FIXED(ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime)
622 typedef typename conditional<
623 is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
629 template<
typename Expr,
typename Scalar =
typename Expr::Scalar>
630 struct plain_constant_type
635 Options, traits<Expr>::MaxRowsAtCompileTime,traits<Expr>::MaxColsAtCompileTime> array_type;
638 Options, traits<Expr>::MaxRowsAtCompileTime,traits<Expr>::MaxColsAtCompileTime> matrix_type;
643 template<
typename ExpressionType>
646 enum { value = !bool(is_const<ExpressionType>::value) &&
647 bool(traits<ExpressionType>::Flags &
LvalueBit) };
650 template<
typename T>
struct is_diagonal
651 {
enum { ret =
false }; };
653 template<
typename T>
struct is_diagonal<DiagonalBase<T> >
654 {
enum { ret =
true }; };
656 template<
typename T>
struct is_diagonal<DiagonalWrapper<T> >
657 {
enum { ret =
true }; };
659 template<
typename T,
int S>
struct is_diagonal<DiagonalMatrix<T,S> >
660 {
enum { ret =
true }; };
662 template<
typename S1,
typename S2>
struct glue_shapes;
663 template<>
struct glue_shapes<DenseShape,TriangularShape> {
typedef TriangularShape type; };
665 template<
typename T1,
typename T2>
666 bool is_same_dense(
const T1 &mat1,
const T2 &mat2,
typename enable_if<has_direct_access<T1>::ret&&has_direct_access<T2>::ret, T1>::type * = 0)
668 return (mat1.data()==mat2.data()) && (mat1.innerStride()==mat2.innerStride()) && (mat1.outerStride()==mat2.outerStride());
671 template<
typename T1,
typename T2>
672 bool is_same_dense(
const T1 &,
const T2 &,
typename enable_if<!(has_direct_access<T1>::ret&&has_direct_access<T2>::ret), T1>::type * = 0)
677 #ifdef EIGEN_DEBUG_ASSIGN 678 std::string demangle_traversal(
int t)
680 if(t==DefaultTraversal)
return "DefaultTraversal";
681 if(t==LinearTraversal)
return "LinearTraversal";
682 if(t==InnerVectorizedTraversal)
return "InnerVectorizedTraversal";
683 if(t==LinearVectorizedTraversal)
return "LinearVectorizedTraversal";
684 if(t==SliceVectorizedTraversal)
return "SliceVectorizedTraversal";
687 std::string demangle_unrolling(
int t)
689 if(t==NoUnrolling)
return "NoUnrolling";
690 if(t==InnerUnrolling)
return "InnerUnrolling";
691 if(t==CompleteUnrolling)
return "CompleteUnrolling";
694 std::string demangle_flags(
int f)
702 if(f&NestByRefBit) res +=
" | NestByRef";
740 template<
typename ScalarA,
typename ScalarB,
typename BinaryOp=
internal::scalar_product_op<ScalarA,ScalarB> >
742 #ifndef EIGEN_PARSED_BY_DOXYGEN
744 : internal::scalar_product_traits<ScalarA,ScalarB>
745 #endif // EIGEN_PARSED_BY_DOXYGEN 748 template<
typename T,
typename BinaryOp>
751 typedef T ReturnType;
755 template<
typename T,
typename BinaryOp>
758 typedef T ReturnType;
762 template<
typename T,
typename BinaryOp>
765 typedef T ReturnType;
769 template<
typename BinaryOp>
772 typedef void ReturnType;
775 template<
typename T,
typename BinaryOp>
778 typedef std::complex<T> ReturnType;
781 template<
typename T,
typename BinaryOp>
784 typedef std::complex<T> ReturnType;
791 #define EIGEN_CHECK_BINARY_COMPATIBILIY(BINOP,LHS,RHS) \ 792 EIGEN_STATIC_ASSERT((Eigen::internal::has_ReturnType<ScalarBinaryOpTraits<LHS, RHS,BINOP> >::value), \ 793 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) 797 #endif // EIGEN_XPRHELPER_H Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:43
Definition: Constants.h:320
const int HugeCost
Definition: Constants.h:39
const unsigned int DirectAccessBit
Definition: Constants.h:150
const unsigned int LvalueBit
Definition: Constants.h:139
Namespace containing all symbols from the Eigen library.
Definition: Core:271
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:167
const unsigned int RowMajorBit
Definition: Constants.h:61
const unsigned int PacketAccessBit
Definition: Constants.h:89
Definition: Constants.h:324
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: XprHelper.h:35
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
Definition: Eigen_Colamd.h:50
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:45
Definition: Constants.h:322
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:741
const int Dynamic
Definition: Constants.h:21
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:65
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
const unsigned int LinearAccessBit
Definition: Constants.h:125
const unsigned int NoPreferredStorageOrderBit
Definition: Constants.h:173