TR-mbed 1.0
Loading...
Searching...
No Matches
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
13namespace Eigen {
14
15namespace internal {
16
17template<typename UnaryOp, typename ArgType>
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 {
35 }
36
37 inline Index nonZerosEstimate() const {
38 return m_argImpl.nonZerosEstimate();
39 }
40
41 protected:
43
46};
47
48template<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:
68 private:
69 Scalar& valueRef();
70};
71
72template<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 {
90 }
91
92 protected:
94
97};
98
99template<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:
120};
121
122} // end namespace internal
123
124template<typename Derived>
125EIGEN_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
136template<typename Derived>
137EIGEN_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
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define EIGEN_STRONG_INLINE
Definition Macros.h:917
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
Definition StaticAssert.h:218
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition CwiseUnaryOp.h:56
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
Definition CwiseUnaryView.h:59
An InnerIterator allows to loop over the element of any matrix expression.
Definition CoreIterators.h:34
internal::traits< Derived >::Scalar Scalar
Definition SparseMatrixBase.h:31
Derived & operator*=(const Scalar &other)
Definition SparseCwiseUnaryOp.h:126
Derived & operator/=(const Scalar &other)
Definition SparseCwiseUnaryOp.h:138
EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator &unaryOp, Index outer)
Definition SparseCwiseUnaryOp.h:57
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition SparseCwiseUnaryOp.h:61
EIGEN_STRONG_INLINE Scalar value() const
Definition SparseCwiseUnaryOp.h:64
unary_evaluator< CwiseUnaryOp< UnaryOp, ArgType >, IteratorBased >::EvalIterator Base
Definition SparseCwiseUnaryOp.h:54
unary_evaluator< CwiseUnaryView< ViewOp, ArgType >, IteratorBased >::EvalIterator Base
Definition SparseCwiseUnaryOp.h:105
EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator &unaryOp, Index outer)
Definition SparseCwiseUnaryOp.h:108
EIGEN_STRONG_INLINE Scalar value() const
Definition SparseCwiseUnaryOp.h:115
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition SparseCwiseUnaryOp.h:112
EIGEN_STRONG_INLINE Scalar & valueRef()
Definition SparseCwiseUnaryOp.h:116
return int(ret)+1
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Definition BandTriangularSolver.h:13
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:39
Definition Constants.h:545
Definition CoreEvaluators.h:111
Definition CoreEvaluators.h:91
Definition XprHelper.h:176
Definition ForwardDeclarations.h:17
unary_evaluator(const XprType &op)
Definition SparseCwiseUnaryOp.h:31
evaluator< ArgType > m_argImpl
Definition SparseCwiseUnaryOp.h:45
CwiseUnaryOp< UnaryOp, ArgType > XprType
Definition SparseCwiseUnaryOp.h:22
evaluator< ArgType >::InnerIterator EvalIterator
Definition SparseCwiseUnaryOp.h:42
unary_evaluator(const XprType &op)
Definition SparseCwiseUnaryOp.h:86
evaluator< ArgType > m_argImpl
Definition SparseCwiseUnaryOp.h:96
CwiseUnaryView< ViewOp, ArgType > XprType
Definition SparseCwiseUnaryOp.h:77
evaluator< ArgType >::InnerIterator EvalIterator
Definition SparseCwiseUnaryOp.h:93
Definition CoreEvaluators.h:65
std::ptrdiff_t j
Definition tut_arithmetic_redux_minmax.cpp:2