Eigen  5.0.1
 
Loading...
Searching...
No Matches
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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_REPLICATE_H
12#define EIGEN_REPLICATE_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20template <typename MatrixType, int RowFactor, int ColFactor>
21struct traits<Replicate<MatrixType, RowFactor, ColFactor> > : traits<MatrixType> {
22 using Scalar = typename MatrixType::Scalar;
23 using StorageKind = typename traits<MatrixType>::StorageKind;
24 using XprKind = typename traits<MatrixType>::XprKind;
25 using MatrixTypeNested = typename ref_selector<MatrixType>::type;
26 using MatrixTypeNested_ = std::remove_reference_t<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: propagate MaxRowsAtCompileTime and MaxColsAtCompileTime.
35 MaxRowsAtCompileTime = RowsAtCompileTime,
36 MaxColsAtCompileTime = ColsAtCompileTime,
37 IsRowMajor = MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1 ? 1
38 : MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1 ? 0
39 : (MatrixType::Flags & RowMajorBit) ? 1
40 : 0,
41
42 // FIXME: consider enabling DirectAccess with negative strides.
43 Flags = IsRowMajor ? RowMajorBit : 0
44 };
45};
46} // namespace internal
47
64template <typename MatrixType, int RowFactor, int ColFactor>
65class Replicate : public internal::dense_xpr_base<Replicate<MatrixType, RowFactor, ColFactor> >::type {
66 using MatrixTypeNested = typename internal::traits<Replicate>::MatrixTypeNested;
67 using MatrixTypeNested_ = typename internal::traits<Replicate>::MatrixTypeNested_;
68
69 public:
70 using Base = typename internal::dense_xpr_base<Replicate>::type;
71 EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
72 using NestedExpression = internal::remove_all_t<MatrixType>;
73
74 template <typename OriginalMatrixType>
75 EIGEN_DEVICE_FUNC constexpr inline explicit Replicate(const OriginalMatrixType& matrix)
76 : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor) {
77 EIGEN_STATIC_ASSERT((std::is_same<std::remove_const_t<MatrixType>, OriginalMatrixType>::value),
78 THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
79 eigen_assert(RowFactor != Dynamic && ColFactor != Dynamic);
80 }
81
82 template <typename OriginalMatrixType>
83 EIGEN_DEVICE_FUNC constexpr inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
84 : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor) {
85 EIGEN_STATIC_ASSERT((std::is_same<std::remove_const_t<MatrixType>, OriginalMatrixType>::value),
86 THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
87 }
88
89 EIGEN_DEVICE_FUNC constexpr Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
90 EIGEN_DEVICE_FUNC constexpr Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
91
92 EIGEN_DEVICE_FUNC constexpr const MatrixTypeNested_& nestedExpression() const { return m_matrix; }
93
94 protected:
95 MatrixTypeNested m_matrix;
96 const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
97 const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
98};
99
109template <typename Derived>
110template <int RowFactor, int ColFactor>
114
123template <typename ExpressionType, int Direction>
124EIGEN_DEVICE_FUNC const typename VectorwiseOp<ExpressionType, Direction>::ReplicateReturnType
126 return typename VectorwiseOp<ExpressionType, Direction>::ReplicateReturnType(
127 _expression(), Direction == Vertical ? factor : 1, Direction == Horizontal ? factor : 1);
128}
129
130} // end namespace Eigen
131
132#endif // EIGEN_REPLICATE_H
const Replicate< Derived, RowFactor, ColFactor > replicate() const
Definition Replicate.h:111
Expression of the multiple replication of a matrix or vector.
Definition Replicate.h:65
const ReplicateReturnType replicate(Index factor) const
Definition Replicate.h:125
Eigen::Index Index
Definition VectorwiseOp.h:253
@ Horizontal
Definition Constants.h:270
@ Vertical
Definition Constants.h:267
constexpr unsigned int RowMajorBit
Definition Constants.h:71