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
00043 namespace internal {
00044 template<typename MatrixType,int RowFactor,int ColFactor>
00045 struct traits<Replicate<MatrixType,RowFactor,ColFactor> >
00046 : traits<MatrixType>
00047 {
00048 typedef typename MatrixType::Scalar Scalar;
00049 typedef typename traits<MatrixType>::StorageKind StorageKind;
00050 typedef typename traits<MatrixType>::XprKind XprKind;
00051 typedef typename nested<MatrixType>::type MatrixTypeNested;
00052 typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
00053 enum {
00054 RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic
00055 ? Dynamic
00056 : RowFactor * MatrixType::RowsAtCompileTime,
00057 ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic
00058 ? Dynamic
00059 : ColFactor * MatrixType::ColsAtCompileTime,
00060
00061 MaxRowsAtCompileTime = RowsAtCompileTime,
00062 MaxColsAtCompileTime = ColsAtCompileTime,
00063 IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1
00064 : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0
00065 : (MatrixType::Flags & RowMajorBit) ? 1 : 0,
00066 Flags = (_MatrixTypeNested::Flags & HereditaryBits & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0),
00067 CoeffReadCost = _MatrixTypeNested::CoeffReadCost
00068 };
00069 };
00070 }
00071
00072 template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
00073 : public internal::dense_xpr_base< Replicate<MatrixType,RowFactor,ColFactor> >::type
00074 {
00075 public:
00076
00077 typedef typename internal::dense_xpr_base<Replicate>::type Base;
00078 EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
00079
00080 template<typename OriginalMatrixType>
00081 inline explicit Replicate(const OriginalMatrixType& matrix)
00082 : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor)
00083 {
00084 EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
00085 THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
00086 eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic);
00087 }
00088
00089 template<typename OriginalMatrixType>
00090 inline Replicate(const OriginalMatrixType& matrix, int rowFactor, int colFactor)
00091 : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor)
00092 {
00093 EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
00094 THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
00095 }
00096
00097 inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
00098 inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
00099
00100 inline Scalar coeff(Index row, Index col) const
00101 {
00102
00103 const Index actual_row = internal::traits<MatrixType>::RowsAtCompileTime==1 ? 0
00104 : RowFactor==1 ? row
00105 : row%m_matrix.rows();
00106 const Index actual_col = internal::traits<MatrixType>::ColsAtCompileTime==1 ? 0
00107 : ColFactor==1 ? col
00108 : col%m_matrix.cols();
00109
00110 return m_matrix.coeff(actual_row, actual_col);
00111 }
00112 template<int LoadMode>
00113 inline PacketScalar packet(Index row, Index col) const
00114 {
00115 const Index actual_row = internal::traits<MatrixType>::RowsAtCompileTime==1 ? 0
00116 : RowFactor==1 ? row
00117 : row%m_matrix.rows();
00118 const Index actual_col = internal::traits<MatrixType>::ColsAtCompileTime==1 ? 0
00119 : ColFactor==1 ? col
00120 : col%m_matrix.cols();
00121
00122 return m_matrix.template packet<LoadMode>(actual_row, actual_col);
00123 }
00124
00125
00126 protected:
00127 const typename MatrixType::Nested m_matrix;
00128 const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
00129 const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
00130 };
00131
00140 template<typename Derived>
00141 template<int RowFactor, int ColFactor>
00142 inline const Replicate<Derived,RowFactor,ColFactor>
00143 DenseBase<Derived>::replicate() const
00144 {
00145 return Replicate<Derived,RowFactor,ColFactor>(derived());
00146 }
00147
00156 template<typename Derived>
00157 inline const Replicate<Derived,Dynamic,Dynamic>
00158 DenseBase<Derived>::replicate(Index rowFactor,Index colFactor) const
00159 {
00160 return Replicate<Derived,Dynamic,Dynamic>(derived(),rowFactor,colFactor);
00161 }
00162
00171 template<typename ExpressionType, int Direction>
00172 const typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
00173 VectorwiseOp<ExpressionType,Direction>::replicate(Index factor) const
00174 {
00175 return typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
00176 (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1);
00177 }
00178
00179 #endif // EIGEN_REPLICATE_H