Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:56:17

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_REPLICATE_H
0011 #define EIGEN_REPLICATE_H
0012 
0013 namespace Eigen {
0014 
0015 namespace internal {
0016 template<typename MatrixType,int RowFactor,int ColFactor>
0017 struct traits<Replicate<MatrixType,RowFactor,ColFactor> >
0018  : traits<MatrixType>
0019 {
0020   typedef typename MatrixType::Scalar Scalar;
0021   typedef typename traits<MatrixType>::StorageKind StorageKind;
0022   typedef typename traits<MatrixType>::XprKind XprKind;
0023   typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
0024   typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
0025   enum {
0026     RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic
0027                       ? Dynamic
0028                       : RowFactor * MatrixType::RowsAtCompileTime,
0029     ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic
0030                       ? Dynamic
0031                       : ColFactor * MatrixType::ColsAtCompileTime,
0032    //FIXME we don't propagate the max sizes !!!
0033     MaxRowsAtCompileTime = RowsAtCompileTime,
0034     MaxColsAtCompileTime = ColsAtCompileTime,
0035     IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1
0036                : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0
0037                : (MatrixType::Flags & RowMajorBit) ? 1 : 0,
0038 
0039     // FIXME enable DirectAccess with negative strides?
0040     Flags = IsRowMajor ? RowMajorBit : 0
0041   };
0042 };
0043 }
0044 
0045 /**
0046   * \class Replicate
0047   * \ingroup Core_Module
0048   *
0049   * \brief Expression of the multiple replication of a matrix or vector
0050   *
0051   * \tparam MatrixType the type of the object we are replicating
0052   * \tparam RowFactor number of repetitions at compile time along the vertical direction, can be Dynamic.
0053   * \tparam ColFactor number of repetitions at compile time along the horizontal direction, can be Dynamic.
0054   *
0055   * This class represents an expression of the multiple replication of a matrix or vector.
0056   * It is the return type of DenseBase::replicate() and most of the time
0057   * this is the only way it is used.
0058   *
0059   * \sa DenseBase::replicate()
0060   */
0061 template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
0062   : public internal::dense_xpr_base< Replicate<MatrixType,RowFactor,ColFactor> >::type
0063 {
0064     typedef typename internal::traits<Replicate>::MatrixTypeNested MatrixTypeNested;
0065     typedef typename internal::traits<Replicate>::_MatrixTypeNested _MatrixTypeNested;
0066   public:
0067 
0068     typedef typename internal::dense_xpr_base<Replicate>::type Base;
0069     EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
0070     typedef typename internal::remove_all<MatrixType>::type NestedExpression;
0071 
0072     template<typename OriginalMatrixType>
0073     EIGEN_DEVICE_FUNC
0074     inline explicit Replicate(const OriginalMatrixType& matrix)
0075       : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor)
0076     {
0077       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
0078                           THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
0079       eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic);
0080     }
0081 
0082     template<typename OriginalMatrixType>
0083     EIGEN_DEVICE_FUNC
0084     inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
0085       : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor)
0086     {
0087       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
0088                           THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
0089     }
0090 
0091     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0092     inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
0093     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0094     inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
0095 
0096     EIGEN_DEVICE_FUNC
0097     const _MatrixTypeNested& nestedExpression() const
0098     {
0099       return m_matrix;
0100     }
0101 
0102   protected:
0103     MatrixTypeNested m_matrix;
0104     const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
0105     const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
0106 };
0107 
0108 /**
0109   * \return an expression of the replication of \c *this
0110   *
0111   * Example: \include MatrixBase_replicate.cpp
0112   * Output: \verbinclude MatrixBase_replicate.out
0113   *
0114   * \sa VectorwiseOp::replicate(), DenseBase::replicate(Index,Index), class Replicate
0115   */
0116 template<typename Derived>
0117 template<int RowFactor, int ColFactor>
0118 EIGEN_DEVICE_FUNC const Replicate<Derived,RowFactor,ColFactor>
0119 DenseBase<Derived>::replicate() const
0120 {
0121   return Replicate<Derived,RowFactor,ColFactor>(derived());
0122 }
0123 
0124 /**
0125   * \return an expression of the replication of each column (or row) of \c *this
0126   *
0127   * Example: \include DirectionWise_replicate_int.cpp
0128   * Output: \verbinclude DirectionWise_replicate_int.out
0129   *
0130   * \sa VectorwiseOp::replicate(), DenseBase::replicate(), class Replicate
0131   */
0132 template<typename ExpressionType, int Direction>
0133 EIGEN_DEVICE_FUNC const typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
0134 VectorwiseOp<ExpressionType,Direction>::replicate(Index factor) const
0135 {
0136   return typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
0137           (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1);
0138 }
0139 
0140 } // end namespace Eigen
0141 
0142 #endif // EIGEN_REPLICATE_H