SparseCwiseUnaryOp.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_SPARSE_CWISE_UNARY_OP_H
11 #define EIGEN_SPARSE_CWISE_UNARY_OP_H
12 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 template <typename UnaryOp, typename ArgType>
21 struct unary_evaluator<CwiseUnaryOp<UnaryOp, ArgType>, IteratorBased>
22  : public evaluator_base<CwiseUnaryOp<UnaryOp, ArgType> > {
23  public:
25 
26  class InnerIterator;
27 
28  enum {
30  Flags = XprType::Flags
31  };
32 
33  explicit unary_evaluator(const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression()) {
35  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
36  }
37 
38  inline Index nonZerosEstimate() const { return m_argImpl.nonZerosEstimate(); }
39 
40  protected:
42 
43  const UnaryOp m_functor;
45 };
46 
47 template <typename UnaryOp, typename ArgType>
49  : public unary_evaluator<CwiseUnaryOp<UnaryOp, ArgType>, IteratorBased>::EvalIterator {
50  protected:
51  typedef typename XprType::Scalar Scalar;
53 
54  public:
56  : Base(unaryOp.m_argImpl, outer), m_functor(unaryOp.m_functor) {}
57 
60  return *this;
61  }
62 
63  EIGEN_STRONG_INLINE Scalar value() const { return m_functor(Base::value()); }
64 
65  protected:
66  const UnaryOp m_functor;
67 
68  private:
70 };
71 
72 template <typename ViewOp, typename ArgType>
73 struct unary_evaluator<CwiseUnaryView<ViewOp, ArgType>, IteratorBased>
74  : public evaluator_base<CwiseUnaryView<ViewOp, ArgType> > {
75  public:
77 
78  class InnerIterator;
79 
80  enum {
82  Flags = XprType::Flags
83  };
84 
85  explicit unary_evaluator(const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression()) {
87  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
88  }
89 
90  protected:
92 
93  const ViewOp m_functor;
95 };
96 
97 template <typename ViewOp, typename ArgType>
99  : public unary_evaluator<CwiseUnaryView<ViewOp, ArgType>, IteratorBased>::EvalIterator {
100  protected:
101  typedef typename XprType::Scalar Scalar;
103 
104  public:
106  : Base(unaryOp.m_argImpl, outer), m_functor(unaryOp.m_functor) {}
107 
110  return *this;
111  }
112 
113  EIGEN_STRONG_INLINE Scalar value() const { return m_functor(Base::value()); }
114  EIGEN_STRONG_INLINE Scalar& valueRef() { return m_functor(Base::valueRef()); }
115 
116  protected:
117  const ViewOp m_functor;
118 };
119 
120 } // end namespace internal
121 
122 template <typename Derived>
125  internal::evaluator<Derived> thisEval(derived());
126  for (Index j = 0; j < outerSize(); ++j)
127  for (EvalIterator i(thisEval, j); i; ++i) i.valueRef() *= other;
128  return derived();
129 }
130 
131 template <typename Derived>
134  internal::evaluator<Derived> thisEval(derived());
135  for (Index j = 0; j < outerSize(); ++j)
136  for (EvalIterator i(thisEval, j); i; ++i) i.valueRef() /= other;
137  return derived();
138 }
139 
140 } // end namespace Eigen
141 
142 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
Definition: StaticAssert.h:101
SCALAR Scalar
Definition: bench_gemm.cpp:45
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:53
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
Definition: CwiseUnaryView.h:135
An InnerIterator allows to loop over the element of any matrix expression.
Definition: CoreIterators.h:37
internal::traits< Derived >::Scalar Scalar
Definition: SparseMatrixBase.h:32
Derived & operator*=(const Scalar &other)
Definition: SparseCwiseUnaryOp.h:123
Derived & operator/=(const Scalar &other)
Definition: SparseCwiseUnaryOp.h:132
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition: SparseCwiseUnaryOp.h:58
EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator &unaryOp, Index outer)
Definition: SparseCwiseUnaryOp.h:55
unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::EvalIterator Base
Definition: SparseCwiseUnaryOp.h:52
EIGEN_STRONG_INLINE Scalar value() const
Definition: SparseCwiseUnaryOp.h:63
EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator &unaryOp, Index outer)
Definition: SparseCwiseUnaryOp.h:105
EIGEN_STRONG_INLINE Scalar value() const
Definition: SparseCwiseUnaryOp.h:113
unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::EvalIterator Base
Definition: SparseCwiseUnaryOp.h:102
EIGEN_STRONG_INLINE Scalar & valueRef()
Definition: SparseCwiseUnaryOp.h:114
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition: SparseCwiseUnaryOp.h:108
return int(ret)+1
char char * op
Definition: level2_impl.h:374
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator++(bfloat16 &a)
Definition: BFloat16.h:307
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56
Definition: Eigen_Colamd.h:49
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
Definition: Constants.h:580
Definition: CoreEvaluators.h:118
Definition: CoreEvaluators.h:104
Definition: XprHelper.h:205
unary_evaluator(const XprType &op)
Definition: SparseCwiseUnaryOp.h:33
evaluator< ArgType > m_argImpl
Definition: SparseCwiseUnaryOp.h:44
CwiseUnaryOp< UnaryOp, ArgType > XprType
Definition: SparseCwiseUnaryOp.h:24
evaluator< ArgType >::InnerIterator EvalIterator
Definition: SparseCwiseUnaryOp.h:41
unary_evaluator(const XprType &op)
Definition: SparseCwiseUnaryOp.h:85
evaluator< ArgType > m_argImpl
Definition: SparseCwiseUnaryOp.h:94
CwiseUnaryView< ViewOp, ArgType > XprType
Definition: SparseCwiseUnaryOp.h:76
evaluator< ArgType >::InnerIterator EvalIterator
Definition: SparseCwiseUnaryOp.h:91
Definition: CoreEvaluators.h:82
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2