10 #ifndef EIGEN_SPARSE_CWISE_UNARY_OP_H 11 #define EIGEN_SPARSE_CWISE_UNARY_OP_H 17 template<
typename UnaryOp,
typename ArgType>
18 struct unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>
19 :
public evaluator_base<CwiseUnaryOp<UnaryOp,ArgType> >
22 typedef CwiseUnaryOp<UnaryOp, ArgType> XprType;
27 CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<UnaryOp>::Cost,
28 Flags = XprType::Flags
31 explicit unary_evaluator(
const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression())
33 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
34 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
37 inline Index nonZerosEstimate()
const {
38 return m_argImpl.nonZerosEstimate();
42 typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
44 const UnaryOp m_functor;
45 evaluator<ArgType> m_argImpl;
48 template<
typename UnaryOp,
typename ArgType>
49 class unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>::InnerIterator
50 :
public unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>::EvalIterator
52 typedef typename XprType::Scalar Scalar;
53 typedef typename unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>::EvalIterator Base;
56 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& unaryOp,
Index outer)
57 : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor)
60 EIGEN_STRONG_INLINE InnerIterator& operator++()
61 { Base::operator++();
return *
this; }
63 EIGEN_STRONG_INLINE Scalar value()
const {
return m_functor(Base::value()); }
66 const UnaryOp m_functor;
71 template<
typename ViewOp,
typename ArgType>
72 struct unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>
73 :
public evaluator_base<CwiseUnaryView<ViewOp,ArgType> >
76 typedef CwiseUnaryView<ViewOp, ArgType> XprType;
81 CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<ViewOp>::Cost,
82 Flags = XprType::Flags
85 explicit unary_evaluator(
const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression())
87 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<ViewOp>::Cost);
88 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
92 typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
94 const ViewOp m_functor;
95 evaluator<ArgType> m_argImpl;
98 template<
typename ViewOp,
typename ArgType>
99 class unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::InnerIterator
100 :
public unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalIterator
102 typedef typename XprType::Scalar Scalar;
103 typedef typename unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalIterator Base;
106 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& unaryOp,
Index outer)
107 : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor)
110 EIGEN_STRONG_INLINE InnerIterator& operator++()
111 { Base::operator++();
return *
this; }
113 EIGEN_STRONG_INLINE Scalar value()
const {
return m_functor(Base::value()); }
114 EIGEN_STRONG_INLINE Scalar& valueRef() {
return m_functor(Base::valueRef()); }
117 const ViewOp m_functor;
122 template<
typename Derived>
123 EIGEN_STRONG_INLINE Derived&
124 SparseMatrixBase<Derived>::operator*=(
const Scalar& other)
126 typedef typename internal::evaluator<Derived>::InnerIterator EvalIterator;
127 internal::evaluator<Derived> thisEval(derived());
128 for (
Index j=0; j<outerSize(); ++j)
129 for (EvalIterator i(thisEval,j); i; ++i)
130 i.valueRef() *= other;
134 template<
typename Derived>
135 EIGEN_STRONG_INLINE Derived&
136 SparseMatrixBase<Derived>::operator/=(
const Scalar& other)
138 typedef typename internal::evaluator<Derived>::InnerIterator EvalIterator;
139 internal::evaluator<Derived> thisEval(derived());
140 for (
Index j=0; j<outerSize(); ++j)
141 for (EvalIterator i(thisEval,j); i; ++i)
142 i.valueRef() /= other;
148 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H Namespace containing all symbols from the Eigen library.
Definition: Core:287
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: Eigen_Colamd.h:50