Eigen  3.2.91
XprHelper.h
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 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& ) {}
21 #else
22  #define EIGEN_EMPTY_STRUCT_CTOR(X)
23 #endif
24 
25 namespace Eigen {
26 
27 typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex;
28 
35 typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE Index;
36 
37 namespace internal {
38 
39 template<typename IndexDest, typename IndexSrc>
40 EIGEN_DEVICE_FUNC
41 inline IndexDest convert_index(const IndexSrc& idx) {
42  // for sizeof(IndexDest)>=sizeof(IndexSrc) compilers should be able to optimize this away:
43  eigen_internal_assert(idx <= NumTraits<IndexDest>::highest() && "Index value to big for target type");
44  return IndexDest(idx);
45 }
46 
47 
48 //classes inheriting no_assignment_operator don't generate a default operator=.
49 class no_assignment_operator
50 {
51  private:
52  no_assignment_operator& operator=(const no_assignment_operator&);
53 };
54 
56 template<typename I1, typename I2>
57 struct promote_index_type
58 {
59  typedef typename conditional<(sizeof(I1)<sizeof(I2)), I2, I1>::type type;
60 };
61 
66 template<typename T, int Value> class variable_if_dynamic
67 {
68  public:
69  EIGEN_EMPTY_STRUCT_CTOR(variable_if_dynamic)
70  EIGEN_DEVICE_FUNC explicit variable_if_dynamic(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); eigen_assert(v == T(Value)); }
71  EIGEN_DEVICE_FUNC static T value() { return T(Value); }
72  EIGEN_DEVICE_FUNC void setValue(T) {}
73 };
74 
75 template<typename T> class variable_if_dynamic<T, Dynamic>
76 {
77  T m_value;
78  EIGEN_DEVICE_FUNC variable_if_dynamic() { eigen_assert(false); }
79  public:
80  EIGEN_DEVICE_FUNC explicit variable_if_dynamic(T value) : m_value(value) {}
81  EIGEN_DEVICE_FUNC T value() const { return m_value; }
82  EIGEN_DEVICE_FUNC void setValue(T value) { m_value = value; }
83 };
84 
87 template<typename T, int Value> class variable_if_dynamicindex
88 {
89  public:
90  EIGEN_EMPTY_STRUCT_CTOR(variable_if_dynamicindex)
91  EIGEN_DEVICE_FUNC explicit variable_if_dynamicindex(T v) { EIGEN_ONLY_USED_FOR_DEBUG(v); eigen_assert(v == T(Value)); }
92  EIGEN_DEVICE_FUNC static T value() { return T(Value); }
93  EIGEN_DEVICE_FUNC void setValue(T) {}
94 };
95 
96 template<typename T> class variable_if_dynamicindex<T, DynamicIndex>
97 {
98  T m_value;
99  EIGEN_DEVICE_FUNC variable_if_dynamicindex() { eigen_assert(false); }
100  public:
101  EIGEN_DEVICE_FUNC explicit variable_if_dynamicindex(T value) : m_value(value) {}
102  EIGEN_DEVICE_FUNC T value() const { return m_value; }
103  EIGEN_DEVICE_FUNC void setValue(T value) { m_value = value; }
104 };
105 
106 template<typename T> struct functor_traits
107 {
108  enum
109  {
110  Cost = 10,
111  PacketAccess = false,
112  IsRepeatable = false
113  };
114 };
115 
116 template<typename T> struct packet_traits;
117 
118 template<typename T> struct unpacket_traits
119 {
120  typedef T type;
121  typedef T half;
122  enum
123  {
124  size = 1,
125  alignment = 1
126  };
127 };
128 
129 template<int Size, typename PacketType,
130  bool Stop = Size==Dynamic || (Size%unpacket_traits<PacketType>::size)==0 || is_same<PacketType,typename unpacket_traits<PacketType>::half>::value>
131 struct find_best_packet_helper;
132 
133 template< int Size, typename PacketType>
134 struct find_best_packet_helper<Size,PacketType,true>
135 {
136  typedef PacketType type;
137 };
138 
139 template<int Size, typename PacketType>
140 struct find_best_packet_helper<Size,PacketType,false>
141 {
142  typedef typename find_best_packet_helper<Size,typename unpacket_traits<PacketType>::half>::type type;
143 };
144 
145 template<typename T, int Size>
146 struct find_best_packet
147 {
148  typedef typename find_best_packet_helper<Size,typename packet_traits<T>::type>::type type;
149 };
150 
151 #if EIGEN_MAX_STATIC_ALIGN_BYTES>0
152 template<int ArrayBytes, int AlignmentBytes,
153  bool Match = bool((ArrayBytes%AlignmentBytes)==0),
154  bool TryHalf = bool(AlignmentBytes>EIGEN_MIN_ALIGN_BYTES) >
155 struct compute_default_alignment_helper
156 {
157  enum { value = 0 };
158 };
159 
160 template<int ArrayBytes, int AlignmentBytes, bool TryHalf>
161 struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, true, TryHalf> // Match
162 {
163  enum { value = AlignmentBytes };
164 };
165 
166 template<int ArrayBytes, int AlignmentBytes>
167 struct compute_default_alignment_helper<ArrayBytes, AlignmentBytes, false, true> // Try-half
168 {
169  // current packet too large, try with an half-packet
170  enum { value = compute_default_alignment_helper<ArrayBytes, AlignmentBytes/2>::value };
171 };
172 #else
173 // If static alignment is disabled, no need to bother.
174 // This also avoids a division by zero in "bool Match = bool((ArrayBytes%AlignmentBytes)==0)"
175 template<int ArrayBytes, int AlignmentBytes>
176 struct compute_default_alignment_helper
177 {
178  enum { value = 0 };
179 };
180 #endif
181 
182 template<typename T, int Size> struct compute_default_alignment {
183  enum { value = compute_default_alignment_helper<Size*sizeof(T),EIGEN_MAX_STATIC_ALIGN_BYTES>::value };
184 };
185 
186 template<typename T> struct compute_default_alignment<T,Dynamic> {
187  enum { value = EIGEN_MAX_ALIGN_BYTES };
188 };
189 
190 template<typename _Scalar, int _Rows, int _Cols,
191  int _Options = AutoAlign |
192  ( (_Rows==1 && _Cols!=1) ? RowMajor
193  : (_Cols==1 && _Rows!=1) ? ColMajor
194  : EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ),
195  int _MaxRows = _Rows,
196  int _MaxCols = _Cols
197 > class make_proper_matrix_type
198 {
199  enum {
200  IsColVector = _Cols==1 && _Rows!=1,
201  IsRowVector = _Rows==1 && _Cols!=1,
202  Options = IsColVector ? (_Options | ColMajor) & ~RowMajor
203  : IsRowVector ? (_Options | RowMajor) & ~ColMajor
204  : _Options
205  };
206  public:
207  typedef Matrix<_Scalar, _Rows, _Cols, Options, _MaxRows, _MaxCols> type;
208 };
209 
210 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
211 class compute_matrix_flags
212 {
213  enum { row_major_bit = Options&RowMajor ? RowMajorBit : 0 };
214  public:
215  // FIXME currently we still have to handle DirectAccessBit at the expression level to handle DenseCoeffsBase<>
216  // and then propagate this information to the evaluator's flags.
217  // However, I (Gael) think that DirectAccessBit should only matter at the evaluation stage.
218  enum { ret = DirectAccessBit | LvalueBit | NestByRefBit | row_major_bit };
219 };
220 
221 template<int _Rows, int _Cols> struct size_at_compile_time
222 {
223  enum { ret = (_Rows==Dynamic || _Cols==Dynamic) ? Dynamic : _Rows * _Cols };
224 };
225 
226 template<typename XprType> struct size_of_xpr_at_compile_time
227 {
228  enum { ret = size_at_compile_time<traits<XprType>::RowsAtCompileTime,traits<XprType>::ColsAtCompileTime>::ret };
229 };
230 
231 /* plain_matrix_type : the difference from eval is that plain_matrix_type is always a plain matrix type,
232  * whereas eval is a const reference in the case of a matrix
233  */
234 
235 template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct plain_matrix_type;
236 template<typename T, typename BaseClassType> struct plain_matrix_type_dense;
237 template<typename T> struct plain_matrix_type<T,Dense>
238 {
239  typedef typename plain_matrix_type_dense<T,typename traits<T>::XprKind>::type type;
240 };
241 template<typename T> struct plain_matrix_type<T,DiagonalShape>
242 {
243  typedef typename T::PlainObject type;
244 };
245 
246 template<typename T> struct plain_matrix_type_dense<T,MatrixXpr>
247 {
248  typedef Matrix<typename traits<T>::Scalar,
249  traits<T>::RowsAtCompileTime,
250  traits<T>::ColsAtCompileTime,
251  AutoAlign | (traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor),
252  traits<T>::MaxRowsAtCompileTime,
253  traits<T>::MaxColsAtCompileTime
254  > type;
255 };
256 
257 template<typename T> struct plain_matrix_type_dense<T,ArrayXpr>
258 {
259  typedef Array<typename traits<T>::Scalar,
260  traits<T>::RowsAtCompileTime,
261  traits<T>::ColsAtCompileTime,
262  AutoAlign | (traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor),
263  traits<T>::MaxRowsAtCompileTime,
264  traits<T>::MaxColsAtCompileTime
265  > type;
266 };
267 
268 /* eval : the return type of eval(). For matrices, this is just a const reference
269  * in order to avoid a useless copy
270  */
271 
272 template<typename T, typename StorageKind = typename traits<T>::StorageKind> struct eval;
273 
274 template<typename T> struct eval<T,Dense>
275 {
276  typedef typename plain_matrix_type<T>::type type;
277 // typedef typename T::PlainObject type;
278 // typedef T::Matrix<typename traits<T>::Scalar,
279 // traits<T>::RowsAtCompileTime,
280 // traits<T>::ColsAtCompileTime,
281 // AutoAlign | (traits<T>::Flags&RowMajorBit ? RowMajor : ColMajor),
282 // traits<T>::MaxRowsAtCompileTime,
283 // traits<T>::MaxColsAtCompileTime
284 // > type;
285 };
286 
287 template<typename T> struct eval<T,DiagonalShape>
288 {
289  typedef typename plain_matrix_type<T>::type type;
290 };
291 
292 // for matrices, no need to evaluate, just use a const reference to avoid a useless copy
293 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
294 struct eval<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
295 {
296  typedef const Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& type;
297 };
298 
299 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
300 struct eval<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, Dense>
301 {
302  typedef const Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& type;
303 };
304 
305 
306 
307 /* plain_matrix_type_column_major : same as plain_matrix_type but guaranteed to be column-major
308  */
309 template<typename T> struct plain_matrix_type_column_major
310 {
311  enum { Rows = traits<T>::RowsAtCompileTime,
312  Cols = traits<T>::ColsAtCompileTime,
313  MaxRows = traits<T>::MaxRowsAtCompileTime,
314  MaxCols = traits<T>::MaxColsAtCompileTime
315  };
316  typedef Matrix<typename traits<T>::Scalar,
317  Rows,
318  Cols,
319  (MaxRows==1&&MaxCols!=1) ? RowMajor : ColMajor,
320  MaxRows,
321  MaxCols
322  > type;
323 };
324 
325 /* plain_matrix_type_row_major : same as plain_matrix_type but guaranteed to be row-major
326  */
327 template<typename T> struct plain_matrix_type_row_major
328 {
329  enum { Rows = traits<T>::RowsAtCompileTime,
330  Cols = traits<T>::ColsAtCompileTime,
331  MaxRows = traits<T>::MaxRowsAtCompileTime,
332  MaxCols = traits<T>::MaxColsAtCompileTime
333  };
334  typedef Matrix<typename traits<T>::Scalar,
335  Rows,
336  Cols,
337  (MaxCols==1&&MaxRows!=1) ? RowMajor : ColMajor,
338  MaxRows,
339  MaxCols
340  > type;
341 };
342 
346 template <typename T>
347 struct ref_selector
348 {
349  typedef typename conditional<
350  bool(traits<T>::Flags & NestByRefBit),
351  T const&,
352  const T
353  >::type type;
354 
355  typedef typename conditional<
356  bool(traits<T>::Flags & NestByRefBit),
357  T &,
358  T
359  >::type non_const_type;
360 };
361 
363 template<typename T1, typename T2>
364 struct transfer_constness
365 {
366  typedef typename conditional<
367  bool(internal::is_const<T1>::value),
368  typename internal::add_const_on_value_type<T2>::type,
369  T2
370  >::type type;
371 };
372 
373 
374 // However, we still need a mechanism to detect whether an expression which is evaluated multiple time
375 // has to be evaluated into a temporary.
376 // That's the purpose of this new nested_eval helper:
388 template<typename T, int n, typename PlainObject = typename eval<T>::type> struct nested_eval
389 {
390  enum {
391  // For the purpose of this test, to keep it reasonably simple, we arbitrarily choose a value of Dynamic values.
392  // the choice of 10000 makes it larger than any practical fixed value and even most dynamic values.
393  // in extreme cases where these assumptions would be wrong, we would still at worst suffer performance issues
394  // (poor choice of temporaries).
395  // It's important that this value can still be squared without integer overflowing.
396  DynamicAsInteger = 10000,
397  ScalarReadCost = NumTraits<typename traits<T>::Scalar>::ReadCost,
398  ScalarReadCostAsInteger = ScalarReadCost == Dynamic ? int(DynamicAsInteger) : int(ScalarReadCost),
399  CoeffReadCost = evaluator<T>::CoeffReadCost, // TODO What if an evaluator evaluate itself into a tempory?
400  // Then CoeffReadCost will be small but we still have to evaluate if n>1...
401  // The solution might be to ask the evaluator if it creates a temp. Perhaps we could even ask the number of temps?
402  CoeffReadCostAsInteger = CoeffReadCost == Dynamic ? int(DynamicAsInteger) : int(CoeffReadCost),
403  NAsInteger = n == Dynamic ? int(DynamicAsInteger) : n,
404  CostEvalAsInteger = (NAsInteger+1) * ScalarReadCostAsInteger + CoeffReadCostAsInteger,
405  CostNoEvalAsInteger = NAsInteger * CoeffReadCostAsInteger
406  };
407 
408  typedef typename conditional<
409  ( (int(evaluator<T>::Flags) & EvalBeforeNestingBit) ||
410  (int(CostEvalAsInteger) < int(CostNoEvalAsInteger)) ),
411  PlainObject,
412  typename ref_selector<T>::type
413  >::type type;
414 };
415 
416 template<typename T>
417 EIGEN_DEVICE_FUNC
418 inline T* const_cast_ptr(const T* ptr)
419 {
420  return const_cast<T*>(ptr);
421 }
422 
423 template<typename Derived, typename XprKind = typename traits<Derived>::XprKind>
424 struct dense_xpr_base
425 {
426  /* dense_xpr_base should only ever be used on dense expressions, thus falling either into the MatrixXpr or into the ArrayXpr cases */
427 };
428 
429 template<typename Derived>
430 struct dense_xpr_base<Derived, MatrixXpr>
431 {
432  typedef MatrixBase<Derived> type;
433 };
434 
435 template<typename Derived>
436 struct dense_xpr_base<Derived, ArrayXpr>
437 {
438  typedef ArrayBase<Derived> type;
439 };
440 
441 template<typename Derived, typename XprKind = typename traits<Derived>::XprKind, typename StorageKind = typename traits<Derived>::StorageKind>
442 struct generic_xpr_base;
443 
444 template<typename Derived, typename XprKind>
445 struct generic_xpr_base<Derived, XprKind, Dense>
446 {
447  typedef typename dense_xpr_base<Derived,XprKind>::type type;
448 };
449 
452 template<typename Derived,typename Scalar,typename OtherScalar,
453  bool EnableIt = !is_same<Scalar,OtherScalar>::value >
454 struct special_scalar_op_base : public DenseCoeffsBase<Derived>
455 {
456  // dummy operator* so that the
457  // "using special_scalar_op_base::operator*" compiles
458  struct dummy {};
459  void operator*(dummy) const;
460  void operator/(dummy) const;
461 };
462 
463 template<typename Derived,typename Scalar,typename OtherScalar>
464 struct special_scalar_op_base<Derived,Scalar,OtherScalar,true> : public DenseCoeffsBase<Derived>
465 {
466  const CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
467  operator*(const OtherScalar& scalar) const
468  {
469 #ifdef EIGEN_SPECIAL_SCALAR_MULTIPLE_PLUGIN
470  EIGEN_SPECIAL_SCALAR_MULTIPLE_PLUGIN
471 #endif
472  return CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
473  (*static_cast<const Derived*>(this), scalar_multiple2_op<Scalar,OtherScalar>(scalar));
474  }
475 
476  inline friend const CwiseUnaryOp<scalar_multiple2_op<Scalar,OtherScalar>, Derived>
477  operator*(const OtherScalar& scalar, const Derived& matrix)
478  {
479 #ifdef EIGEN_SPECIAL_SCALAR_MULTIPLE_PLUGIN
480  EIGEN_SPECIAL_SCALAR_MULTIPLE_PLUGIN
481 #endif
482  return static_cast<const special_scalar_op_base&>(matrix).operator*(scalar);
483  }
484 
485  const CwiseUnaryOp<scalar_quotient2_op<Scalar,OtherScalar>, Derived>
486  operator/(const OtherScalar& scalar) const
487  {
488 #ifdef EIGEN_SPECIAL_SCALAR_MULTIPLE_PLUGIN
489  EIGEN_SPECIAL_SCALAR_MULTIPLE_PLUGIN
490 #endif
491  return CwiseUnaryOp<scalar_quotient2_op<Scalar,OtherScalar>, Derived>
492  (*static_cast<const Derived*>(this), scalar_quotient2_op<Scalar,OtherScalar>(scalar));
493  }
494 };
495 
496 template<typename XprType, typename CastType> struct cast_return_type
497 {
498  typedef typename XprType::Scalar CurrentScalarType;
499  typedef typename remove_all<CastType>::type _CastType;
500  typedef typename _CastType::Scalar NewScalarType;
501  typedef typename conditional<is_same<CurrentScalarType,NewScalarType>::value,
502  const XprType&,CastType>::type type;
503 };
504 
505 template <typename A, typename B> struct promote_storage_type;
506 
507 template <typename A> struct promote_storage_type<A,A>
508 {
509  typedef A ret;
510 };
511 template <typename A> struct promote_storage_type<A, const A>
512 {
513  typedef A ret;
514 };
515 template <typename A> struct promote_storage_type<const A, A>
516 {
517  typedef A ret;
518 };
519 
533 template <typename A, typename B, typename Functor> struct cwise_promote_storage_type;
534 
535 template <typename A, typename Functor> struct cwise_promote_storage_type<A,A,Functor> { typedef A ret; };
536 template <typename Functor> struct cwise_promote_storage_type<Dense,Dense,Functor> { typedef Dense ret; };
537 template <typename ScalarA, typename ScalarB> struct cwise_promote_storage_type<Dense,Dense,scalar_product_op<ScalarA,ScalarB> > { typedef Dense ret; };
538 template <typename A, typename Functor> struct cwise_promote_storage_type<A,Dense,Functor> { typedef Dense ret; };
539 template <typename B, typename Functor> struct cwise_promote_storage_type<Dense,B,Functor> { typedef Dense ret; };
540 template <typename A, typename ScalarA, typename ScalarB> struct cwise_promote_storage_type<A,Dense,scalar_product_op<ScalarA,ScalarB> > { typedef A ret; };
541 template <typename B, typename ScalarA, typename ScalarB> struct cwise_promote_storage_type<Dense,B,scalar_product_op<ScalarA,ScalarB> > { typedef B ret; };
542 
557 template <typename A, typename B, int ProductTag> struct product_promote_storage_type;
558 
559 template <typename A, int ProductTag> struct product_promote_storage_type<A, A, ProductTag> { typedef A ret;};
560 template <int ProductTag> struct product_promote_storage_type<Dense, Dense, ProductTag> { typedef Dense ret;};
561 template <typename A, int ProductTag> struct product_promote_storage_type<A, Dense, ProductTag> { typedef Dense ret; };
562 template <typename B, int ProductTag> struct product_promote_storage_type<Dense, B, ProductTag> { typedef Dense ret; };
563 
564 template <typename A, int ProductTag> struct product_promote_storage_type<A, DiagonalShape, ProductTag> { typedef A ret; };
565 template <typename B, int ProductTag> struct product_promote_storage_type<DiagonalShape, B, ProductTag> { typedef B ret; };
566 template <int ProductTag> struct product_promote_storage_type<Dense, DiagonalShape, ProductTag> { typedef Dense ret; };
567 template <int ProductTag> struct product_promote_storage_type<DiagonalShape, Dense, ProductTag> { typedef Dense ret; };
568 
569 template <typename A, int ProductTag> struct product_promote_storage_type<A, PermutationStorage, ProductTag> { typedef A ret; };
570 template <typename B, int ProductTag> struct product_promote_storage_type<PermutationStorage, B, ProductTag> { typedef B ret; };
571 template <int ProductTag> struct product_promote_storage_type<Dense, PermutationStorage, ProductTag> { typedef Dense ret; };
572 template <int ProductTag> struct product_promote_storage_type<PermutationStorage, Dense, ProductTag> { typedef Dense ret; };
573 
577 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
578 struct plain_row_type
579 {
580  typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime,
581  ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> MatrixRowType;
582  typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime,
583  ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> ArrayRowType;
584 
585  typedef typename conditional<
586  is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
587  MatrixRowType,
588  ArrayRowType
589  >::type type;
590 };
591 
592 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
593 struct plain_col_type
594 {
595  typedef Matrix<Scalar, ExpressionType::RowsAtCompileTime, 1,
596  ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> MatrixColType;
597  typedef Array<Scalar, ExpressionType::RowsAtCompileTime, 1,
598  ExpressionType::PlainObject::Options & ~RowMajor, ExpressionType::MaxRowsAtCompileTime, 1> ArrayColType;
599 
600  typedef typename conditional<
601  is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
602  MatrixColType,
603  ArrayColType
604  >::type type;
605 };
606 
607 template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
608 struct plain_diag_type
609 {
610  enum { diag_size = EIGEN_SIZE_MIN_PREFER_DYNAMIC(ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime),
611  max_diag_size = EIGEN_SIZE_MIN_PREFER_FIXED(ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime)
612  };
613  typedef Matrix<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> MatrixDiagType;
614  typedef Array<Scalar, diag_size, 1, ExpressionType::PlainObject::Options & ~RowMajor, max_diag_size, 1> ArrayDiagType;
615 
616  typedef typename conditional<
617  is_same< typename traits<ExpressionType>::XprKind, MatrixXpr >::value,
618  MatrixDiagType,
619  ArrayDiagType
620  >::type type;
621 };
622 
623 template<typename ExpressionType>
624 struct is_lvalue
625 {
626  enum { value = !bool(is_const<ExpressionType>::value) &&
627  bool(traits<ExpressionType>::Flags & LvalueBit) };
628 };
629 
630 template<typename T> struct is_diagonal
631 { enum { ret = false }; };
632 
633 template<typename T> struct is_diagonal<DiagonalBase<T> >
634 { enum { ret = true }; };
635 
636 template<typename T> struct is_diagonal<DiagonalWrapper<T> >
637 { enum { ret = true }; };
638 
639 template<typename T, int S> struct is_diagonal<DiagonalMatrix<T,S> >
640 { enum { ret = true }; };
641 
642 template<typename S1, typename S2> struct glue_shapes;
643 template<> struct glue_shapes<DenseShape,TriangularShape> { typedef TriangularShape type; };
644 
645 template<typename T1, typename T2>
646 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)
647 {
648  return (mat1.data()==mat2.data()) && (mat1.innerStride()==mat2.innerStride()) && (mat1.outerStride()==mat2.outerStride());
649 }
650 
651 template<typename T1, typename T2>
652 bool is_same_dense(const T1 &, const T2 &, typename enable_if<!(has_direct_access<T1>::ret&&has_direct_access<T2>::ret), T1>::type * = 0)
653 {
654  return false;
655 }
656 
657 } // end namespace internal
658 
659 // we require Lhs and Rhs to have the same scalar type. Currently there is no example of a binary functor
660 // that would take two operands of different types. If there were such an example, then this check should be
661 // moved to the BinaryOp functors, on a per-case basis. This would however require a change in the BinaryOp functors, as
662 // currently they take only one typename Scalar template parameter.
663 // It is tempting to always allow mixing different types but remember that this is often impossible in the vectorized paths.
664 // So allowing mixing different types gives very unexpected errors when enabling vectorization, when the user tries to
665 // add together a float matrix and a double matrix.
666 #define EIGEN_CHECK_BINARY_COMPATIBILIY(BINOP,LHS,RHS) \
667  EIGEN_STATIC_ASSERT((internal::functor_is_product_like<BINOP>::ret \
668  ? int(internal::scalar_product_traits<LHS, RHS>::Defined) \
669  : int(internal::is_same<LHS, RHS>::value)), \
670  YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
671 
672 } // end namespace Eigen
673 
674 #endif // EIGEN_XPRHELPER_H
Definition: Constants.h:314
const unsigned int DirectAccessBit
Definition: Constants.h:141
const unsigned int LvalueBit
Definition: Constants.h:130
Definition: LDLT.h:16
const unsigned int RowMajorBit
Definition: Constants.h:53
Definition: Eigen_Colamd.h:54
Definition: Constants.h:316
Definition: Constants.h:312
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:57