Replicate.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_REPLICATE_H
00011 #define EIGEN_REPLICATE_H
00012 
00013 namespace Eigen { 
00014 
00030 namespace internal {
00031 template<typename MatrixType,int RowFactor,int ColFactor>
00032 struct traits<Replicate<MatrixType,RowFactor,ColFactor> >
00033  : traits<MatrixType>
00034 {
00035   typedef typename MatrixType::Scalar Scalar;
00036   typedef typename traits<MatrixType>::StorageKind StorageKind;
00037   typedef typename traits<MatrixType>::XprKind XprKind;
00038   enum {
00039     Factor = (RowFactor==Dynamic || ColFactor==Dynamic) ? Dynamic : RowFactor*ColFactor
00040   };
00041   typedef typename nested<MatrixType,Factor>::type MatrixTypeNested;
00042   typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
00043   enum {
00044     RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic
00045                       ? Dynamic
00046                       : RowFactor * MatrixType::RowsAtCompileTime,
00047     ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic
00048                       ? Dynamic
00049                       : ColFactor * MatrixType::ColsAtCompileTime,
00050    //FIXME we don't propagate the max sizes !!!
00051     MaxRowsAtCompileTime = RowsAtCompileTime,
00052     MaxColsAtCompileTime = ColsAtCompileTime,
00053     IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1
00054                : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0
00055                : (MatrixType::Flags & RowMajorBit) ? 1 : 0,
00056     Flags = (_MatrixTypeNested::Flags & HereditaryBits & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0),
00057     CoeffReadCost = _MatrixTypeNested::CoeffReadCost
00058   };
00059 };
00060 }
00061 
00062 template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
00063   : public internal::dense_xpr_base< Replicate<MatrixType,RowFactor,ColFactor> >::type
00064 {
00065     typedef typename internal::traits<Replicate>::MatrixTypeNested MatrixTypeNested;
00066     typedef typename internal::traits<Replicate>::_MatrixTypeNested _MatrixTypeNested;
00067   public:
00068 
00069     typedef typename internal::dense_xpr_base<Replicate>::type Base;
00070     EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
00071 
00072     template<typename OriginalMatrixType>
00073     inline explicit Replicate(const OriginalMatrixType& matrix)
00074       : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor)
00075     {
00076       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
00077                           THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
00078       eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic);
00079     }
00080 
00081     template<typename OriginalMatrixType>
00082     inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
00083       : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor)
00084     {
00085       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
00086                           THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
00087     }
00088 
00089     inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
00090     inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
00091 
00092     inline Scalar coeff(Index row, Index col) const
00093     {
00094       // try to avoid using modulo; this is a pure optimization strategy
00095       const Index actual_row  = internal::traits<MatrixType>::RowsAtCompileTime==1 ? 0
00096                             : RowFactor==1 ? row
00097                             : row%m_matrix.rows();
00098       const Index actual_col  = internal::traits<MatrixType>::ColsAtCompileTime==1 ? 0
00099                             : ColFactor==1 ? col
00100                             : col%m_matrix.cols();
00101 
00102       return m_matrix.coeff(actual_row, actual_col);
00103     }
00104     template<int LoadMode>
00105     inline PacketScalar packet(Index row, Index col) const
00106     {
00107       const Index actual_row  = internal::traits<MatrixType>::RowsAtCompileTime==1 ? 0
00108                             : RowFactor==1 ? row
00109                             : row%m_matrix.rows();
00110       const Index actual_col  = internal::traits<MatrixType>::ColsAtCompileTime==1 ? 0
00111                             : ColFactor==1 ? col
00112                             : col%m_matrix.cols();
00113 
00114       return m_matrix.template packet<LoadMode>(actual_row, actual_col);
00115     }
00116 
00117     const _MatrixTypeNested& nestedExpression() const
00118     { 
00119       return m_matrix; 
00120     }
00121 
00122   protected:
00123     MatrixTypeNested m_matrix;
00124     const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
00125     const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
00126 };
00127 
00136 template<typename Derived>
00137 template<int RowFactor, int ColFactor>
00138 inline const Replicate<Derived,RowFactor,ColFactor>
00139 DenseBase<Derived>::replicate() const
00140 {
00141   return Replicate<Derived,RowFactor,ColFactor>(derived());
00142 }
00143 
00152 template<typename Derived>
00153 inline const Replicate<Derived,Dynamic,Dynamic>
00154 DenseBase<Derived>::replicate(Index rowFactor,Index colFactor) const
00155 {
00156   return Replicate<Derived,Dynamic,Dynamic>(derived(),rowFactor,colFactor);
00157 }
00158 
00167 template<typename ExpressionType, int Direction>
00168 const typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
00169 VectorwiseOp<ExpressionType,Direction>::replicate(Index factor) const
00170 {
00171   return typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
00172           (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1);
00173 }
00174 
00175 } // end namespace Eigen
00176 
00177 #endif // EIGEN_REPLICATE_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:11:41