Eigen  3.2.92
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 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;
36  typedef typename traits<MatrixType>::StorageKind StorageKind;
37  typedef typename traits<MatrixType>::XprKind XprKind;
38  typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
39  typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
40  enum {
41  RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic
42  ? Dynamic
43  : RowFactor * MatrixType::RowsAtCompileTime,
44  ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic
45  ? Dynamic
46  : ColFactor * MatrixType::ColsAtCompileTime,
47  //FIXME we don't propagate the max sizes !!!
48  MaxRowsAtCompileTime = RowsAtCompileTime,
49  MaxColsAtCompileTime = ColsAtCompileTime,
50  IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1
51  : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0
52  : (MatrixType::Flags & RowMajorBit) ? 1 : 0,
53 
54  // FIXME enable DirectAccess with negative strides?
55  Flags = IsRowMajor ? RowMajorBit : 0
56  };
57 };
58 }
59 
60 template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
61  : public internal::dense_xpr_base< Replicate<MatrixType,RowFactor,ColFactor> >::type
62 {
63  typedef typename internal::traits<Replicate>::MatrixTypeNested MatrixTypeNested;
64  typedef typename internal::traits<Replicate>::_MatrixTypeNested _MatrixTypeNested;
65  public:
66 
67  typedef typename internal::dense_xpr_base<Replicate>::type Base;
68  EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
69  typedef typename internal::remove_all<MatrixType>::type NestedExpression;
70 
71  template<typename OriginalMatrixType>
72  EIGEN_DEVICE_FUNC
73  inline explicit Replicate(const OriginalMatrixType& matrix)
74  : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor)
75  {
76  EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
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  EIGEN_DEVICE_FUNC
83  inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
84  : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor)
85  {
86  EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
87  THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
88  }
89 
90  EIGEN_DEVICE_FUNC
91  inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
92  EIGEN_DEVICE_FUNC
93  inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
94 
95  EIGEN_DEVICE_FUNC
96  const _MatrixTypeNested& nestedExpression() const
97  {
98  return m_matrix;
99  }
100 
101  protected:
102  MatrixTypeNested m_matrix;
103  const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
104  const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
105 };
106 
115 template<typename Derived>
116 template<int RowFactor, int ColFactor>
119 {
120  return Replicate<Derived,RowFactor,ColFactor>(derived());
121 }
122 
131 template<typename ExpressionType, int Direction>
134 {
136  (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1);
137 }
138 
139 } // end namespace Eigen
140 
141 #endif // EIGEN_REPLICATE_H
Definition: Constants.h:265
const Replicate< Derived, RowFactor, ColFactor > replicate() const
Definition: Replicate.h:118
Eigen::Index Index
Definition: VectorwiseOp.h:162
Definition: LDLT.h:16
const unsigned int RowMajorBit
Definition: Constants.h:61
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:60
Definition: Constants.h:268
Definition: Eigen_Colamd.h:54
const ReplicateReturnType replicate(Index factor) const
Definition: Replicate.h:133