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
Eigen
Definition: common.h:73
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::m_functor
const ViewOp m_functor
Definition: SparseCwiseUnaryOp.h:117
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::Scalar
XprType::Scalar Scalar
Definition: SparseCwiseUnaryOp.h:102
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::unary_evaluator
unary_evaluator(const XprType &op)
Definition: SparseCwiseUnaryOp.h:85
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::value
EIGEN_STRONG_INLINE Scalar value() const
Definition: SparseCwiseUnaryOp.h:63
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::operator++
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition: SparseCwiseUnaryOp.h:110
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::valueRef
EIGEN_STRONG_INLINE Scalar & valueRef()
Definition: SparseCwiseUnaryOp.h:114
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::EvalIterator
evaluator< ArgType >::InnerIterator EvalIterator
Definition: SparseCwiseUnaryOp.h:92
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::value
EIGEN_STRONG_INLINE Scalar value() const
Definition: SparseCwiseUnaryOp.h:113
Eigen::SparseMatrixBase::operator*=
Derived & operator*=(const Scalar &other)
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::m_functor
const UnaryOp m_functor
Definition: SparseCwiseUnaryOp.h:44
Scalar
SCALAR Scalar
Definition: common.h:84
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::m_functor
const ViewOp m_functor
Definition: SparseCwiseUnaryOp.h:94
Eigen::internal::evaluator_base
Definition: CoreEvaluators.h:109
Eigen::CwiseUnaryView
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
Definition: CwiseUnaryView.h:58
Eigen::SparseMatrixBase::operator/=
Derived & operator/=(const Scalar &other)
Definition: SparseCwiseUnaryOp.h:136
Eigen::SparseMatrixBase< CwiseBinaryOp< BinaryOp, Lhs, Rhs > >::Scalar
internal::traits< Derived >::Scalar Scalar
Definition: SparseMatrixBase.h:31
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::operator++
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition: SparseCwiseUnaryOp.h:60
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:494
Eigen::internal::IteratorBased
Definition: Constants.h:529
Eigen::internal::evaluator
Definition: CoreEvaluators.h:90
Eigen::InnerIterator
An InnerIterator allows to loop over the element of any matrix expression.
Definition: CoreIterators.h:33
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::m_argImpl
evaluator< ArgType > m_argImpl
Definition: SparseCwiseUnaryOp.h:45
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::XprType
CwiseUnaryOp< UnaryOp, ArgType > XprType
Definition: SparseCwiseUnaryOp.h:22
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::InnerIterator
EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator &unaryOp, Index outer)
Definition: SparseCwiseUnaryOp.h:106
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::Scalar
XprType::Scalar Scalar
Definition: SparseCwiseUnaryOp.h:52
Eigen::CwiseUnaryOp
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::m_argImpl
evaluator< ArgType > m_argImpl
Definition: SparseCwiseUnaryOp.h:95
Eigen::internal::unary_evaluator
Definition: CoreEvaluators.h:65
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::XprType
CwiseUnaryView< ViewOp, ArgType > XprType
Definition: SparseCwiseUnaryOp.h:76
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::InnerIterator
EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator &unaryOp, Index outer)
Definition: SparseCwiseUnaryOp.h:56
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::EvalIterator
evaluator< ArgType >::InnerIterator EvalIterator
Definition: SparseCwiseUnaryOp.h:42
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::nonZerosEstimate
Index nonZerosEstimate() const
Definition: SparseCwiseUnaryOp.h:37
Eigen::internal::functor_traits
Definition: XprHelper.h:146
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::Base
unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::EvalIterator Base
Definition: SparseCwiseUnaryOp.h:103
EIGEN_INTERNAL_CHECK_COST_VALUE
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
Definition: StaticAssert.h:215
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::m_functor
const UnaryOp m_functor
Definition: SparseCwiseUnaryOp.h:66
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::unary_evaluator
unary_evaluator(const XprType &op)
Definition: SparseCwiseUnaryOp.h:31
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::Base
unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::EvalIterator Base
Definition: SparseCwiseUnaryOp.h:53
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:06:18