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  protected:
53  typedef typename XprType::Scalar Scalar;
55  public:
56 
58  : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor)
59  {}
60 
62  { Base::operator++(); return *this; }
63 
64  EIGEN_STRONG_INLINE Scalar value() const { return m_functor(Base::value()); }
65 
66  protected:
67  const UnaryOp m_functor;
68  private:
69  Scalar& valueRef();
70 };
71 
72 template<typename ViewOp, typename ArgType>
74  : public evaluator_base<CwiseUnaryView<ViewOp,ArgType> >
75 {
76  public:
78 
79  class InnerIterator;
80 
81  enum {
83  Flags = XprType::Flags
84  };
85 
86  explicit unary_evaluator(const XprType& op) : m_functor(op.functor()), m_argImpl(op.nestedExpression())
87  {
89  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
90  }
91 
92  protected:
94 
95  const ViewOp m_functor;
97 };
98 
99 template<typename ViewOp, typename ArgType>
101  : public unary_evaluator<CwiseUnaryView<ViewOp,ArgType>, IteratorBased>::EvalIterator
102 {
103  protected:
104  typedef typename XprType::Scalar Scalar;
106  public:
107 
109  : Base(unaryOp.m_argImpl,outer), m_functor(unaryOp.m_functor)
110  {}
111 
113  { Base::operator++(); return *this; }
114 
115  EIGEN_STRONG_INLINE Scalar value() const { return m_functor(Base::value()); }
116  EIGEN_STRONG_INLINE Scalar& valueRef() { return m_functor(Base::valueRef()); }
117 
118  protected:
119  const ViewOp m_functor;
120 };
121 
122 } // end namespace internal
123 
124 template<typename Derived>
125 EIGEN_STRONG_INLINE Derived&
127 {
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;
133  return derived();
134 }
135 
136 template<typename Derived>
137 EIGEN_STRONG_INLINE Derived&
139 {
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;
145  return derived();
146 }
147 
148 } // end namespace Eigen
149 
150 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::m_functor
const ViewOp m_functor
Definition: SparseCwiseUnaryOp.h:119
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::Scalar
XprType::Scalar Scalar
Definition: SparseCwiseUnaryOp.h:104
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::unary_evaluator
unary_evaluator(const XprType &op)
Definition: SparseCwiseUnaryOp.h:86
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::value
EIGEN_STRONG_INLINE Scalar value() const
Definition: SparseCwiseUnaryOp.h:64
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::operator++
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition: SparseCwiseUnaryOp.h:112
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::valueRef
EIGEN_STRONG_INLINE Scalar & valueRef()
Definition: SparseCwiseUnaryOp.h:116
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::EvalIterator
evaluator< ArgType >::InnerIterator EvalIterator
Definition: SparseCwiseUnaryOp.h:93
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::InnerIterator::value
EIGEN_STRONG_INLINE Scalar value() const
Definition: SparseCwiseUnaryOp.h:115
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
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::m_functor
const ViewOp m_functor
Definition: SparseCwiseUnaryOp.h:95
Eigen::internal::evaluator_base
Definition: CoreEvaluators.h:110
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:138
Eigen::SparseMatrixBase< CwiseBinaryOp< BinaryOp, Lhs, Rhs > >::Scalar
internal::traits< Derived >::Scalar Scalar
Definition: SparseMatrixBase.h:31
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::operator++
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition: SparseCwiseUnaryOp.h:61
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::internal::IteratorBased
Definition: Constants.h:545
Eigen::internal::evaluator
Definition: CoreEvaluators.h:90
Eigen::bfloat16_impl::operator++
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator++(bfloat16 &a)
Definition: BFloat16.h:200
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:108
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::Scalar
XprType::Scalar Scalar
Definition: SparseCwiseUnaryOp.h:53
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:96
Eigen::internal::unary_evaluator
Definition: CoreEvaluators.h:65
Eigen::internal::unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::XprType
CwiseUnaryView< ViewOp, ArgType > XprType
Definition: SparseCwiseUnaryOp.h:77
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::InnerIterator
EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator &unaryOp, Index outer)
Definition: SparseCwiseUnaryOp.h:57
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:175
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:105
EIGEN_INTERNAL_CHECK_COST_VALUE
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
Definition: StaticAssert.h:218
Base
Definition: test_virtual_functions.cpp:156
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::m_functor
const UnaryOp m_functor
Definition: SparseCwiseUnaryOp.h:67
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::unary_evaluator
unary_evaluator(const XprType &op)
Definition: SparseCwiseUnaryOp.h:31
test_callbacks.value
value
Definition: test_callbacks.py:160
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Eigen::internal::unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::InnerIterator::Base
unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::EvalIterator Base
Definition: SparseCwiseUnaryOp.h:54
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:35:40