2009-03-05 10:25:22 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2009-03-05 10:25:22 +00:00
|
|
|
//
|
2010-06-24 23:21:58 +02:00
|
|
|
// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2009-03-05 10:25:22 +00:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2009-03-05 10:25:22 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_REPLICATE_H
|
|
|
|
|
#define EIGEN_REPLICATE_H
|
|
|
|
|
|
2023-08-21 16:25:22 +00:00
|
|
|
// IWYU pragma: private
|
2021-09-10 19:12:26 +00:00
|
|
|
#include "./InternalHeaderCheck.h"
|
|
|
|
|
|
2021-03-08 12:39:11 -05:00
|
|
|
namespace Eigen {
|
2012-04-15 11:06:28 +01:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
2009-03-05 10:25:22 +00:00
|
|
|
template <typename MatrixType, int RowFactor, int ColFactor>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct traits<Replicate<MatrixType, RowFactor, ColFactor> > : traits<MatrixType> {
|
2009-03-05 10:25:22 +00:00
|
|
|
typedef typename MatrixType::Scalar Scalar;
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename traits<MatrixType>::StorageKind StorageKind;
|
|
|
|
|
typedef typename traits<MatrixType>::XprKind XprKind;
|
2015-06-19 17:56:39 +02:00
|
|
|
typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
|
2022-03-16 16:43:40 +00:00
|
|
|
typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNested_;
|
2009-03-05 10:25:22 +00:00
|
|
|
enum {
|
2009-10-13 09:23:09 +02:00
|
|
|
RowsAtCompileTime = RowFactor == Dynamic || int(MatrixType::RowsAtCompileTime) == Dynamic
|
2009-03-05 10:25:22 +00:00
|
|
|
? Dynamic
|
|
|
|
|
: RowFactor * MatrixType::RowsAtCompileTime,
|
2009-10-13 09:23:09 +02:00
|
|
|
ColsAtCompileTime = ColFactor == Dynamic || int(MatrixType::ColsAtCompileTime) == Dynamic
|
2009-03-05 10:25:22 +00:00
|
|
|
? Dynamic
|
|
|
|
|
: ColFactor * MatrixType::ColsAtCompileTime,
|
2026-02-22 21:20:08 -08:00
|
|
|
// FIXME: propagate MaxRowsAtCompileTime and MaxColsAtCompileTime.
|
2009-03-05 10:25:22 +00:00
|
|
|
MaxRowsAtCompileTime = RowsAtCompileTime,
|
|
|
|
|
MaxColsAtCompileTime = ColsAtCompileTime,
|
2010-04-16 10:13:32 -04:00
|
|
|
IsRowMajor = MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1 ? 1
|
|
|
|
|
: MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1 ? 0
|
2010-03-21 11:28:03 -04:00
|
|
|
: (MatrixType::Flags & RowMajorBit) ? 1
|
|
|
|
|
: 0,
|
2021-03-08 12:39:11 -05:00
|
|
|
|
2026-02-22 21:20:08 -08:00
|
|
|
// FIXME: consider enabling DirectAccess with negative strides.
|
2014-03-12 13:34:11 +01:00
|
|
|
Flags = IsRowMajor ? RowMajorBit : 0
|
2009-03-05 10:25:22 +00:00
|
|
|
};
|
|
|
|
|
};
|
2010-10-25 10:15:22 -04:00
|
|
|
} // namespace internal
|
2009-03-05 10:25:22 +00:00
|
|
|
|
2016-01-01 21:45:06 +01:00
|
|
|
/**
|
|
|
|
|
* \class Replicate
|
|
|
|
|
* \ingroup Core_Module
|
|
|
|
|
*
|
|
|
|
|
* \brief Expression of the multiple replication of a matrix or vector
|
|
|
|
|
*
|
|
|
|
|
* \tparam MatrixType the type of the object we are replicating
|
|
|
|
|
* \tparam RowFactor number of repetitions at compile time along the vertical direction, can be Dynamic.
|
|
|
|
|
* \tparam ColFactor number of repetitions at compile time along the horizontal direction, can be Dynamic.
|
|
|
|
|
*
|
|
|
|
|
* This class represents an expression of the multiple replication of a matrix or vector.
|
|
|
|
|
* It is the return type of DenseBase::replicate() and most of the time
|
|
|
|
|
* this is the only way it is used.
|
|
|
|
|
*
|
|
|
|
|
* \sa DenseBase::replicate()
|
|
|
|
|
*/
|
2009-03-05 10:25:22 +00:00
|
|
|
template <typename MatrixType, int RowFactor, int ColFactor>
|
2010-10-25 10:15:22 -04:00
|
|
|
class Replicate : public internal::dense_xpr_base<Replicate<MatrixType, RowFactor, ColFactor> >::type {
|
2012-04-06 00:22:13 +02:00
|
|
|
typedef typename internal::traits<Replicate>::MatrixTypeNested MatrixTypeNested;
|
2022-01-10 20:53:29 +00:00
|
|
|
typedef typename internal::traits<Replicate>::MatrixTypeNested_ MatrixTypeNested_;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2009-03-05 10:25:22 +00:00
|
|
|
public:
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename internal::dense_xpr_base<Replicate>::type Base;
|
2010-01-22 10:15:41 +01:00
|
|
|
EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
|
2022-03-16 16:43:40 +00:00
|
|
|
typedef internal::remove_all_t<MatrixType> NestedExpression;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2009-09-30 15:47:11 -04:00
|
|
|
template <typename OriginalMatrixType>
|
2026-02-24 19:59:10 -08:00
|
|
|
EIGEN_DEVICE_FUNC constexpr inline explicit Replicate(const OriginalMatrixType& matrix)
|
2015-06-09 13:32:12 +02:00
|
|
|
: m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor) {
|
2022-03-16 16:43:40 +00:00
|
|
|
EIGEN_STATIC_ASSERT((internal::is_same<std::remove_const_t<MatrixType>, OriginalMatrixType>::value),
|
2009-09-30 15:47:11 -04:00
|
|
|
THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
|
2010-10-25 10:15:22 -04:00
|
|
|
eigen_assert(RowFactor != Dynamic && ColFactor != Dynamic);
|
2009-03-05 10:25:22 +00:00
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2009-09-30 15:47:11 -04:00
|
|
|
template <typename OriginalMatrixType>
|
2026-02-24 19:59:10 -08:00
|
|
|
EIGEN_DEVICE_FUNC constexpr inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
|
2024-05-20 23:02:42 +00:00
|
|
|
: m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor) {
|
|
|
|
|
EIGEN_STATIC_ASSERT((internal::is_same<std::remove_const_t<MatrixType>, OriginalMatrixType>::value),
|
|
|
|
|
THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
|
2010-05-30 16:00:58 -04:00
|
|
|
}
|
2024-05-20 23:02:42 +00:00
|
|
|
|
2024-11-15 21:11:01 -08:00
|
|
|
EIGEN_DEVICE_FUNC constexpr Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
|
|
|
|
|
EIGEN_DEVICE_FUNC constexpr Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2026-02-24 19:59:10 -08:00
|
|
|
EIGEN_DEVICE_FUNC constexpr const MatrixTypeNested_& nestedExpression() const { return m_matrix; }
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2009-03-05 10:25:22 +00:00
|
|
|
protected:
|
2012-04-06 00:22:13 +02:00
|
|
|
MatrixTypeNested m_matrix;
|
2010-10-25 10:15:22 -04:00
|
|
|
const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
|
|
|
|
|
const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
|
2009-03-05 10:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
2010-06-29 10:10:47 -04:00
|
|
|
/**
|
2009-03-05 10:25:22 +00:00
|
|
|
* \return an expression of the replication of \c *this
|
2009-03-11 08:45:53 +00:00
|
|
|
*
|
2009-03-05 10:25:22 +00:00
|
|
|
* Example: \include MatrixBase_replicate.cpp
|
|
|
|
|
* Output: \verbinclude MatrixBase_replicate.out
|
|
|
|
|
*
|
2010-05-30 16:00:58 -04:00
|
|
|
* \sa VectorwiseOp::replicate(), DenseBase::replicate(Index,Index), class Replicate
|
2009-03-05 10:25:22 +00:00
|
|
|
*/
|
|
|
|
|
template <typename Derived>
|
|
|
|
|
template <int RowFactor, int ColFactor>
|
2017-02-28 16:42:00 -08:00
|
|
|
EIGEN_DEVICE_FUNC const Replicate<Derived, RowFactor, ColFactor> DenseBase<Derived>::replicate() const {
|
2009-10-13 09:23:09 +02:00
|
|
|
return Replicate<Derived, RowFactor, ColFactor>(derived());
|
2009-03-05 10:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-29 10:10:47 -04:00
|
|
|
/**
|
2009-03-05 10:25:22 +00:00
|
|
|
* \return an expression of the replication of each column (or row) of \c *this
|
2009-03-11 08:45:53 +00:00
|
|
|
*
|
2009-03-05 10:25:22 +00:00
|
|
|
* Example: \include DirectionWise_replicate_int.cpp
|
|
|
|
|
* Output: \verbinclude DirectionWise_replicate_int.out
|
|
|
|
|
*
|
2009-12-10 22:00:35 +01:00
|
|
|
* \sa VectorwiseOp::replicate(), DenseBase::replicate(), class Replicate
|
2009-03-05 10:25:22 +00:00
|
|
|
*/
|
|
|
|
|
template <typename ExpressionType, int Direction>
|
2017-02-28 16:42:00 -08:00
|
|
|
EIGEN_DEVICE_FUNC const typename VectorwiseOp<ExpressionType, Direction>::ReplicateReturnType
|
2010-05-30 16:00:58 -04:00
|
|
|
VectorwiseOp<ExpressionType, Direction>::replicate(Index factor) const {
|
2010-03-18 20:10:24 -04:00
|
|
|
return typename VectorwiseOp<ExpressionType, Direction>::ReplicateReturnType(
|
2009-03-05 10:25:22 +00:00
|
|
|
_expression(), Direction == Vertical ? factor : 1, Direction == Horizontal ? factor : 1);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2009-03-05 10:25:22 +00:00
|
|
|
#endif // EIGEN_REPLICATE_H
|