DenseBase.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) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
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_DENSEBASE_H
12 #define EIGEN_DENSEBASE_H
13 
14 namespace Eigen {
15 
16 namespace internal {
17 
18 // The index type defined by EIGEN_DEFAULT_DENSE_INDEX_TYPE must be a signed type.
19 // This dummy function simply aims at checking that at compile time.
20 static inline void check_DenseIndex_is_signed() {
21  EIGEN_STATIC_ASSERT(NumTraits<DenseIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE);
22 }
23 
24 } // end namespace internal
25 
41 template<typename Derived> class DenseBase
42 #ifndef EIGEN_PARSED_BY_DOXYGEN
43  : public internal::special_scalar_op_base<Derived,typename internal::traits<Derived>::Scalar,
44  typename NumTraits<typename internal::traits<Derived>::Scalar>::Real>
45 #else
46  : public DenseCoeffsBase<Derived>
47 #endif // not EIGEN_PARSED_BY_DOXYGEN
48 {
49  public:
51  typename NumTraits<typename internal::traits<Derived>::Scalar>::Real>::operator*;
52 
54 
56 
62 
66 
68  using Base::derived;
69  using Base::const_cast_derived;
70  using Base::rows;
71  using Base::cols;
72  using Base::size;
73  using Base::rowIndexByOuterInner;
74  using Base::colIndexByOuterInner;
75  using Base::coeff;
76  using Base::coeffByOuterInner;
77  using Base::packet;
78  using Base::packetByOuterInner;
79  using Base::writePacket;
80  using Base::writePacketByOuterInner;
81  using Base::coeffRef;
82  using Base::coeffRefByOuterInner;
83  using Base::copyCoeff;
84  using Base::copyCoeffByOuterInner;
85  using Base::copyPacket;
86  using Base::copyPacketByOuterInner;
87  using Base::operator();
88  using Base::operator[];
89  using Base::x;
90  using Base::y;
91  using Base::z;
92  using Base::w;
93  using Base::stride;
94  using Base::innerStride;
95  using Base::outerStride;
96  using Base::rowStride;
97  using Base::colStride;
98  typedef typename Base::CoeffReturnType CoeffReturnType;
99 
100  enum {
101 
167  IsRowMajor = int(Flags) & RowMajorBit,
169  InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime)
170  : int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
171 
172  CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
177  InnerStrideAtCompileTime = internal::inner_stride_at_compile_time<Derived>::ret,
178  OuterStrideAtCompileTime = internal::outer_stride_at_compile_time<Derived>::ret
179  };
180 
181  enum { ThisConstantIsPrivateInPlainObjectBase };
182 
185  inline Index nonZeros() const { return size(); }
196  Index outerSize() const
197  {
198  return IsVectorAtCompileTime ? 1
199  : int(IsRowMajor) ? this->rows() : this->cols();
200  }
201 
207  Index innerSize() const
208  {
209  return IsVectorAtCompileTime ? this->size()
210  : int(IsRowMajor) ? this->cols() : this->rows();
211  }
212 
217  void resize(Index newSize)
218  {
219  EIGEN_ONLY_USED_FOR_DEBUG(newSize);
220  eigen_assert(newSize == this->size()
221  && "DenseBase::resize() does not actually allow to resize.");
222  }
227  void resize(Index nbRows, Index nbCols)
228  {
231  eigen_assert(nbRows == this->rows() && nbCols == this->cols()
232  && "DenseBase::resize() does not actually allow to resize.");
233  }
234 
235 #ifndef EIGEN_PARSED_BY_DOXYGEN
236 
245 
246 #endif // not EIGEN_PARSED_BY_DOXYGEN
247 
249  template<typename OtherDerived>
250  Derived& operator=(const DenseBase<OtherDerived>& other);
251 
255  Derived& operator=(const DenseBase& other);
256 
257  template<typename OtherDerived>
258  Derived& operator=(const EigenBase<OtherDerived> &other);
259 
260  template<typename OtherDerived>
261  Derived& operator+=(const EigenBase<OtherDerived> &other);
262 
263  template<typename OtherDerived>
264  Derived& operator-=(const EigenBase<OtherDerived> &other);
265 
266  template<typename OtherDerived>
267  Derived& operator=(const ReturnByValue<OtherDerived>& func);
268 
269 #ifndef EIGEN_PARSED_BY_DOXYGEN
270 
271  template<typename OtherDerived>
272  Derived& lazyAssign(const DenseBase<OtherDerived>& other);
273 #endif // not EIGEN_PARSED_BY_DOXYGEN
274 
275  CommaInitializer<Derived> operator<< (const Scalar& s);
276 
277  template<unsigned int Added,unsigned int Removed>
278  const Flagged<Derived, Added, Removed> flagged() const;
279 
280  template<typename OtherDerived>
281  CommaInitializer<Derived> operator<< (const DenseBase<OtherDerived>& other);
282 
285  ConstTransposeReturnType transpose() const;
286  void transposeInPlace();
287 #ifndef EIGEN_NO_DEBUG
288  protected:
289  template<typename OtherDerived>
290  void checkTransposeAliasing(const OtherDerived& other) const;
291  public:
292 #endif
293 
294 
295  static const ConstantReturnType
296  Constant(Index rows, Index cols, const Scalar& value);
297  static const ConstantReturnType
298  Constant(Index size, const Scalar& value);
299  static const ConstantReturnType
300  Constant(const Scalar& value);
301 
302  static const SequentialLinSpacedReturnType
303  LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high);
304  static const RandomAccessLinSpacedReturnType
305  LinSpaced(Index size, const Scalar& low, const Scalar& high);
306  static const SequentialLinSpacedReturnType
307  LinSpaced(Sequential_t, const Scalar& low, const Scalar& high);
308  static const RandomAccessLinSpacedReturnType
309  LinSpaced(const Scalar& low, const Scalar& high);
310 
311  template<typename CustomNullaryOp>
313  NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func);
314  template<typename CustomNullaryOp>
316  NullaryExpr(Index size, const CustomNullaryOp& func);
317  template<typename CustomNullaryOp>
319  NullaryExpr(const CustomNullaryOp& func);
320 
321  static const ConstantReturnType Zero(Index rows, Index cols);
322  static const ConstantReturnType Zero(Index size);
323  static const ConstantReturnType Zero();
324  static const ConstantReturnType Ones(Index rows, Index cols);
325  static const ConstantReturnType Ones(Index size);
326  static const ConstantReturnType Ones();
327 
328  void fill(const Scalar& value);
329  Derived& setConstant(const Scalar& value);
330  Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high);
331  Derived& setLinSpaced(const Scalar& low, const Scalar& high);
332  Derived& setZero();
333  Derived& setOnes();
334  Derived& setRandom();
336  template<typename OtherDerived>
337  bool isApprox(const DenseBase<OtherDerived>& other,
338  const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
339  bool isMuchSmallerThan(const RealScalar& other,
340  const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
341  template<typename OtherDerived>
342  bool isMuchSmallerThan(const DenseBase<OtherDerived>& other,
343  const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
344 
345  bool isApproxToConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
346  bool isConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
347  bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
348  bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const;
349 
350  inline bool hasNaN() const;
351  inline bool allFinite() const;
352 
353  inline Derived& operator*=(const Scalar& other);
354  inline Derived& operator/=(const Scalar& other);
355 
362  EIGEN_STRONG_INLINE EvalReturnType eval() const
363  {
364  // Even though MSVC does not honor strong inlining when the return type
365  // is a dynamic matrix, we desperately need strong inlining for fixed
366  // size types on MSVC.
367  return typename internal::eval<Derived>::type(derived());
368  }
369 
373  template<typename OtherDerived>
374  void swap(const DenseBase<OtherDerived>& other,
375  int = OtherDerived::ThisConstantIsPrivateInPlainObjectBase)
376  {
377  SwapWrapper<Derived>(derived()).lazyAssign(other.derived());
378  }
379 
383  template<typename OtherDerived>
385  {
386  SwapWrapper<Derived>(derived()).lazyAssign(other.derived());
387  }
388 
389 
390  inline const NestByValue<Derived> nestByValue() const;
391  inline const ForceAlignedAccess<Derived> forceAlignedAccess() const;
392  inline ForceAlignedAccess<Derived> forceAlignedAccess();
393  template<bool Enable> inline const typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf() const;
394  template<bool Enable> inline typename internal::conditional<Enable,ForceAlignedAccess<Derived>,Derived&>::type forceAlignedAccessIf();
395 
396  Scalar sum() const;
397  Scalar mean() const;
398  Scalar trace() const;
399 
400  Scalar prod() const;
401 
402  typename internal::traits<Derived>::Scalar minCoeff() const;
403  typename internal::traits<Derived>::Scalar maxCoeff() const;
404 
405  template<typename IndexType>
406  typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const;
407  template<typename IndexType>
408  typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const;
409  template<typename IndexType>
410  typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const;
411  template<typename IndexType>
412  typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const;
413 
414  template<typename BinaryOp>
416  redux(const BinaryOp& func) const;
417 
418  template<typename Visitor>
419  void visit(Visitor& func) const;
420 
421  inline const WithFormat<Derived> format(const IOFormat& fmt) const;
422 
424  CoeffReturnType value() const
425  {
427  eigen_assert(this->rows() == 1 && this->cols() == 1);
428  return derived().coeff(0,0);
429  }
430 
431  bool all(void) const;
432  bool any(void) const;
433  Index count() const;
434 
439 
440  ConstRowwiseReturnType rowwise() const;
441  RowwiseReturnType rowwise();
442  ConstColwiseReturnType colwise() const;
443  ColwiseReturnType colwise();
444 
445  static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index rows, Index cols);
446  static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random(Index size);
447  static const CwiseNullaryOp<internal::scalar_random_op<Scalar>,Derived> Random();
448 
449  template<typename ThenDerived,typename ElseDerived>
451  select(const DenseBase<ThenDerived>& thenMatrix,
452  const DenseBase<ElseDerived>& elseMatrix) const;
454  template<typename ThenDerived>
456  select(const DenseBase<ThenDerived>& thenMatrix, const typename ThenDerived::Scalar& elseScalar) const;
457 
458  template<typename ElseDerived>
460  select(const typename ElseDerived::Scalar& thenScalar, const DenseBase<ElseDerived>& elseMatrix) const;
461 
462  template<int p> RealScalar lpNorm() const;
463 
464  template<int RowFactor, int ColFactor>
465  const Replicate<Derived,RowFactor,ColFactor> replicate() const;
466  const Replicate<Derived,Dynamic,Dynamic> replicate(Index rowFacor,Index colFactor) const;
467 
470  ReverseReturnType reverse();
471  ConstReverseReturnType reverse() const;
472  void reverseInPlace();
473 
474 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
475 # include "../plugins/BlockMethods.h"
476 # ifdef EIGEN_DENSEBASE_PLUGIN
477 # include EIGEN_DENSEBASE_PLUGIN
478 # endif
479 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
480 
481 #ifdef EIGEN2_SUPPORT
482 
483  Block<Derived> corner(CornerType type, Index cRows, Index cCols);
484  const Block<Derived> corner(CornerType type, Index cRows, Index cCols) const;
485  template<int CRows, int CCols>
487  template<int CRows, int CCols>
488  const Block<Derived, CRows, CCols> corner(CornerType type) const;
489 
490 #endif // EIGEN2_SUPPORT
491 
493  // disable the use of evalTo for dense objects with a nice compilation error
494  template<typename Dest> inline void evalTo(Dest& ) const
495  {
496  EIGEN_STATIC_ASSERT((internal::is_same<Dest,void>::value),THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS);
497  }
498 
499  protected:
502  {
503  /* Just checks for self-consistency of the flags.
504  * Only do it when debugging Eigen, as this borders on paranoiac and could slow compilation down
505  */
506 #ifdef EIGEN_INTERNAL_DEBUGGING
507  EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor))
508  && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, int(!IsRowMajor))),
509  INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION)
510 #endif
511  }
512 
513  private:
514  explicit DenseBase(int);
515  DenseBase(int,int);
516  template<typename OtherDerived> explicit DenseBase(const DenseBase<OtherDerived>&);
517 };
518 
519 } // end namespace Eigen
520 
521 #endif // EIGEN_DENSEBASE_H
Generic expression of a matrix where all coefficients are defined by a functor.
#define EIGEN_STATIC_ASSERT_SIZE_1x1(TYPE)
Definition: StaticAssert.h:186
CwiseNullaryOp< internal::linspaced_op< Scalar, true >, Derived > RandomAccessLinSpacedReturnType
Definition: DenseBase.h:242
Enforce aligned packet loads and stores regardless of what is requested.
internal::packet_traits< Scalar >::type PacketScalar
Definition: DenseBase.h:64
#define EIGEN_STRONG_INLINE
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:63
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
Base::CoeffReturnType CoeffReturnType
Definition: DenseBase.h:98
Expression with modified flags.
Definition: Flagged.h:39
BooleanType isZero(real_t x, real_t TOL=ZERO)
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:61
internal::traits< Derived >::StorageKind StorageKind
Definition: DenseBase.h:53
Expression of the transpose of a matrix.
Definition: Transpose.h:57
static void check_DenseIndex_is_signed()
Definition: DenseBase.h:20
internal::add_const< Transpose< const Derived > >::type ConstTransposeReturnType
Definition: DenseBase.h:284
DenseCoeffsBase< Derived > Base
Definition: DenseBase.h:67
const VectorwiseOp< const Derived, Horizontal > ConstRowwiseReturnType
Definition: DenseBase.h:436
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
CwiseNullaryOp< internal::linspaced_op< Scalar, false >, Derived > SequentialLinSpacedReturnType
Definition: DenseBase.h:240
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:111
Pseudo expression providing partial reduction operations.
VectorwiseOp< Derived, Horizontal > RowwiseReturnType
Definition: DenseBase.h:435
bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, typename NumTraits< Scalar >::Real precision=NumTraits< Scalar >::dummy_precision())
const unsigned int RowMajorBit
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
const Reverse< const Derived, BothDirections > ConstReverseReturnType
Definition: DenseBase.h:469
void resize(Index newSize)
Definition: DenseBase.h:217
Helper class used by the comma initializer operator.
Index innerSize() const
Definition: DenseBase.h:207
internal::add_const_on_value_type< typename internal::eval< Derived >::type >::type EvalReturnType
Definition: DenseBase.h:356
ExportArithmeticStatement operator-=(const ExportVariable &arg1, const ExportVariable &arg2)
Reverse< Derived, BothDirections > ReverseReturnType
Definition: DenseBase.h:468
Index outerSize() const
Definition: DenseBase.h:196
CoeffReturnType value() const
Definition: DenseBase.h:424
bool isApprox(const Scalar &x, const Scalar &y, typename NumTraits< Scalar >::Real precision=NumTraits< Scalar >::dummy_precision())
Dense storage base class for matrices and arrays.
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:62
void resize(Index nbRows, Index nbCols)
Definition: DenseBase.h:227
ExportArithmeticStatement operator+=(const ExportVariable &arg1, const ExportVariable &arg2)
Expression which must be nested by value.
Definition: NestByValue.h:35
ExportStatementBlock & operator<<(ExportStatementBlock &_block, const ExportStatement &_statement)
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:65
Expression of a fixed-size or dynamic-size block.
Definition: Core/Block.h:102
RowXpr row(Index i)
Definition: BlockMethods.h:725
CwiseNullaryOp< internal::scalar_constant_op< Scalar >, Derived > ConstantReturnType
Definition: DenseBase.h:238
Matrix< typename NumTraits< typename internal::traits< Derived >::Scalar >::Real, internal::traits< Derived >::ColsAtCompileTime, 1 > EigenvaluesReturnType
Definition: DenseBase.h:244
VectorwiseOp< Derived, Vertical > ColwiseReturnType
Definition: DenseBase.h:437
EIGEN_STRONG_INLINE EvalReturnType eval() const
Definition: DenseBase.h:362
void swap(const DenseBase< OtherDerived > &other, int=OtherDerived::ThisConstantIsPrivateInPlainObjectBase)
Definition: DenseBase.h:374
const VectorwiseOp< const Derived, Vertical > ConstColwiseReturnType
Definition: DenseBase.h:438
#define EIGEN_IMPLIES(a, b)
ColXpr col(Index i)
Definition: BlockMethods.h:708
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
#define eigen_assert(x)
Pseudo expression providing matrix output with given format.
Definition: IO.h:90
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:70
void evalTo(Dest &) const
Definition: DenseBase.h:494
Stores a set of parameters controlling the way matrices are printed.
Definition: IO.h:50
void swap(PlainObjectBase< OtherDerived > &other)
Definition: DenseBase.h:384
Expression of a coefficient wise version of the C++ ternary operator ?:
Definition: Select.h:55


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