Eigen  3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)
Replicate.h
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 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 namespace internal {
18 template<typename MatrixType,int RowFactor,int ColFactor>
19 struct traits<Replicate<MatrixType,RowFactor,ColFactor> >
20  : traits<MatrixType>
21 {
22  typedef typename MatrixType::Scalar Scalar;
23  typedef typename traits<MatrixType>::StorageKind StorageKind;
24  typedef typename traits<MatrixType>::XprKind XprKind;
25  typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
26  typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNested_;
27  enum {
28  RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic
29  ? Dynamic
30  : RowFactor * MatrixType::RowsAtCompileTime,
31  ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic
32  ? Dynamic
33  : ColFactor * MatrixType::ColsAtCompileTime,
34  //FIXME we don't propagate the max sizes !!!
35  MaxRowsAtCompileTime = RowsAtCompileTime,
36  MaxColsAtCompileTime = ColsAtCompileTime,
37  IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1
38  : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0
39  : (MatrixType::Flags & RowMajorBit) ? 1 : 0,
40 
41  // FIXME enable DirectAccess with negative strides?
42  Flags = IsRowMajor ? RowMajorBit : 0
43  };
44 };
45 }
46 
63 template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
64  : public internal::dense_xpr_base< Replicate<MatrixType,RowFactor,ColFactor> >::type
65 {
66  typedef typename internal::traits<Replicate>::MatrixTypeNested MatrixTypeNested;
67  typedef typename internal::traits<Replicate>::MatrixTypeNested_ MatrixTypeNested_;
68  public:
69 
70  typedef typename internal::dense_xpr_base<Replicate>::type Base;
71  EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
72  typedef internal::remove_all_t<MatrixType> NestedExpression;
73 
74  template<typename OriginalMatrixType>
75  EIGEN_DEVICE_FUNC
76  inline explicit Replicate(const OriginalMatrixType& matrix)
77  : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor)
78  {
79  EIGEN_STATIC_ASSERT((internal::is_same<std::remove_const_t<MatrixType>,OriginalMatrixType>::value),
80  THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
81  eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic);
82  }
83 
84  template<typename OriginalMatrixType>
85  EIGEN_DEVICE_FUNC
86  inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
87  : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor)
88  {
89  EIGEN_STATIC_ASSERT((internal::is_same<std::remove_const_t<MatrixType>,OriginalMatrixType>::value),
90  THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
91  }
92 
93  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
94  inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
95  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
96  inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
97 
98  EIGEN_DEVICE_FUNC
99  const MatrixTypeNested_& nestedExpression() const
100  {
101  return m_matrix;
102  }
103 
104  protected:
105  MatrixTypeNested m_matrix;
106  const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
107  const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
108 };
109 
118 template<typename Derived>
119 template<int RowFactor, int ColFactor>
120 EIGEN_DEVICE_FUNC const Replicate<Derived,RowFactor,ColFactor>
122 {
123  return Replicate<Derived,RowFactor,ColFactor>(derived());
124 }
125 
134 template<typename ExpressionType, int Direction>
137 {
139  (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1);
140 }
141 
142 } // end namespace Eigen
143 
144 #endif // EIGEN_REPLICATE_H
const Replicate< Derived, RowFactor, ColFactor > replicate() const
Definition: Replicate.h:121
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:65
Eigen::Index Index
Definition: VectorwiseOp.h:193
const ReplicateReturnType replicate(Index factor) const
Definition: Replicate.h:136
@ Horizontal
Definition: Constants.h:269
@ Vertical
Definition: Constants.h:266
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24