XprHelper.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_XPRHELPER_H
12 #define EIGEN_XPRHELPER_H
13 
14 // just a workaround because GCC seems to not really like empty structs
15 // FIXME: gcc 4.3 generates bad code when strict-aliasing is enabled
16 // so currently we simply disable this optimization for gcc 4.3
17 #if (defined __GNUG__) && !((__GNUC__==4) && (__GNUC_MINOR__==3))
18  #define EIGEN_EMPTY_STRUCT_CTOR(X) \
19  EIGEN_STRONG_INLINE X() {} \
20  EIGEN_STRONG_INLINE X(const X& ) {}
21 #else
22  #define EIGEN_EMPTY_STRUCT_CTOR(X)
23 #endif
24 
25 namespace Eigen {
26 
28 
29 namespace internal {
30 
31 //classes inheriting no_assignment_operator don't generate a default operator=.
33 {
34  private:
36 };
37 
39 template<typename I1, typename I2>
41 {
43 };
44 
49 template<typename T, int Value> class variable_if_dynamic
50 {
51  public:
53  explicit variable_if_dynamic(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); assert(v == T(Value)); }
54  static T value() { return T(Value); }
55  void setValue(T) {}
56 };
57 
58 template<typename T> class variable_if_dynamic<T, Dynamic>
59 {
61  variable_if_dynamic() { assert(false); }
62  public:
63  explicit variable_if_dynamic(T value) : m_value(value) {}
64  T value() const { return m_value; }
65  void setValue(T value) { m_value = value; }
66 };
67 
70 template<typename T, int Value> class variable_if_dynamicindex
71 {
72  public:
74  explicit variable_if_dynamicindex(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); assert(v == T(Value)); }
75  static T value() { return T(Value); }
76  void setValue(T) {}
77 };
78 
79 template<typename T> class variable_if_dynamicindex<T, DynamicIndex>
80 {
82  variable_if_dynamicindex() { assert(false); }
83  public:
84  explicit variable_if_dynamicindex(T value) : m_value(value) {}
85  T value() const { return m_value; }
86  void setValue(T value) { m_value = value; }
87 };
88 
89 template<typename T> struct functor_traits
90 {
91  enum
92  {
93  Cost = 10,
94  PacketAccess = false,
95  IsRepeatable = false
96  };
97 };
98 
99 template<typename T> struct packet_traits;
100 
101 template<typename T> struct unpacket_traits
102 {
103  typedef T type;
104  enum {size=1};
105 };
106 
107 template<typename _Scalar, int _Rows, int _Cols,
108  int _Options = AutoAlign |
109  ( (_Rows==1 && _Cols!=1) ? RowMajor
110  : (_Cols==1 && _Rows!=1) ? ColMajor
112  int _MaxRows = _Rows,
113  int _MaxCols = _Cols
115 {
116  enum {
117  IsColVector = _Cols==1 && _Rows!=1,
118  IsRowVector = _Rows==1 && _Cols!=1,
119  Options = IsColVector ? (_Options | ColMajor) & ~RowMajor
120  : IsRowVector ? (_Options | RowMajor) & ~ColMajor
121  : _Options
122  };
123  public:
125 };
126 
127 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
129 {
130  enum {
131  row_major_bit = Options&RowMajor ? RowMajorBit : 0,
132  is_dynamic_size_storage = MaxRows==Dynamic || MaxCols==Dynamic,
133 
134  aligned_bit =
135  (
136  ((Options&DontAlign)==0)
137  && (
138 #if EIGEN_ALIGN_STATICALLY
139  ((!is_dynamic_size_storage) && (((MaxCols*MaxRows*int(sizeof(Scalar))) % 16) == 0))
140 #else
141  0
142 #endif
143 
144  ||
145 
146 #if EIGEN_ALIGN
147  is_dynamic_size_storage
148 #else
149  0
150 #endif
151 
152  )
153  ) ? AlignedBit : 0,
154  packet_access_bit = packet_traits<Scalar>::Vectorizable && aligned_bit ? PacketAccessBit : 0
155  };
156 
157  public:
158  enum { ret = LinearAccessBit | LvalueBit | DirectAccessBit | NestByRefBit | packet_access_bit | row_major_bit | aligned_bit };
159 };
160 
161 template<int _Rows, int _Cols> struct size_at_compile_time
162 {
163  enum { ret = (_Rows==Dynamic || _Cols==Dynamic) ? Dynamic : _Rows * _Cols };
164 };
165 
166 /* plain_matrix_type : the difference from eval is that plain_matrix_type is always a plain matrix type,
167  * whereas eval is a const reference in the case of a matrix
168  */
169 
170 template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct plain_matrix_type;
171 template<typename T, typename BaseClassType> struct plain_matrix_type_dense;
172 template<typename T> struct plain_matrix_type<T,Dense>
173 {
175 };
176 
177 template<typename T> struct plain_matrix_type_dense<T,MatrixXpr>
178 {
185  > type;
186 };
187 
188 template<typename T> struct plain_matrix_type_dense<T,ArrayXpr>
189 {
196  > type;
197 };
198 
199 /* eval : the return type of eval(). For matrices, this is just a const reference
200  * in order to avoid a useless copy
201  */
202 
203 template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct eval;
204 
205 template<typename T> struct eval<T,Dense>
206 {
208 // typedef typename T::PlainObject type;
209 // typedef T::Matrix<typename traits<T>::Scalar,
210 // traits<T>::RowsAtCompileTime,
211 // traits<T>::ColsAtCompileTime,
212 // AutoAlign | (traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor),
213 // traits<T>::MaxRowsAtCompileTime,
214 // traits<T>::MaxColsAtCompileTime
215 // > type;
216 };
217 
218 // for matrices, no need to evaluate, just use a const reference to avoid a useless copy
219 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
220 struct eval<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
221 {
223 };
224 
225 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
226 struct eval<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
227 {
229 };
230 
231 
232 
233 /* plain_matrix_type_column_major : same as plain_matrix_type but guaranteed to be column-major
234  */
235 template<typename T> struct plain_matrix_type_column_major
236 {
241  };
243  Rows,
244  Cols,
245  (MaxRows==1&&MaxCols!=1) ? RowMajor : ColMajor,
246  MaxRows,
247  MaxCols
248  > type;
249 };
250 
251 /* plain_matrix_type_row_major : same as plain_matrix_type but guaranteed to be row-major
252  */
253 template<typename T> struct plain_matrix_type_row_major
254 {
259  };
261  Rows,
262  Cols,
263  (MaxCols==1&&MaxRows!=1) ? RowMajor : ColMajor,
264  MaxRows,
265  MaxCols
266  > type;
267 };
268 
269 // we should be able to get rid of this one too
270 template<typename T> struct must_nest_by_value { enum { ret = false }; };
271 
275 template <typename T>
277 {
278  typedef typename conditional<
280  T const&,
281  const T
283 };
284 
286 template<typename T1, typename T2>
288 {
289  typedef typename conditional<
292  T2
294 };
295 
316 template<typename T, int n=1, typename PlainObject = typename eval<T>::type> struct nested
317 {
318  enum {
319  // for the purpose of this test, to keep it reasonably simple, we arbitrarily choose a value of Dynamic values.
320  // the choice of 10000 makes it larger than any practical fixed value and even most dynamic values.
321  // in extreme cases where these assumptions would be wrong, we would still at worst suffer performance issues
322  // (poor choice of temporaries).
323  // it's important that this value can still be squared without integer overflowing.
324  DynamicAsInteger = 10000,
325  ScalarReadCost = NumTraits<typename traits<T>::Scalar>::ReadCost,
326  ScalarReadCostAsInteger = ScalarReadCost == Dynamic ? int(DynamicAsInteger) : int(ScalarReadCost),
327  CoeffReadCost = traits<T>::CoeffReadCost,
328  CoeffReadCostAsInteger = CoeffReadCost == Dynamic ? int(DynamicAsInteger) : int(CoeffReadCost),
329  NAsInteger = n == Dynamic ? int(DynamicAsInteger) : n,
330  CostEvalAsInteger = (NAsInteger+1) * ScalarReadCostAsInteger + CoeffReadCostAsInteger,
331  CostNoEvalAsInteger = NAsInteger * CoeffReadCostAsInteger
332  };
333 
334  typedef typename conditional<
336  int(CostEvalAsInteger) < int(CostNoEvalAsInteger)
337  ),
338  PlainObject,
339  typename ref_selector<T>::type
340  >::type type;
341 };
342 
343 template<typename T>
344 T* const_cast_ptr(const T* ptr)
345 {
346  return const_cast<T*>(ptr);
347 }
348 
349 template<typename Derived, typename XprKind = typename traits<Derived>::XprKind>
351 {
352  /* dense_xpr_base should only ever be used on dense expressions, thus falling either into the MatrixXpr or into the ArrayXpr cases */
353 };
354 
355 template<typename Derived>
356 struct dense_xpr_base<Derived, MatrixXpr>
357 {
359 };
360 
361 template<typename Derived>
362 struct dense_xpr_base<Derived, ArrayXpr>
363 {
365 };
366 
369 template<typename Derived,typename Scalar,typename OtherScalar,
370  bool EnableIt = !is_same<Scalar,OtherScalar>::value >
371 struct special_scalar_op_base : public DenseCoeffsBase<Derived>
372 {
373  // dummy operator* so that the
374  // "using special_scalar_op_base::operator*" compiles
375  void operator*() const;
376 };
377 
378 template<typename Derived,typename Scalar,typename OtherScalar>
379 struct special_scalar_op_base<Derived,Scalar,OtherScalar,true> : public DenseCoeffsBase<Derived>
380 {
382  operator*(const OtherScalar& scalar) const
383  {
384  return CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
385  (*static_cast<const Derived*>(this), scalar_multiple2_op<Scalar,OtherScalar>(scalar));
386  }
387 
388  inline friend const CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
389  operator*(const OtherScalar& scalar, const Derived& matrix)
390  { return static_cast<const special_scalar_op_base&>(matrix).operator*(scalar); }
391 };
392 
393 template<typename XprType, typename CastType> struct cast_return_type
394 {
395  typedef typename XprType::Scalar CurrentScalarType;
397  typedef typename _CastType::Scalar NewScalarType;
399  const XprType&,CastType>::type type;
400 };
401 
402 template <typename A, typename B> struct promote_storage_type;
403 
404 template <typename A> struct promote_storage_type<A,A>
405 {
406  typedef A ret;
407 };
408 
412 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
414 {
415  typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime,
416  ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> MatrixRowType;
417  typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime,
418  ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> ArrayRowType;
419 
420  typedef typename conditional<
422  MatrixRowType,
423  ArrayRowType
425 };
426 
427 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
429 {
430  typedef Matrix<Scalar, ExpressionType::RowsAtCompileTime, 1,
431  ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> MatrixColType;
432  typedef Array<Scalar, ExpressionType::RowsAtCompileTime, 1,
433  ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> ArrayColType;
434 
435  typedef typename conditional<
437  MatrixColType,
438  ArrayColType
440 };
441 
442 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
444 {
445  enum { diag_size = EIGEN_SIZE_MIN_PREFER_DYNAMIC(ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime),
446  max_diag_size = EIGEN_SIZE_MIN_PREFER_FIXED(ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime)
447  };
450 
451  typedef typename conditional<
453  MatrixDiagType,
454  ArrayDiagType
456 };
457 
458 template<typename ExpressionType>
459 struct is_lvalue
460 {
461  enum { value = !bool(is_const<ExpressionType>::value) &&
463 };
464 
465 } // end namespace internal
466 
467 } // end namespace Eigen
468 
469 #endif // EIGEN_XPRHELPER_H
Matrix< Scalar, ExpressionType::RowsAtCompileTime, 1, ExpressionType::PlainObject::Options &~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1 > MatrixColType
Definition: XprHelper.h:431
conditional< bool(traits< T >::Flags &NestByRefBit), T const &, const T >::type type
Definition: XprHelper.h:282
#define EIGEN_EMPTY_STRUCT_CTOR(X)
Definition: XprHelper.h:22
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
plain_matrix_type< T >::type type
Definition: XprHelper.h:207
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE
const CwiseUnaryOp< scalar_multiple2_op< Scalar, OtherScalar >, Derived > operator*(const OtherScalar &scalar) const
Definition: XprHelper.h:382
T * const_cast_ptr(const T *ptr)
Definition: XprHelper.h:344
remove_all< CastType >::type _CastType
Definition: XprHelper.h:396
const unsigned int DirectAccessBit
Definition: Constants.h:142
const Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & type
Definition: XprHelper.h:222
const unsigned int LvalueBit
Definition: Constants.h:131
conditional< bool(internal::is_const< T1 >::value), typename internal::add_const_on_value_type< T2 >::type, T2 >::type type
Definition: XprHelper.h:293
Definition: LDLT.h:16
const int DynamicIndex
Definition: Constants.h:26
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION
#define EIGEN_SIZE_MIN_PREFER_FIXED(a, b)
const unsigned int RowMajorBit
Definition: Constants.h:53
const unsigned int PacketAccessBit
Definition: Constants.h:81
const unsigned int AlignedBit
Definition: Constants.h:147
conditional< is_same< typename traits< ExpressionType >::XprKind, MatrixXpr >::value, MatrixRowType, ArrayRowType >::type type
Definition: XprHelper.h:424
Matrix< Scalar, 1, ExpressionType::ColsAtCompileTime, ExpressionType::PlainObject::Options|RowMajor, 1, ExpressionType::MaxColsAtCompileTime > MatrixRowType
Definition: XprHelper.h:416
#define EIGEN_ALIGN
friend const CwiseUnaryOp< scalar_multiple2_op< Scalar, OtherScalar >, Derived > operator*(const OtherScalar &scalar, const Derived &matrix)
Definition: XprHelper.h:389
Array< Scalar, diag_size, 1, ExpressionType::PlainObject::Options &~RowMajor, max_diag_size, 1 > ArrayDiagType
Definition: XprHelper.h:449
conditional<(sizeof(I1)< sizeof(I2)), I2, I1 >::type type
Definition: XprHelper.h:42
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
plain_matrix_type_dense< T, typename traits< T >::XprKind >::type type
Definition: XprHelper.h:174
const Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & type
Definition: XprHelper.h:228
Matrix< _Scalar, _Rows, _Cols, Options, _MaxRows, _MaxCols > type
Definition: XprHelper.h:124
const unsigned int NestByRefBit
Definition: Constants.h:149
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition: XprHelper.h:27
_CastType::Scalar NewScalarType
Definition: XprHelper.h:397
Array< Scalar, 1, ExpressionType::ColsAtCompileTime, ExpressionType::PlainObject::Options|RowMajor, 1, ExpressionType::MaxColsAtCompileTime > ArrayRowType
Definition: XprHelper.h:418
#define EIGEN_SIZE_MIN_PREFER_DYNAMIC(a, b)
conditional< is_same< CurrentScalarType, NewScalarType >::value, const XprType &, CastType >::type type
Definition: XprHelper.h:399
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:42
no_assignment_operator& operator=(const no_assignment_operator&)
conditional< is_same< typename traits< ExpressionType >::XprKind, MatrixXpr >::value, MatrixDiagType, ArrayDiagType >::type type
Definition: XprHelper.h:455
const int Dynamic
Definition: Constants.h:21
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:58
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:59
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
conditional< is_same< typename traits< ExpressionType >::XprKind, MatrixXpr >::value, MatrixColType, ArrayColType >::type type
Definition: XprHelper.h:439
Matrix< Scalar, diag_size, 1, ExpressionType::PlainObject::Options &~RowMajor, max_diag_size, 1 > MatrixDiagType
Definition: XprHelper.h:448
XprType::Scalar CurrentScalarType
Definition: XprHelper.h:395
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
const unsigned int LinearAccessBit
Definition: Constants.h:117
Array< Scalar, ExpressionType::RowsAtCompileTime, 1, ExpressionType::PlainObject::Options &~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1 > ArrayColType
Definition: XprHelper.h:433


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:41:02