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 // 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;
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 {
67 
68  public:
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 EIGEN_CONSTEXPR inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
89  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
90 
92 
93  protected:
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
Direction
An enum that indicates the direction in Cartesian coordinates.
Definition: GeneralDefine.h:56
#define EIGEN_CONSTEXPR
Definition: Macros.h:758
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1171
#define eigen_assert(x)
Definition: Macros.h:910
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
EIGEN_DEVICE_FUNC const Replicate< Derived, RowFactor, ColFactor > replicate() const
Definition: Replicate.h:109
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:64
internal::traits< Replicate >::MatrixTypeNested_ MatrixTypeNested_
Definition: Replicate.h:66
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const
Definition: Replicate.h:88
internal::traits< Replicate >::MatrixTypeNested MatrixTypeNested
Definition: Replicate.h:65
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const
Definition: Replicate.h:89
internal::dense_xpr_base< Replicate >::type Base
Definition: Replicate.h:69
const internal::variable_if_dynamic< Index, ColFactor > m_colFactor
Definition: Replicate.h:96
const internal::variable_if_dynamic< Index, RowFactor > m_rowFactor
Definition: Replicate.h:95
internal::remove_all_t< MatrixType > NestedExpression
Definition: Replicate.h:71
EIGEN_DEVICE_FUNC Replicate(const OriginalMatrixType &matrix, Index rowFactor, Index colFactor)
Definition: Replicate.h:82
MatrixTypeNested m_matrix
Definition: Replicate.h:94
EIGEN_DEVICE_FUNC const MatrixTypeNested_ & nestedExpression() const
Definition: Replicate.h:91
Replicate< ExpressionType,(isVertical ? Dynamic :1),(isHorizontal ? Dynamic :1)> ReplicateReturnType
Definition: VectorwiseOp.h:517
Eigen::Index Index
Definition: VectorwiseOp.h:196
EIGEN_DEVICE_FUNC const ReplicateReturnType replicate(Index factor) const
Definition: Replicate.h:123
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR T value()
Definition: XprHelper.h:161
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
@ Horizontal
Definition: Constants.h:269
@ Vertical
Definition: Constants.h:266
const unsigned int RowMajorBit
Definition: Constants.h:70
return int(ret)+1
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
const int Dynamic
Definition: Constants.h:25
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56
type
Definition: compute_granudrum_aor.py:141
Definition: Eigen_Colamd.h:49
Definition: XprHelper.h:558
Definition: Meta.h:205
Definition: XprHelper.h:506
ref_selector< MatrixType >::type MatrixTypeNested
Definition: Replicate.h:24
traits< MatrixType >::XprKind XprKind
Definition: Replicate.h:23
std::remove_reference_t< MatrixTypeNested > MatrixTypeNested_
Definition: Replicate.h:25
traits< MatrixType >::StorageKind StorageKind
Definition: Replicate.h:22
Definition: ForwardDeclarations.h:21