10 #ifndef EIGEN_SPARSE_CWISE_UNARY_OP_H
11 #define EIGEN_SPARSE_CWISE_UNARY_OP_H
15 template<
typename UnaryOp,
typename MatrixType>
16 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>
17 :
public SparseMatrixBase<CwiseUnaryOp<UnaryOp, MatrixType> >
22 class ReverseInnerIterator;
24 typedef CwiseUnaryOp<UnaryOp, MatrixType> Derived;
25 EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
28 typedef typename internal::traits<Derived>::_XprTypeNested _MatrixTypeNested;
29 typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
30 typedef typename _MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator;
33 template<typename UnaryOp, typename MatrixType>
34 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::InnerIterator
35 : public CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeIterator
37 typedef typename CwiseUnaryOpImpl::Scalar Scalar;
38 typedef typename CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeIterator Base;
41 EIGEN_STRONG_INLINE InnerIterator(
const CwiseUnaryOpImpl& unaryOp,
typename CwiseUnaryOpImpl::Index outer)
42 : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
45 EIGEN_STRONG_INLINE InnerIterator& operator++()
46 { Base::operator++();
return *
this; }
48 EIGEN_STRONG_INLINE
typename CwiseUnaryOpImpl::Scalar value()
const {
return m_functor(Base::value()); }
51 const UnaryOp m_functor;
53 typename CwiseUnaryOpImpl::Scalar& valueRef();
56 template<
typename UnaryOp,
typename MatrixType>
57 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::ReverseInnerIterator
58 :
public CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeReverseIterator
60 typedef typename CwiseUnaryOpImpl::Scalar Scalar;
61 typedef typename CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeReverseIterator Base;
64 EIGEN_STRONG_INLINE ReverseInnerIterator(
const CwiseUnaryOpImpl& unaryOp,
typename CwiseUnaryOpImpl::Index outer)
65 : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
68 EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
69 { Base::operator--();
return *
this; }
71 EIGEN_STRONG_INLINE
typename CwiseUnaryOpImpl::Scalar value()
const {
return m_functor(Base::value()); }
74 const UnaryOp m_functor;
76 typename CwiseUnaryOpImpl::Scalar& valueRef();
79 template<
typename ViewOp,
typename MatrixType>
80 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>
81 :
public SparseMatrixBase<CwiseUnaryView<ViewOp, MatrixType> >
86 class ReverseInnerIterator;
88 typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
89 EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
92 typedef typename internal::traits<Derived>::_MatrixTypeNested _MatrixTypeNested;
93 typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
94 typedef typename _MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator;
97 template<typename ViewOp, typename MatrixType>
98 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::InnerIterator
99 : public CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeIterator
101 typedef typename CwiseUnaryViewImpl::Scalar Scalar;
102 typedef typename CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeIterator Base;
105 EIGEN_STRONG_INLINE InnerIterator(
const CwiseUnaryViewImpl& unaryOp,
typename CwiseUnaryViewImpl::Index outer)
106 : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
109 EIGEN_STRONG_INLINE InnerIterator& operator++()
110 { Base::operator++();
return *
this; }
112 EIGEN_STRONG_INLINE
typename CwiseUnaryViewImpl::Scalar value()
const {
return m_functor(Base::value()); }
113 EIGEN_STRONG_INLINE
typename CwiseUnaryViewImpl::Scalar& valueRef() {
return m_functor(Base::valueRef()); }
116 const ViewOp m_functor;
119 template<
typename ViewOp,
typename MatrixType>
120 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::ReverseInnerIterator
121 :
public CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeReverseIterator
123 typedef typename CwiseUnaryViewImpl::Scalar Scalar;
124 typedef typename CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeReverseIterator Base;
127 EIGEN_STRONG_INLINE ReverseInnerIterator(
const CwiseUnaryViewImpl& unaryOp,
typename CwiseUnaryViewImpl::Index outer)
128 : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
131 EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
132 { Base::operator--();
return *
this; }
134 EIGEN_STRONG_INLINE
typename CwiseUnaryViewImpl::Scalar value()
const {
return m_functor(Base::value()); }
135 EIGEN_STRONG_INLINE
typename CwiseUnaryViewImpl::Scalar& valueRef() {
return m_functor(Base::valueRef()); }
138 const ViewOp m_functor;
141 template<
typename Derived>
142 EIGEN_STRONG_INLINE Derived&
143 SparseMatrixBase<Derived>::operator*=(
const Scalar& other)
145 for (Index j=0; j<outerSize(); ++j)
146 for (
typename Derived::InnerIterator i(derived(),j); i; ++i)
147 i.valueRef() *= other;
151 template<
typename Derived>
152 EIGEN_STRONG_INLINE Derived&
153 SparseMatrixBase<Derived>::operator/=(
const Scalar& other)
155 for (Index j=0; j<outerSize(); ++j)
156 for (
typename Derived::InnerIterator i(derived(),j); i; ++i)
157 i.valueRef() /= other;
163 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H