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 #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;
73 
74  template<typename OriginalMatrixType>
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>
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 
94  inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
96  inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
97 
100  {
101  return m_matrix;
102  }
103 
104  protected:
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>
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
#define EIGEN_CONSTEXPR
Definition: Macros.h:747
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1168
#define eigen_assert(x)
Definition: Macros.h:902
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
Matrix< float, 1, Dynamic > MatrixType
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:61
const Replicate< Derived, RowFactor, ColFactor > replicate() const
Definition: Replicate.h:121
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:65
internal::traits< Replicate >::MatrixTypeNested_ MatrixTypeNested_
Definition: Replicate.h:67
internal::traits< Replicate >::MatrixTypeNested MatrixTypeNested
Definition: Replicate.h:66
EIGEN_CONSTEXPR Index rows() const
Definition: Replicate.h:94
internal::dense_xpr_base< Replicate >::type Base
Definition: Replicate.h:70
const internal::variable_if_dynamic< Index, ColFactor > m_colFactor
Definition: Replicate.h:107
Replicate(const OriginalMatrixType &matrix, Index rowFactor, Index colFactor)
Definition: Replicate.h:86
const internal::variable_if_dynamic< Index, RowFactor > m_rowFactor
Definition: Replicate.h:106
internal::remove_all_t< MatrixType > NestedExpression
Definition: Replicate.h:72
EIGEN_CONSTEXPR Index cols() const
Definition: Replicate.h:96
MatrixTypeNested m_matrix
Definition: Replicate.h:105
const MatrixTypeNested_ & nestedExpression() const
Definition: Replicate.h:99
Eigen::Index Index
Definition: VectorwiseOp.h:193
const ReplicateReturnType replicate(Index factor) const
Definition: Replicate.h:136
Replicate< ExpressionType,(isVertical?Dynamic:1),(isHorizontal?Dynamic:1)> ReplicateReturnType
Definition: VectorwiseOp.h:553
@ Horizontal
Definition: Constants.h:269
@ Vertical
Definition: Constants.h:266
const unsigned int RowMajorBit
Definition: Constants.h:68
typename remove_all< T >::type remove_all_t
Definition: Meta.h:119
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
const int Dynamic
Definition: Constants.h:24