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 namespace Eigen {
00029
00030 template<typename UnaryOp, typename MatrixType>
00031 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>
00032 : public SparseMatrixBase<CwiseUnaryOp<UnaryOp, MatrixType> >
00033 {
00034 public:
00035
00036 class InnerIterator;
00037 class ReverseInnerIterator;
00038
00039 typedef CwiseUnaryOp<UnaryOp, MatrixType> Derived;
00040 EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
00041
00042 protected:
00043 typedef typename internal::traits<Derived>::_XprTypeNested _MatrixTypeNested;
00044 typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
00045 typedef typename _MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator;
00046 };
00047
00048 template<typename UnaryOp, typename MatrixType>
00049 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::InnerIterator
00050 : public CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeIterator
00051 {
00052 typedef typename CwiseUnaryOpImpl::Scalar Scalar;
00053 typedef typename CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeIterator Base;
00054 public:
00055
00056 EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryOpImpl& unaryOp, typename CwiseUnaryOpImpl::Index outer)
00057 : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
00058 {}
00059
00060 EIGEN_STRONG_INLINE InnerIterator& operator++()
00061 { Base::operator++(); return *this; }
00062
00063 EIGEN_STRONG_INLINE typename CwiseUnaryOpImpl::Scalar value() const { return m_functor(Base::value()); }
00064
00065 protected:
00066 const UnaryOp m_functor;
00067 private:
00068 typename CwiseUnaryOpImpl::Scalar& valueRef();
00069 };
00070
00071 template<typename UnaryOp, typename MatrixType>
00072 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::ReverseInnerIterator
00073 : public CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeReverseIterator
00074 {
00075 typedef typename CwiseUnaryOpImpl::Scalar Scalar;
00076 typedef typename CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeReverseIterator Base;
00077 public:
00078
00079 EIGEN_STRONG_INLINE ReverseInnerIterator(const CwiseUnaryOpImpl& unaryOp, typename CwiseUnaryOpImpl::Index outer)
00080 : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
00081 {}
00082
00083 EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
00084 { Base::operator--(); return *this; }
00085
00086 EIGEN_STRONG_INLINE typename CwiseUnaryOpImpl::Scalar value() const { return m_functor(Base::value()); }
00087
00088 protected:
00089 const UnaryOp m_functor;
00090 private:
00091 typename CwiseUnaryOpImpl::Scalar& valueRef();
00092 };
00093
00094 template<typename ViewOp, typename MatrixType>
00095 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>
00096 : public SparseMatrixBase<CwiseUnaryView<ViewOp, MatrixType> >
00097 {
00098 public:
00099
00100 class InnerIterator;
00101 class ReverseInnerIterator;
00102
00103 typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
00104 EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
00105
00106 protected:
00107 typedef typename internal::traits<Derived>::_MatrixTypeNested _MatrixTypeNested;
00108 typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
00109 typedef typename _MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator;
00110 };
00111
00112 template<typename ViewOp, typename MatrixType>
00113 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::InnerIterator
00114 : public CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeIterator
00115 {
00116 typedef typename CwiseUnaryViewImpl::Scalar Scalar;
00117 typedef typename CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeIterator Base;
00118 public:
00119
00120 EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryViewImpl& unaryOp, typename CwiseUnaryViewImpl::Index outer)
00121 : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
00122 {}
00123
00124 EIGEN_STRONG_INLINE InnerIterator& operator++()
00125 { Base::operator++(); return *this; }
00126
00127 EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar value() const { return m_functor(Base::value()); }
00128 EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar& valueRef() { return m_functor(Base::valueRef()); }
00129
00130 protected:
00131 const ViewOp m_functor;
00132 };
00133
00134 template<typename ViewOp, typename MatrixType>
00135 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::ReverseInnerIterator
00136 : public CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeReverseIterator
00137 {
00138 typedef typename CwiseUnaryViewImpl::Scalar Scalar;
00139 typedef typename CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeReverseIterator Base;
00140 public:
00141
00142 EIGEN_STRONG_INLINE ReverseInnerIterator(const CwiseUnaryViewImpl& unaryOp, typename CwiseUnaryViewImpl::Index outer)
00143 : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
00144 {}
00145
00146 EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
00147 { Base::operator--(); return *this; }
00148
00149 EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar value() const { return m_functor(Base::value()); }
00150 EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar& valueRef() { return m_functor(Base::valueRef()); }
00151
00152 protected:
00153 const ViewOp m_functor;
00154 };
00155
00156 template<typename Derived>
00157 EIGEN_STRONG_INLINE Derived&
00158 SparseMatrixBase<Derived>::operator*=(const Scalar& other)
00159 {
00160 for (Index j=0; j<outerSize(); ++j)
00161 for (typename Derived::InnerIterator i(derived(),j); i; ++i)
00162 i.valueRef() *= other;
00163 return derived();
00164 }
00165
00166 template<typename Derived>
00167 EIGEN_STRONG_INLINE Derived&
00168 SparseMatrixBase<Derived>::operator/=(const Scalar& other)
00169 {
00170 for (Index j=0; j<outerSize(); ++j)
00171 for (typename Derived::InnerIterator i(derived(),j); i; ++i)
00172 i.valueRef() /= other;
00173 return derived();
00174 }
00175
00176 }
00177
00178 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H