Go to the documentation of this file.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_SPARSE_CWISE_UNARY_OP_H
00026 #define EIGEN_SPARSE_CWISE_UNARY_OP_H
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 template<typename UnaryOp, typename MatrixType>
00042 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>
00043 : public SparseMatrixBase<CwiseUnaryOp<UnaryOp, MatrixType> >
00044 {
00045 public:
00046
00047 class InnerIterator;
00048
00049
00050 typedef CwiseUnaryOp<UnaryOp, MatrixType> Derived;
00051 EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
00052 };
00053
00054 template<typename UnaryOp, typename MatrixType>
00055 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::InnerIterator
00056 {
00057 typedef typename CwiseUnaryOpImpl::Scalar Scalar;
00058 typedef typename internal::traits<Derived>::_XprTypeNested _MatrixTypeNested;
00059 typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
00060 typedef typename MatrixType::Index Index;
00061 public:
00062
00063 EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryOpImpl& unaryOp, Index outer)
00064 : m_iter(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
00065 {}
00066
00067 EIGEN_STRONG_INLINE InnerIterator& operator++()
00068 { ++m_iter; return *this; }
00069
00070 EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_iter.value()); }
00071
00072 EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); }
00073 EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); }
00074 EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); }
00075
00076 EIGEN_STRONG_INLINE operator bool() const { return m_iter; }
00077
00078 protected:
00079 MatrixTypeIterator m_iter;
00080 const UnaryOp m_functor;
00081 };
00082
00083 template<typename ViewOp, typename MatrixType>
00084 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>
00085 : public SparseMatrixBase<CwiseUnaryView<ViewOp, MatrixType> >
00086 {
00087 public:
00088
00089 class InnerIterator;
00090
00091
00092 typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
00093 EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
00094 };
00095
00096 template<typename ViewOp, typename MatrixType>
00097 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::InnerIterator
00098 {
00099 typedef typename CwiseUnaryViewImpl::Scalar Scalar;
00100 typedef typename internal::traits<Derived>::_MatrixTypeNested _MatrixTypeNested;
00101 typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
00102 typedef typename MatrixType::Index Index;
00103 public:
00104
00105 EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryViewImpl& unaryView, Index outer)
00106 : m_iter(unaryView.derived().nestedExpression(),outer), m_functor(unaryView.derived().functor())
00107 {}
00108
00109 EIGEN_STRONG_INLINE InnerIterator& operator++()
00110 { ++m_iter; return *this; }
00111
00112 EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_iter.value()); }
00113 EIGEN_STRONG_INLINE Scalar& valueRef() { return m_functor(m_iter.valueRef()); }
00114
00115 EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); }
00116 EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); }
00117 EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); }
00118
00119 EIGEN_STRONG_INLINE operator bool() const { return m_iter; }
00120
00121 protected:
00122 MatrixTypeIterator m_iter;
00123 const ViewOp m_functor;
00124 };
00125
00126 template<typename Derived>
00127 EIGEN_STRONG_INLINE Derived&
00128 SparseMatrixBase<Derived>::operator*=(const Scalar& other)
00129 {
00130 for (Index j=0; j<outerSize(); ++j)
00131 for (typename Derived::InnerIterator i(derived(),j); i; ++i)
00132 i.valueRef() *= other;
00133 return derived();
00134 }
00135
00136 template<typename Derived>
00137 EIGEN_STRONG_INLINE Derived&
00138 SparseMatrixBase<Derived>::operator/=(const Scalar& other)
00139 {
00140 for (Index j=0; j<outerSize(); ++j)
00141 for (typename Derived::InnerIterator i(derived(),j); i; ++i)
00142 i.valueRef() /= other;
00143 return derived();
00144 }
00145
00146 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H