00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_REPLICATE_H
00026 #define EIGEN_REPLICATE_H
00027
00028 namespace Eigen {
00029
00045 namespace internal {
00046 template<typename MatrixType,int RowFactor,int ColFactor>
00047 struct traits<Replicate<MatrixType,RowFactor,ColFactor> >
00048 : traits<MatrixType>
00049 {
00050 typedef typename MatrixType::Scalar Scalar;
00051 typedef typename traits<MatrixType>::StorageKind StorageKind;
00052 typedef typename traits<MatrixType>::XprKind XprKind;
00053 enum {
00054 Factor = (RowFactor==Dynamic || ColFactor==Dynamic) ? Dynamic : RowFactor*ColFactor
00055 };
00056 typedef typename nested<MatrixType,Factor>::type MatrixTypeNested;
00057 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
00058 enum {
00059 RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic
00060 ? Dynamic
00061 : RowFactor * MatrixType::RowsAtCompileTime,
00062 ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic
00063 ? Dynamic
00064 : ColFactor * MatrixType::ColsAtCompileTime,
00065
00066 MaxRowsAtCompileTime = RowsAtCompileTime,
00067 MaxColsAtCompileTime = ColsAtCompileTime,
00068 IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1
00069 : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0
00070 : (MatrixType::Flags & RowMajorBit) ? 1 : 0,
00071 Flags = (_MatrixTypeNested::Flags & HereditaryBits & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0),
00072 CoeffReadCost = _MatrixTypeNested::CoeffReadCost
00073 };
00074 };
00075 }
00076
00077 template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
00078 : public internal::dense_xpr_base< Replicate<MatrixType,RowFactor,ColFactor> >::type
00079 {
00080 typedef typename internal::traits<Replicate>::MatrixTypeNested MatrixTypeNested;
00081 typedef typename internal::traits<Replicate>::_MatrixTypeNested _MatrixTypeNested;
00082 public:
00083
00084 typedef typename internal::dense_xpr_base<Replicate>::type Base;
00085 EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
00086
00087 template<typename OriginalMatrixType>
00088 inline explicit Replicate(const OriginalMatrixType& matrix)
00089 : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor)
00090 {
00091 EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
00092 THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
00093 eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic);
00094 }
00095
00096 template<typename OriginalMatrixType>
00097 inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
00098 : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor)
00099 {
00100 EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
00101 THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
00102 }
00103
00104 inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
00105 inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
00106
00107 inline Scalar coeff(Index row, Index col) const
00108 {
00109
00110 const Index actual_row = internal::traits<MatrixType>::RowsAtCompileTime==1 ? 0
00111 : RowFactor==1 ? row
00112 : row%m_matrix.rows();
00113 const Index actual_col = internal::traits<MatrixType>::ColsAtCompileTime==1 ? 0
00114 : ColFactor==1 ? col
00115 : col%m_matrix.cols();
00116
00117 return m_matrix.coeff(actual_row, actual_col);
00118 }
00119 template<int LoadMode>
00120 inline PacketScalar packet(Index row, Index col) const
00121 {
00122 const Index actual_row = internal::traits<MatrixType>::RowsAtCompileTime==1 ? 0
00123 : RowFactor==1 ? row
00124 : row%m_matrix.rows();
00125 const Index actual_col = internal::traits<MatrixType>::ColsAtCompileTime==1 ? 0
00126 : ColFactor==1 ? col
00127 : col%m_matrix.cols();
00128
00129 return m_matrix.template packet<LoadMode>(actual_row, actual_col);
00130 }
00131
00132 const _MatrixTypeNested& nestedExpression() const
00133 {
00134 return m_matrix;
00135 }
00136
00137 protected:
00138 MatrixTypeNested m_matrix;
00139 const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
00140 const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
00141 };
00142
00151 template<typename Derived>
00152 template<int RowFactor, int ColFactor>
00153 inline const Replicate<Derived,RowFactor,ColFactor>
00154 DenseBase<Derived>::replicate() const
00155 {
00156 return Replicate<Derived,RowFactor,ColFactor>(derived());
00157 }
00158
00167 template<typename Derived>
00168 inline const Replicate<Derived,Dynamic,Dynamic>
00169 DenseBase<Derived>::replicate(Index rowFactor,Index colFactor) const
00170 {
00171 return Replicate<Derived,Dynamic,Dynamic>(derived(),rowFactor,colFactor);
00172 }
00173
00182 template<typename ExpressionType, int Direction>
00183 const typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
00184 VectorwiseOp<ExpressionType,Direction>::replicate(Index factor) const
00185 {
00186 return typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
00187 (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1);
00188 }
00189
00190 }
00191
00192 #endif // EIGEN_REPLICATE_H