$darkmode
Eigen  5.0.1-dev
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 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 template <typename MatrixType, int RowFactor, int ColFactor>
20 struct traits<Replicate<MatrixType, RowFactor, ColFactor> > : traits<MatrixType> {
21  typedef typename MatrixType::Scalar Scalar;
22  typedef typename traits<MatrixType>::StorageKind StorageKind;
23  typedef typename traits<MatrixType>::XprKind XprKind;
24  typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
25  typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNested_;
26  enum {
27  RowsAtCompileTime = RowFactor == Dynamic || int(MatrixType::RowsAtCompileTime) == Dynamic
28  ? Dynamic
29  : RowFactor * MatrixType::RowsAtCompileTime,
30  ColsAtCompileTime = ColFactor == Dynamic || int(MatrixType::ColsAtCompileTime) == Dynamic
31  ? Dynamic
32  : ColFactor * MatrixType::ColsAtCompileTime,
33  // FIXME we don't propagate the max sizes !!!
34  MaxRowsAtCompileTime = RowsAtCompileTime,
35  MaxColsAtCompileTime = ColsAtCompileTime,
36  IsRowMajor = MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1 ? 1
37  : MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1 ? 0
38  : (MatrixType::Flags & RowMajorBit) ? 1
39  : 0,
40 
41  // FIXME enable DirectAccess with negative strides?
42  Flags = IsRowMajor ? RowMajorBit : 0
43  };
44 };
45 } // namespace internal
46 
63 template <typename MatrixType, int RowFactor, int ColFactor>
64 class Replicate : public internal::dense_xpr_base<Replicate<MatrixType, RowFactor, ColFactor> >::type {
65  typedef typename internal::traits<Replicate>::MatrixTypeNested MatrixTypeNested;
66  typedef typename internal::traits<Replicate>::MatrixTypeNested_ MatrixTypeNested_;
67 
68  public:
69  typedef typename internal::dense_xpr_base<Replicate>::type Base;
70  EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
71  typedef internal::remove_all_t<MatrixType> NestedExpression;
72 
73  template <typename OriginalMatrixType>
74  EIGEN_DEVICE_FUNC inline explicit Replicate(const OriginalMatrixType& matrix)
75  : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor) {
76  EIGEN_STATIC_ASSERT((internal::is_same<std::remove_const_t<MatrixType>, 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 inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
83  : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor) {
84  EIGEN_STATIC_ASSERT((internal::is_same<std::remove_const_t<MatrixType>, OriginalMatrixType>::value),
85  THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
86  }
87 
88  EIGEN_DEVICE_FUNC constexpr Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
89  EIGEN_DEVICE_FUNC constexpr Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
90 
91  EIGEN_DEVICE_FUNC const MatrixTypeNested_& nestedExpression() const { return m_matrix; }
92 
93  protected:
94  MatrixTypeNested m_matrix;
95  const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
96  const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
97 };
98 
107 template <typename Derived>
108 template <int RowFactor, int ColFactor>
111 }
112 
121 template <typename ExpressionType, int Direction>
125  _expression(), Direction == Vertical ? factor : 1, Direction == Horizontal ? factor : 1);
126 }
127 
128 } // end namespace Eigen
129 
130 #endif // EIGEN_REPLICATE_H
Definition: Constants.h:266
const ReplicateReturnType replicate(Index factor) const
Definition: Replicate.h:123
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
const unsigned int RowMajorBit
Definition: Constants.h:70
const Replicate< Derived, RowFactor, ColFactor > replicate() const
Definition: Replicate.h:109
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:64
Definition: Constants.h:269
const int Dynamic
Definition: Constants.h:25