Eigen  3.3.3
Replicate.h
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 
00015 namespace internal {
00016 template<typename MatrixType,int RowFactor,int ColFactor>
00017 struct traits<Replicate<MatrixType,RowFactor,ColFactor> >
00018  : traits<MatrixType>
00019 {
00020   typedef typename MatrixType::Scalar Scalar;
00021   typedef typename traits<MatrixType>::StorageKind StorageKind;
00022   typedef typename traits<MatrixType>::XprKind XprKind;
00023   typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
00024   typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
00025   enum {
00026     RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic
00027                       ? Dynamic
00028                       : RowFactor * MatrixType::RowsAtCompileTime,
00029     ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic
00030                       ? Dynamic
00031                       : ColFactor * MatrixType::ColsAtCompileTime,
00032    //FIXME we don't propagate the max sizes !!!
00033     MaxRowsAtCompileTime = RowsAtCompileTime,
00034     MaxColsAtCompileTime = ColsAtCompileTime,
00035     IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1
00036                : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0
00037                : (MatrixType::Flags & RowMajorBit) ? 1 : 0,
00038     
00039     // FIXME enable DirectAccess with negative strides?
00040     Flags = IsRowMajor ? RowMajorBit : 0
00041   };
00042 };
00043 }
00044 
00061 template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
00062   : public internal::dense_xpr_base< Replicate<MatrixType,RowFactor,ColFactor> >::type
00063 {
00064     typedef typename internal::traits<Replicate>::MatrixTypeNested MatrixTypeNested;
00065     typedef typename internal::traits<Replicate>::_MatrixTypeNested _MatrixTypeNested;
00066   public:
00067 
00068     typedef typename internal::dense_xpr_base<Replicate>::type Base;
00069     EIGEN_DENSE_PUBLIC_INTERFACE(Replicate)
00070     typedef typename internal::remove_all<MatrixType>::type NestedExpression;
00071 
00072     template<typename OriginalMatrixType>
00073     EIGEN_DEVICE_FUNC
00074     inline explicit Replicate(const OriginalMatrixType& matrix)
00075       : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor)
00076     {
00077       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
00078                           THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
00079       eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic);
00080     }
00081 
00082     template<typename OriginalMatrixType>
00083     EIGEN_DEVICE_FUNC
00084     inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor)
00085       : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor)
00086     {
00087       EIGEN_STATIC_ASSERT((internal::is_same<typename internal::remove_const<MatrixType>::type,OriginalMatrixType>::value),
00088                           THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)
00089     }
00090 
00091     EIGEN_DEVICE_FUNC
00092     inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); }
00093     EIGEN_DEVICE_FUNC
00094     inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); }
00095 
00096     EIGEN_DEVICE_FUNC
00097     const _MatrixTypeNested& nestedExpression() const
00098     { 
00099       return m_matrix; 
00100     }
00101 
00102   protected:
00103     MatrixTypeNested m_matrix;
00104     const internal::variable_if_dynamic<Index, RowFactor> m_rowFactor;
00105     const internal::variable_if_dynamic<Index, ColFactor> m_colFactor;
00106 };
00107 
00116 template<typename Derived>
00117 template<int RowFactor, int ColFactor>
00118 const Replicate<Derived,RowFactor,ColFactor>
00119 DenseBase<Derived>::replicate() const
00120 {
00121   return Replicate<Derived,RowFactor,ColFactor>(derived());
00122 }
00123 
00132 template<typename ExpressionType, int Direction>
00133 const typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
00134 VectorwiseOp<ExpressionType,Direction>::replicate(Index factor) const
00135 {
00136   return typename VectorwiseOp<ExpressionType,Direction>::ReplicateReturnType
00137           (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1);
00138 }
00139 
00140 } // end namespace Eigen
00141 
00142 #endif // EIGEN_REPLICATE_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends