DenseCoeffsBase.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) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_DENSECOEFFSBASE_H
11 #define EIGEN_DENSECOEFFSBASE_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 template<typename T> struct add_const_on_value_type_if_arithmetic
17 {
19 };
20 }
21 
33 template<typename Derived>
34 class DenseCoeffsBase<Derived,ReadOnlyAccessors> : public EigenBase<Derived>
35 {
36  public:
41 
42  // Explanation for this CoeffReturnType typedef.
43  // - This is the return type of the coeff() method.
44  // - The LvalueBit means exactly that we can offer a coeffRef() method, which means exactly that we can get references
45  // to coeffs, which means exactly that we can have coeff() return a const reference (as opposed to returning a value).
46  // - The is_artihmetic check is required since "const int", "const double", etc. will cause warnings on some systems
47  // while the declaration of "const T", where T is a non arithmetic type does not. Always returning "const Scalar&" is
48  // not possible, since the underlying expressions might not offer a valid address the reference could be referring to.
50  const Scalar&,
53 
57 
59  using Base::rows;
60  using Base::cols;
61  using Base::size;
62  using Base::derived;
63 
64  EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) const
65  {
66  return int(Derived::RowsAtCompileTime) == 1 ? 0
67  : int(Derived::ColsAtCompileTime) == 1 ? inner
68  : int(Derived::Flags)&RowMajorBit ? outer
69  : inner;
70  }
71 
72  EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) const
73  {
74  return int(Derived::ColsAtCompileTime) == 1 ? 0
75  : int(Derived::RowsAtCompileTime) == 1 ? inner
76  : int(Derived::Flags)&RowMajorBit ? inner
77  : outer;
78  }
79 
95  {
96  eigen_internal_assert(row >= 0 && row < rows()
97  && col >= 0 && col < cols());
98  return derived().coeff(row, col);
99  }
100 
101  EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner) const
102  {
103  return coeff(rowIndexByOuterInner(outer, inner),
104  colIndexByOuterInner(outer, inner));
105  }
106 
112  {
113  eigen_assert(row >= 0 && row < rows()
114  && col >= 0 && col < cols());
115  return derived().coeff(row, col);
116  }
117 
134  coeff(Index index) const
135  {
136  eigen_internal_assert(index >= 0 && index < size());
137  return derived().coeff(index);
138  }
139 
140 
150  operator[](Index index) const
151  {
152  #ifndef EIGEN2_SUPPORT
153  EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
154  THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
155  #endif
156  eigen_assert(index >= 0 && index < size());
157  return derived().coeff(index);
158  }
159 
171  operator()(Index index) const
172  {
173  eigen_assert(index >= 0 && index < size());
174  return derived().coeff(index);
175  }
176 
180  x() const { return (*this)[0]; }
181 
185  y() const { return (*this)[1]; }
186 
190  z() const { return (*this)[2]; }
191 
195  w() const { return (*this)[3]; }
196 
207  template<int LoadMode>
208  EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col) const
209  {
210  eigen_internal_assert(row >= 0 && row < rows()
211  && col >= 0 && col < cols());
212  return derived().template packet<LoadMode>(row,col);
213  }
214 
215 
217  template<int LoadMode>
218  EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner) const
219  {
220  return packet<LoadMode>(rowIndexByOuterInner(outer, inner),
221  colIndexByOuterInner(outer, inner));
222  }
223 
234  template<int LoadMode>
235  EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
236  {
237  eigen_internal_assert(index >= 0 && index < size());
238  return derived().template packet<LoadMode>(index);
239  }
240 
241  protected:
242  // explanation: DenseBase is doing "using ..." on the methods from DenseCoeffsBase.
243  // But some methods are only available in the DirectAccess case.
244  // So we add dummy methods here with these names, so that "using... " doesn't fail.
245  // It's not private so that the child class DenseBase can access them, and it's not public
246  // either since it's an implementation detail, so has to be protected.
247  void coeffRef();
248  void coeffRefByOuterInner();
249  void writePacket();
250  void writePacketByOuterInner();
251  void copyCoeff();
252  void copyCoeffByOuterInner();
253  void copyPacket();
254  void copyPacketByOuterInner();
255  void stride();
256  void innerStride();
257  void outerStride();
258  void rowStride();
259  void colStride();
260 };
261 
273 template<typename Derived>
274 class DenseCoeffsBase<Derived, WriteAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
275 {
276  public:
277 
279 
285 
286  using Base::coeff;
287  using Base::rows;
288  using Base::cols;
289  using Base::size;
290  using Base::derived;
291  using Base::rowIndexByOuterInner;
292  using Base::colIndexByOuterInner;
293  using Base::operator[];
294  using Base::operator();
295  using Base::x;
296  using Base::y;
297  using Base::z;
298  using Base::w;
299 
314  EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col)
315  {
316  eigen_internal_assert(row >= 0 && row < rows()
317  && col >= 0 && col < cols());
318  return derived().coeffRef(row, col);
319  }
320 
321  EIGEN_STRONG_INLINE Scalar&
322  coeffRefByOuterInner(Index outer, Index inner)
323  {
324  return coeffRef(rowIndexByOuterInner(outer, inner),
325  colIndexByOuterInner(outer, inner));
326  }
327 
333  EIGEN_STRONG_INLINE Scalar&
334  operator()(Index row, Index col)
335  {
336  eigen_assert(row >= 0 && row < rows()
337  && col >= 0 && col < cols());
338  return derived().coeffRef(row, col);
339  }
340 
341 
357  EIGEN_STRONG_INLINE Scalar&
358  coeffRef(Index index)
359  {
360  eigen_internal_assert(index >= 0 && index < size());
361  return derived().coeffRef(index);
362  }
363 
371  EIGEN_STRONG_INLINE Scalar&
372  operator[](Index index)
373  {
374  #ifndef EIGEN2_SUPPORT
375  EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
376  THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
377  #endif
378  eigen_assert(index >= 0 && index < size());
379  return derived().coeffRef(index);
380  }
381 
391  EIGEN_STRONG_INLINE Scalar&
392  operator()(Index index)
393  {
394  eigen_assert(index >= 0 && index < size());
395  return derived().coeffRef(index);
396  }
397 
400  EIGEN_STRONG_INLINE Scalar&
401  x() { return (*this)[0]; }
402 
405  EIGEN_STRONG_INLINE Scalar&
406  y() { return (*this)[1]; }
407 
410  EIGEN_STRONG_INLINE Scalar&
411  z() { return (*this)[2]; }
412 
415  EIGEN_STRONG_INLINE Scalar&
416  w() { return (*this)[3]; }
417 
428  template<int StoreMode>
429  EIGEN_STRONG_INLINE void writePacket
430  (Index row, Index col, const typename internal::packet_traits<Scalar>::type& val)
431  {
432  eigen_internal_assert(row >= 0 && row < rows()
433  && col >= 0 && col < cols());
434  derived().template writePacket<StoreMode>(row,col,val);
435  }
436 
437 
439  template<int StoreMode>
440  EIGEN_STRONG_INLINE void writePacketByOuterInner
441  (Index outer, Index inner, const typename internal::packet_traits<Scalar>::type& val)
442  {
443  writePacket<StoreMode>(rowIndexByOuterInner(outer, inner),
444  colIndexByOuterInner(outer, inner),
445  val);
446  }
447 
457  template<int StoreMode>
458  EIGEN_STRONG_INLINE void writePacket
459  (Index index, const typename internal::packet_traits<Scalar>::type& val)
460  {
461  eigen_internal_assert(index >= 0 && index < size());
462  derived().template writePacket<StoreMode>(index,val);
463  }
464 
465 #ifndef EIGEN_PARSED_BY_DOXYGEN
466 
475  template<typename OtherDerived>
476  EIGEN_STRONG_INLINE void copyCoeff(Index row, Index col, const DenseBase<OtherDerived>& other)
477  {
478  eigen_internal_assert(row >= 0 && row < rows()
479  && col >= 0 && col < cols());
480  derived().coeffRef(row, col) = other.derived().coeff(row, col);
481  }
482 
491  template<typename OtherDerived>
492  EIGEN_STRONG_INLINE void copyCoeff(Index index, const DenseBase<OtherDerived>& other)
493  {
494  eigen_internal_assert(index >= 0 && index < size());
495  derived().coeffRef(index) = other.derived().coeff(index);
496  }
497 
498 
499  template<typename OtherDerived>
500  EIGEN_STRONG_INLINE void copyCoeffByOuterInner(Index outer, Index inner, const DenseBase<OtherDerived>& other)
501  {
502  const Index row = rowIndexByOuterInner(outer,inner);
503  const Index col = colIndexByOuterInner(outer,inner);
504  // derived() is important here: copyCoeff() may be reimplemented in Derived!
505  derived().copyCoeff(row, col, other);
506  }
507 
516  template<typename OtherDerived, int StoreMode, int LoadMode>
517  EIGEN_STRONG_INLINE void copyPacket(Index row, Index col, const DenseBase<OtherDerived>& other)
518  {
519  eigen_internal_assert(row >= 0 && row < rows()
520  && col >= 0 && col < cols());
521  derived().template writePacket<StoreMode>(row, col,
522  other.derived().template packet<LoadMode>(row, col));
523  }
524 
533  template<typename OtherDerived, int StoreMode, int LoadMode>
535  {
536  eigen_internal_assert(index >= 0 && index < size());
537  derived().template writePacket<StoreMode>(index,
538  other.derived().template packet<LoadMode>(index));
539  }
540 
542  template<typename OtherDerived, int StoreMode, int LoadMode>
543  EIGEN_STRONG_INLINE void copyPacketByOuterInner(Index outer, Index inner, const DenseBase<OtherDerived>& other)
544  {
545  const Index row = rowIndexByOuterInner(outer,inner);
546  const Index col = colIndexByOuterInner(outer,inner);
547  // derived() is important here: copyCoeff() may be reimplemented in Derived!
548  derived().template copyPacket< OtherDerived, StoreMode, LoadMode>(row, col, other);
549  }
550 #endif
551 
552 };
553 
565 template<typename Derived>
566 class DenseCoeffsBase<Derived, DirectAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
567 {
568  public:
569 
574 
575  using Base::rows;
576  using Base::cols;
577  using Base::size;
578  using Base::derived;
579 
584  inline Index innerStride() const
585  {
586  return derived().innerStride();
587  }
588 
594  inline Index outerStride() const
595  {
596  return derived().outerStride();
597  }
598 
599  // FIXME shall we remove it ?
600  inline Index stride() const
601  {
602  return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
603  }
604 
609  inline Index rowStride() const
610  {
611  return Derived::IsRowMajor ? outerStride() : innerStride();
612  }
613 
618  inline Index colStride() const
619  {
620  return Derived::IsRowMajor ? innerStride() : outerStride();
621  }
622 };
623 
635 template<typename Derived>
637  : public DenseCoeffsBase<Derived, WriteAccessors>
638 {
639  public:
640 
645 
646  using Base::rows;
647  using Base::cols;
648  using Base::size;
649  using Base::derived;
650 
655  inline Index innerStride() const
656  {
657  return derived().innerStride();
658  }
659 
665  inline Index outerStride() const
666  {
667  return derived().outerStride();
668  }
669 
670  // FIXME shall we remove it ?
671  inline Index stride() const
672  {
673  return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
674  }
675 
680  inline Index rowStride() const
681  {
682  return Derived::IsRowMajor ? outerStride() : innerStride();
683  }
684 
689  inline Index colStride() const
690  {
691  return Derived::IsRowMajor ? innerStride() : outerStride();
692  }
693 };
694 
695 namespace internal {
696 
697 template<typename Derived, bool JustReturnZero>
699 {
700  static inline typename Derived::Index run(const Derived&)
701  { return 0; }
702 };
703 
704 template<typename Derived>
705 struct first_aligned_impl<Derived, false>
706 {
707  static inline typename Derived::Index run(const Derived& m)
708  {
709  return internal::first_aligned(&m.const_cast_derived().coeffRef(0,0), m.size());
710  }
711 };
712 
718 template<typename Derived>
719 static inline typename Derived::Index first_aligned(const Derived& m)
720 {
721  return first_aligned_impl
722  <Derived, (Derived::Flags & AlignedBit) || !(Derived::Flags & DirectAccessBit)>
723  ::run(m);
724 }
725 
726 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
728 {
730 };
731 
732 template<typename Derived>
733 struct inner_stride_at_compile_time<Derived, false>
734 {
735  enum { ret = 0 };
736 };
737 
738 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
740 {
742 };
743 
744 template<typename Derived>
745 struct outer_stride_at_compile_time<Derived, false>
746 {
747  enum { ret = 0 };
748 };
749 
750 } // end namespace internal
751 
752 } // end namespace Eigen
753 
754 #endif // EIGEN_DENSECOEFFSBASE_H
EIGEN_STRONG_INLINE CoeffReturnType y() const
EIGEN_STRONG_INLINE Scalar & operator[](Index index)
EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const
EIGEN_STRONG_INLINE Scalar & operator()(Index index)
#define EIGEN_STRONG_INLINE
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner) const
EIGEN_STRONG_INLINE CoeffReturnType operator[](Index index) const
const unsigned int DirectAccessBit
EIGEN_STRONG_INLINE CoeffReturnType z() const
EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col) const
EIGEN_STRONG_INLINE void copyPacket(Index index, const DenseBase< OtherDerived > &other)
const unsigned int LvalueBit
EIGEN_STRONG_INLINE CoeffReturnType operator()(Index row, Index col) const
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
internal::packet_traits< Scalar >::type PacketScalar
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
#define eigen_internal_assert(x)
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:111
internal::traits< Derived >::StorageKind StorageKind
EIGEN_STRONG_INLINE void copyPacket(Index row, Index col, const DenseBase< OtherDerived > &other)
const unsigned int RowMajorBit
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
EIGEN_STRONG_INLINE Scalar & operator()(Index row, Index col)
DenseCoeffsBase< Derived, ReadOnlyAccessors > Base
EIGEN_STRONG_INLINE CoeffReturnType w() const
EIGEN_STRONG_INLINE Scalar & coeffRef(Index row, Index col)
EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) const
internal::traits< Derived >::Index Index
const unsigned int AlignedBit
conditional< is_arithmetic< T >::value, T, typename add_const_on_value_type< T >::type >::type type
EIGEN_STRONG_INLINE void copyCoeff(Index index, const DenseBase< OtherDerived > &other)
EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner) const
internal::add_const_on_value_type_if_arithmetic< typename internal::packet_traits< Scalar >::type >::type PacketReturnType
internal::traits< Derived >::Scalar Scalar
EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
EIGEN_STRONG_INLINE CoeffReturnType x() const
internal::packet_traits< Scalar >::type PacketScalar
static Derived::Index run(const Derived &m)
EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) const
DenseCoeffsBase< Derived, WriteAccessors > Base
static Derived::Index run(const Derived &)
EIGEN_STRONG_INLINE Scalar & coeffRef(Index index)
EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
RowXpr row(Index i)
Definition: BlockMethods.h:725
internal::traits< Derived >::Scalar Scalar
EIGEN_STRONG_INLINE Scalar & coeffRefByOuterInner(Index outer, Index inner)
Base class providing read-only coefficient access to matrices and arrays.
DenseCoeffsBase< Derived, ReadOnlyAccessors > Base
EIGEN_STRONG_INLINE void copyCoeff(Index row, Index col, const DenseBase< OtherDerived > &other)
internal::traits< Derived >::StorageKind StorageKind
internal::traits< Derived >::Index Index
ColXpr col(Index i)
Definition: BlockMethods.h:708
Base class providing read/write coefficient access to matrices and arrays.
EIGEN_STRONG_INLINE void copyPacketByOuterInner(Index outer, Index inner, const DenseBase< OtherDerived > &other)
static Derived::Index first_aligned(const Derived &m)
#define eigen_assert(x)
EIGEN_STRONG_INLINE CoeffReturnType operator()(Index index) const
internal::traits< Derived >::Scalar Scalar
EIGEN_STRONG_INLINE void copyCoeffByOuterInner(Index outer, Index inner, const DenseBase< OtherDerived > &other)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:32