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:
40 
41  // Explanation for this CoeffReturnType typedef.
42  // - This is the return type of the coeff() method.
43  // - The LvalueBit means exactly that we can offer a coeffRef() method, which means exactly that we can get references
44  // to coeffs, which means exactly that we can have coeff() return a const reference (as opposed to returning a value).
45  // - The is_artihmetic check is required since "const int", "const double", etc. will cause warnings on some systems
46  // while the declaration of "const T", where T is a non arithmetic type does not. Always returning "const Scalar&" is
47  // not possible, since the underlying expressions might not offer a valid address the reference could be referring to.
49  const Scalar&,
52 
56 
58  using Base::rows;
59  using Base::cols;
60  using Base::size;
61  using Base::derived;
62 
63  EIGEN_DEVICE_FUNC
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_DEVICE_FUNC
74  {
75  return int(Derived::ColsAtCompileTime) == 1 ? 0
76  : int(Derived::RowsAtCompileTime) == 1 ? inner
77  : int(Derived::Flags)&RowMajorBit ? inner
78  : outer;
79  }
80 
95  EIGEN_DEVICE_FUNC
97  {
98  eigen_internal_assert(row >= 0 && row < rows()
99  && col >= 0 && col < cols());
100  return internal::evaluator<Derived>(derived()).coeff(row,col);
101  }
102 
103  EIGEN_DEVICE_FUNC
105  {
106  return coeff(rowIndexByOuterInner(outer, inner),
107  colIndexByOuterInner(outer, inner));
108  }
109 
114  EIGEN_DEVICE_FUNC
116  {
117  eigen_assert(row >= 0 && row < rows()
118  && col >= 0 && col < cols());
119  return coeff(row, col);
120  }
121 
137  EIGEN_DEVICE_FUNC
139  coeff(Index index) const
140  {
142  THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
143  eigen_internal_assert(index >= 0 && index < size());
144  return internal::evaluator<Derived>(derived()).coeff(index);
145  }
146 
147 
156  EIGEN_DEVICE_FUNC
158  operator[](Index index) const
159  {
160  EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
161  THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
162  eigen_assert(index >= 0 && index < size());
163  return coeff(index);
164  }
165 
176  EIGEN_DEVICE_FUNC
178  operator()(Index index) const
179  {
180  eigen_assert(index >= 0 && index < size());
181  return coeff(index);
182  }
183 
186  EIGEN_DEVICE_FUNC
188  x() const { return (*this)[0]; }
189 
192  EIGEN_DEVICE_FUNC
194  y() const
195  {
196  EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS);
197  return (*this)[1];
198  }
199 
202  EIGEN_DEVICE_FUNC
204  z() const
205  {
206  EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS);
207  return (*this)[2];
208  }
209 
212  EIGEN_DEVICE_FUNC
214  w() const
215  {
216  EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS);
217  return (*this)[3];
218  }
219 
230  template<int LoadMode>
231  EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col) const
232  {
233  typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
234  eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
235  return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(row,col);
236  }
237 
238 
240  template<int LoadMode>
241  EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner) const
242  {
243  return packet<LoadMode>(rowIndexByOuterInner(outer, inner),
244  colIndexByOuterInner(outer, inner));
245  }
246 
257  template<int LoadMode>
258  EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
259  {
261  THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
262  typedef typename internal::packet_traits<Scalar>::type DefaultPacketType;
263  eigen_internal_assert(index >= 0 && index < size());
264  return internal::evaluator<Derived>(derived()).template packet<LoadMode,DefaultPacketType>(index);
265  }
266 
267  protected:
268  // explanation: DenseBase is doing "using ..." on the methods from DenseCoeffsBase.
269  // But some methods are only available in the DirectAccess case.
270  // So we add dummy methods here with these names, so that "using... " doesn't fail.
271  // It's not private so that the child class DenseBase can access them, and it's not public
272  // either since it's an implementation detail, so has to be protected.
273  void coeffRef();
274  void coeffRefByOuterInner();
275  void writePacket();
276  void writePacketByOuterInner();
277  void copyCoeff();
278  void copyCoeffByOuterInner();
279  void copyPacket();
280  void copyPacketByOuterInner();
281  void stride();
282  void innerStride();
283  void outerStride();
284  void rowStride();
285  void colStride();
286 };
287 
299 template<typename Derived>
300 class DenseCoeffsBase<Derived, WriteAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
301 {
302  public:
303 
305 
310 
311  using Base::coeff;
312  using Base::rows;
313  using Base::cols;
314  using Base::size;
315  using Base::derived;
316  using Base::rowIndexByOuterInner;
317  using Base::colIndexByOuterInner;
318  using Base::operator[];
319  using Base::operator();
320  using Base::x;
321  using Base::y;
322  using Base::z;
323  using Base::w;
324 
339  EIGEN_DEVICE_FUNC
341  {
342  eigen_internal_assert(row >= 0 && row < rows()
343  && col >= 0 && col < cols());
344  return internal::evaluator<Derived>(derived()).coeffRef(row,col);
345  }
346 
347  EIGEN_DEVICE_FUNC
348  EIGEN_STRONG_INLINE Scalar&
350  {
351  return coeffRef(rowIndexByOuterInner(outer, inner),
352  colIndexByOuterInner(outer, inner));
353  }
354 
360  EIGEN_DEVICE_FUNC
361  EIGEN_STRONG_INLINE Scalar&
363  {
364  eigen_assert(row >= 0 && row < rows()
365  && col >= 0 && col < cols());
366  return coeffRef(row, col);
367  }
368 
369 
385  EIGEN_DEVICE_FUNC
386  EIGEN_STRONG_INLINE Scalar&
388  {
390  THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS)
391  eigen_internal_assert(index >= 0 && index < size());
392  return internal::evaluator<Derived>(derived()).coeffRef(index);
393  }
394 
402  EIGEN_DEVICE_FUNC
403  EIGEN_STRONG_INLINE Scalar&
405  {
406  EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
407  THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
408  eigen_assert(index >= 0 && index < size());
409  return coeffRef(index);
410  }
411 
421  EIGEN_DEVICE_FUNC
422  EIGEN_STRONG_INLINE Scalar&
424  {
425  eigen_assert(index >= 0 && index < size());
426  return coeffRef(index);
427  }
428 
431  EIGEN_DEVICE_FUNC
432  EIGEN_STRONG_INLINE Scalar&
433  x() { return (*this)[0]; }
434 
437  EIGEN_DEVICE_FUNC
438  EIGEN_STRONG_INLINE Scalar&
439  y()
440  {
441  EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=2, OUT_OF_RANGE_ACCESS);
442  return (*this)[1];
443  }
444 
447  EIGEN_DEVICE_FUNC
448  EIGEN_STRONG_INLINE Scalar&
449  z()
450  {
451  EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=3, OUT_OF_RANGE_ACCESS);
452  return (*this)[2];
453  }
454 
457  EIGEN_DEVICE_FUNC
458  EIGEN_STRONG_INLINE Scalar&
459  w()
460  {
461  EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime==-1 || Derived::SizeAtCompileTime>=4, OUT_OF_RANGE_ACCESS);
462  return (*this)[3];
463  }
464 };
465 
477 template<typename Derived>
478 class DenseCoeffsBase<Derived, DirectAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
479 {
480  public:
481 
485 
486  using Base::rows;
487  using Base::cols;
488  using Base::size;
489  using Base::derived;
490 
495  EIGEN_DEVICE_FUNC
496  inline Index innerStride() const
497  {
498  return derived().innerStride();
499  }
500 
506  EIGEN_DEVICE_FUNC
507  inline Index outerStride() const
508  {
509  return derived().outerStride();
510  }
511 
512  // FIXME shall we remove it ?
513  inline Index stride() const
514  {
515  return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
516  }
517 
522  EIGEN_DEVICE_FUNC
523  inline Index rowStride() const
524  {
525  return Derived::IsRowMajor ? outerStride() : innerStride();
526  }
527 
532  EIGEN_DEVICE_FUNC
533  inline Index colStride() const
534  {
535  return Derived::IsRowMajor ? innerStride() : outerStride();
536  }
537 };
538 
550 template<typename Derived>
552  : public DenseCoeffsBase<Derived, WriteAccessors>
553 {
554  public:
555 
559 
560  using Base::rows;
561  using Base::cols;
562  using Base::size;
563  using Base::derived;
564 
569  EIGEN_DEVICE_FUNC
570  inline Index innerStride() const
571  {
572  return derived().innerStride();
573  }
574 
580  EIGEN_DEVICE_FUNC
581  inline Index outerStride() const
582  {
583  return derived().outerStride();
584  }
585 
586  // FIXME shall we remove it ?
587  inline Index stride() const
588  {
589  return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
590  }
591 
596  EIGEN_DEVICE_FUNC
597  inline Index rowStride() const
598  {
599  return Derived::IsRowMajor ? outerStride() : innerStride();
600  }
601 
606  EIGEN_DEVICE_FUNC
607  inline Index colStride() const
608  {
609  return Derived::IsRowMajor ? innerStride() : outerStride();
610  }
611 };
612 
613 namespace internal {
614 
615 template<int Alignment, typename Derived, bool JustReturnZero>
617 {
618  static inline Index run(const Derived&)
619  { return 0; }
620 };
621 
622 template<int Alignment, typename Derived>
623 struct first_aligned_impl<Alignment, Derived, false>
624 {
625  static inline Index run(const Derived& m)
626  {
627  return internal::first_aligned<Alignment>(m.data(), m.size());
628  }
629 };
630 
638 template<int Alignment, typename Derived>
639 static inline Index first_aligned(const DenseBase<Derived>& m)
640 {
641  enum { ReturnZero = (int(evaluator<Derived>::Alignment) >= Alignment) || !(Derived::Flags & DirectAccessBit) };
643 }
644 
645 template<typename Derived>
647 {
648  typedef typename Derived::Scalar Scalar;
649  typedef typename packet_traits<Scalar>::type DefaultPacketType;
650  return internal::first_aligned<int(unpacket_traits<DefaultPacketType>::alignment),Derived>(m);
651 }
652 
653 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
655 {
657 };
658 
659 template<typename Derived>
660 struct inner_stride_at_compile_time<Derived, false>
661 {
662  enum { ret = 0 };
663 };
664 
665 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
667 {
669 };
670 
671 template<typename Derived>
672 struct outer_stride_at_compile_time<Derived, false>
673 {
674  enum { ret = 0 };
675 };
676 
677 } // end namespace internal
678 
679 } // end namespace Eigen
680 
681 #endif // EIGEN_DENSECOEFFSBASE_H
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) const
static Index first_aligned(const DenseBase< Derived > &m)
EIGEN_DEVICE_FUNC Index outerStride() const
const unsigned int DirectAccessBit
Definition: Constants.h:150
EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col) const
const unsigned int LvalueBit
Definition: Constants.h:139
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator()(Index index)
Definition: LDLT.h:16
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
internal::packet_traits< Scalar >::type PacketScalar
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:122
internal::traits< Derived >::StorageKind StorageKind
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType z() const
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:38
const unsigned int RowMajorBit
Definition: Constants.h:61
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType operator[](Index index) const
DenseCoeffsBase< Derived, ReadOnlyAccessors > Base
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner) const
static Index first_default_aligned(const DenseBase< Derived > &m)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator()(Index row, Index col)
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
Definition: BlockMethods.h:838
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType w() const
conditional< is_arithmetic< T >::value, T, typename add_const_on_value_type< T >::type >::type type
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_DEVICE_FUNC Index innerStride() const
EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType operator()(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
internal::packet_traits< Scalar >::type PacketScalar
#define eigen_assert(x)
Definition: Macros.h:577
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). */.
Definition: BlockMethods.h:859
DenseCoeffsBase< Derived, WriteAccessors > Base
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRefByOuterInner(Index outer, Index inner)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType x() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index index)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & x()
static Index run(const Derived &)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & y()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index row, Index col)
internal::traits< Derived >::Scalar Scalar
Base class providing read-only coefficient access to matrices and arrays.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) const
DenseCoeffsBase< Derived, ReadOnlyAccessors > Base
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator[](Index index)
#define eigen_internal_assert(x)
Definition: Macros.h:583
internal::traits< Derived >::StorageKind StorageKind
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & z()
Base class providing read/write coefficient access to matrices and arrays.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType y() const
internal::traits< Derived >::Scalar Scalar
const unsigned int LinearAccessBit
Definition: Constants.h:125
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & w()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType operator()(Index row, Index col) const


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:09