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
SCALAR Scalar
Definition: bench_gemm.cpp:46
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:39
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:218
internal::traits< CwiseBinaryOp< BinaryOp, Lhs, Rhs > >::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:74
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
std::ptrdiff_t j
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator++(bfloat16 &a)
Definition: BFloat16.h:200
An InnerIterator allows to loop over the element of any matrix expression.
Definition: CoreIterators.h:33


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:35:57