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 namespace Eigen {
14 
15 namespace internal {
16 
17 template<typename UnaryOp, typename ArgType>
18 struct unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>
19  : public evaluator_base<CwiseUnaryOp<UnaryOp,ArgType> >
20 {
21  public:
23 
24  class InnerIterator;
25 
26  enum {
28  Flags = XprType::Flags
29  };
30 
31  explicit unary_evaluator(const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression())
32  {
34  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
35  }
36 
37  inline Index nonZerosEstimate() const {
38  return m_argImpl.nonZerosEstimate();
39  }
40 
41  protected:
43 
44  const UnaryOp m_functor;
46 };
47 
48 template<typename UnaryOp, typename ArgType>
50  : public unary_evaluator<CwiseUnaryOp<UnaryOp,ArgType>, IteratorBased>::EvalIterator
51 {
52  typedef typename XprType::Scalar Scalar;
54  public:
55 
57  : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor)
58  {}
59 
61  { Base::operator++(); return *this; }
62 
63  EIGEN_STRONG_INLINE Scalar value() const { return m_functor(Base::value()); }
64 
65  protected:
66  const UnaryOp m_functor;
67  private:
68  Scalar& valueRef();
69 };
70 
71 template<typename ViewOp, typename ArgType>
73  : public evaluator_base<CwiseUnaryView<ViewOp,ArgType> >
74 {
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())
86  {
88  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
89  }
90 
91  protected:
93 
94  const ViewOp m_functor;
96 };
97 
98 template<typename ViewOp, typename ArgType>
100  : public unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalIterator
101 {
102  typedef typename XprType::Scalar Scalar;
104  public:
105 
107  : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor)
108  {}
109 
111  { Base::operator++(); return *this; }
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>
123 EIGEN_STRONG_INLINE Derived&
125 {
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;
131  return derived();
132 }
133 
134 template<typename Derived>
135 EIGEN_STRONG_INLINE Derived&
137 {
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;
143  return derived();
144 }
145 
146 } // end namespace Eigen
147 
148 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
Definition: LDLT.h:16
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:38
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
Definition: StaticAssert.h:213
internal::traits< Derived >::Scalar Scalar
unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::EvalIterator Base
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Derived & operator*=(const Scalar &other)
Derived & operator/=(const Scalar &other)
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::EvalIterator Base
An InnerIterator allows to loop over the element of any matrix expression.
Definition: CoreIterators.h:33


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:52