Replicate.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) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
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_REPLICATE_H
11 #define EIGEN_REPLICATE_H
12 
13 namespace Eigen {
14 
30 namespace internal {
31 template<typename MatrixType,int RowFactor,int ColFactor>
32 struct traits<Replicate<MatrixType,RowFactor,ColFactor> >
33  : traits<MatrixType>
34 {
35  typedef typename MatrixType::Scalar Scalar;
38  enum {
39  Factor = (RowFactor==Dynamic || ColFactor==Dynamic) ? Dynamic : RowFactor*ColFactor
40  };
43  enum {
44  RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic
45  ? Dynamic
46  : RowFactor * MatrixType::RowsAtCompileTime,
47  ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic
48  ? Dynamic
49  : ColFactor * MatrixType::ColsAtCompileTime,
50  //FIXME we don't propagate the max sizes !!!
51  MaxRowsAtCompileTime = RowsAtCompileTime,
52  MaxColsAtCompileTime = ColsAtCompileTime,
53  IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1
54  : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0
55  : (MatrixType::Flags & RowMajorBit) ? 1 : 0,
56  Flags = (_MatrixTypeNested::Flags & HereditaryBits & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0),
57  CoeffReadCost = _MatrixTypeNested::CoeffReadCost
58  };
59 };
60 }
61 
62 template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
63  : public internal::dense_xpr_base< Replicate<MatrixType,RowFactor,ColFactor> >::type
64 {
67  public:
68 
71 
72  template<typename OriginalMatrixType>
73  inline explicit Replicate(const OriginalMatrixType& a_matrix)
74  : m_matrix(a_matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor)
75  {
77  THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
78  eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic);
79  }
80 
81  template<typename OriginalMatrixType>
82  inline Replicate(const OriginalMatrixType& a_matrix, Index rowFactor, Index colFactor)
83  : m_matrix(a_matrix), m_rowFactor(rowFactor), m_colFactor(colFactor)
84  {
86  THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
87  }
88 
89  inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
90  inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
91 
92  inline Scalar coeff(Index rowId, Index colId) const
93  {
94  // try to avoid using modulo; this is a pure optimization strategy
95  const Index actual_row = internal::traits<MatrixType>::RowsAtCompileTime==1 ? 0
96  : RowFactor==1 ? rowId
97  : rowId%m_matrix.rows();
98  const Index actual_col = internal::traits<MatrixType>::ColsAtCompileTime==1 ? 0
99  : ColFactor==1 ? colId
100  : colId%m_matrix.cols();
101 
102  return m_matrix.coeff(actual_row, actual_col);
103  }
104  template<int LoadMode>
105  inline PacketScalar packet(Index rowId, Index colId) const
106  {
107  const Index actual_row = internal::traits<MatrixType>::RowsAtCompileTime==1 ? 0
108  : RowFactor==1 ? rowId
109  : rowId%m_matrix.rows();
110  const Index actual_col = internal::traits<MatrixType>::ColsAtCompileTime==1 ? 0
111  : ColFactor==1 ? colId
112  : colId%m_matrix.cols();
113 
114  return m_matrix.template packet<LoadMode>(actual_row, actual_col);
115  }
116 
117  const _MatrixTypeNested& nestedExpression() const
118  {
119  return m_matrix;
120  }
121 
122  protected:
123  MatrixTypeNested m_matrix;
126 };
127 
136 template<typename Derived>
137 template<int RowFactor, int ColFactor>
140 {
141  return Replicate<Derived,RowFactor,ColFactor>(derived());
142 }
143 
152 template<typename Derived>
154 DenseBase<Derived>::replicate(Index rowFactor,Index colFactor) const
155 {
156  return Replicate<Derived,Dynamic,Dynamic>(derived(),rowFactor,colFactor);
157 }
158 
167 template<typename ExpressionType, int Direction>
170 {
172  (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1);
173 }
174 
175 } // end namespace Eigen
176 
177 #endif // EIGEN_REPLICATE_H
const _MatrixTypeNested & nestedExpression() const
Definition: Replicate.h:117
ExpressionType::Index Index
Definition: VectorwiseOp.h:171
#define inline
Definition: Types.h:109
Replicate< ExpressionType, Direction==Vertical?Dynamic:1, Direction==Horizontal?Dynamic:1 > ReplicateReturnType
Definition: VectorwiseOp.h:411
const Replicate< Derived, RowFactor, ColFactor > replicate() const
Definition: Replicate.h:139
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:61
Scalar coeff(Index rowId, Index colId) const
Definition: Replicate.h:92
Index cols() const
Definition: Replicate.h:90
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:111
const internal::variable_if_dynamic< Index, RowFactor > m_rowFactor
Definition: Replicate.h:124
const unsigned int RowMajorBit
internal::dense_xpr_base< Replicate >::type Base
Definition: Replicate.h:69
const unsigned int HereditaryBits
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:62
PacketScalar packet(Index rowId, Index colId) const
Definition: Replicate.h:105
Index rows() const
Definition: Replicate.h:89
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
const ReplicateReturnType replicate(Index factor) const
Definition: Replicate.h:169
remove_reference< MatrixTypeNested >::type _MatrixTypeNested
Definition: Replicate.h:42
MatrixTypeNested m_matrix
Definition: Replicate.h:123
const internal::variable_if_dynamic< Index, ColFactor > m_colFactor
Definition: Replicate.h:125
Replicate(const OriginalMatrixType &a_matrix, Index rowFactor, Index colFactor)
Definition: Replicate.h:82
internal::traits< Replicate >::_MatrixTypeNested _MatrixTypeNested
Definition: Replicate.h:66
#define eigen_assert(x)
internal::traits< Replicate >::MatrixTypeNested MatrixTypeNested
Definition: Replicate.h:65


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