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 = int(evaluator<ArgType>::CoeffReadCost) + int(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
53 typedef typename XprType::Scalar Scalar;
54 typedef typename unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>::EvalIterator Base;
57 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& unaryOp,
Index outer)
58 : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor)
61 EIGEN_STRONG_INLINE InnerIterator& operator++()
62 { Base::operator++();
return *
this; }
64 EIGEN_STRONG_INLINE Scalar value()
const {
return m_functor(Base::value()); }
67 const UnaryOp m_functor;
72 template<
typename ViewOp,
typename ArgType>
73 struct unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>
74 :
public evaluator_base<CwiseUnaryView<ViewOp,ArgType> >
77 typedef CwiseUnaryView<ViewOp, ArgType> XprType;
82 CoeffReadCost = int(evaluator<ArgType>::CoeffReadCost) + int(functor_traits<ViewOp>::Cost),
83 Flags = XprType::Flags
86 explicit unary_evaluator(
const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression())
88 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<ViewOp>::Cost);
89 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
93 typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
95 const ViewOp m_functor;
96 evaluator<ArgType> m_argImpl;
99 template<
typename ViewOp,
typename ArgType>
100 class unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::InnerIterator
101 :
public unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalIterator
104 typedef typename XprType::Scalar Scalar;
105 typedef typename unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalIterator Base;
108 EIGEN_STRONG_INLINE InnerIterator(
const unary_evaluator& unaryOp,
Index outer)
109 : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor)
112 EIGEN_STRONG_INLINE InnerIterator& operator++()
113 { Base::operator++();
return *
this; }
115 EIGEN_STRONG_INLINE Scalar value()
const {
return m_functor(Base::value()); }
116 EIGEN_STRONG_INLINE Scalar& valueRef() {
return m_functor(Base::valueRef()); }
119 const ViewOp m_functor;
124 template<
typename Derived>
125 EIGEN_STRONG_INLINE Derived&
126 SparseMatrixBase<Derived>::operator*=(
const Scalar& other)
128 typedef typename internal::evaluator<Derived>::InnerIterator EvalIterator;
129 internal::evaluator<Derived> thisEval(derived());
130 for (
Index j=0; j<outerSize(); ++j)
131 for (EvalIterator i(thisEval,j); i; ++i)
132 i.valueRef() *= other;
136 template<
typename Derived>
137 EIGEN_STRONG_INLINE Derived&
138 SparseMatrixBase<Derived>::operator/=(
const Scalar& other)
140 typedef typename internal::evaluator<Derived>::InnerIterator EvalIterator;
141 internal::evaluator<Derived> thisEval(derived());
142 for (
Index j=0; j<outerSize(); ++j)
143 for (EvalIterator i(thisEval,j); i; ++i)
144 i.valueRef() /= other;
150 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: Eigen_Colamd.h:50