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-2010 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 template<typename UnaryOp, typename MatrixType>
16 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>
17  : public SparseMatrixBase<CwiseUnaryOp<UnaryOp, MatrixType> >
18 {
19  public:
20 
21  class InnerIterator;
22  class ReverseInnerIterator;
23 
26 
27  protected:
28  typedef typename internal::traits<Derived>::_XprTypeNested _MatrixTypeNested;
29  typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
30  typedef typename _MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator;
31 };
32 
33 template<typename UnaryOp, typename MatrixType>
34 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::InnerIterator
35  : public CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeIterator
36 {
37  typedef typename CwiseUnaryOpImpl::Scalar Scalar;
39  public:
40 
41  EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryOpImpl& unaryOp, typename CwiseUnaryOpImpl::Index outer)
42  : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
43  {}
44 
46  { Base::operator++(); return *this; }
47 
48  EIGEN_STRONG_INLINE typename CwiseUnaryOpImpl::Scalar value() const { return m_functor(Base::value()); }
49 
50  protected:
51  const UnaryOp m_functor;
52  private:
53  typename CwiseUnaryOpImpl::Scalar& valueRef();
54 };
55 
56 template<typename UnaryOp, typename MatrixType>
57 class CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::ReverseInnerIterator
58  : public CwiseUnaryOpImpl<UnaryOp,MatrixType,Sparse>::MatrixTypeReverseIterator
59 {
60  typedef typename CwiseUnaryOpImpl::Scalar Scalar;
62  public:
63 
64  EIGEN_STRONG_INLINE ReverseInnerIterator(const CwiseUnaryOpImpl& unaryOp, typename CwiseUnaryOpImpl::Index outer)
65  : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
66  {}
67 
68  EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
69  { Base::operator--(); return *this; }
70 
71  EIGEN_STRONG_INLINE typename CwiseUnaryOpImpl::Scalar value() const { return m_functor(Base::value()); }
72 
73  protected:
74  const UnaryOp m_functor;
75  private:
76  typename CwiseUnaryOpImpl::Scalar& valueRef();
77 };
78 
79 template<typename ViewOp, typename MatrixType>
80 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>
81  : public SparseMatrixBase<CwiseUnaryView<ViewOp, MatrixType> >
82 {
83  public:
84 
85  class InnerIterator;
86  class ReverseInnerIterator;
87 
90 
91  protected:
92  typedef typename internal::traits<Derived>::_MatrixTypeNested _MatrixTypeNested;
93  typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
94  typedef typename _MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator;
95 };
96 
97 template<typename ViewOp, typename MatrixType>
98 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::InnerIterator
99  : public CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeIterator
100 {
101  typedef typename CwiseUnaryViewImpl::Scalar Scalar;
103  public:
104 
105  EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryViewImpl& unaryOp, typename CwiseUnaryViewImpl::Index outer)
106  : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
107  {}
108 
110  { Base::operator++(); return *this; }
111 
112  EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar value() const { return m_functor(Base::value()); }
113  EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar& valueRef() { return m_functor(Base::valueRef()); }
114 
115  protected:
116  const ViewOp m_functor;
117 };
118 
119 template<typename ViewOp, typename MatrixType>
120 class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::ReverseInnerIterator
121  : public CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::MatrixTypeReverseIterator
122 {
123  typedef typename CwiseUnaryViewImpl::Scalar Scalar;
125  public:
126 
127  EIGEN_STRONG_INLINE ReverseInnerIterator(const CwiseUnaryViewImpl& unaryOp, typename CwiseUnaryViewImpl::Index outer)
128  : Base(unaryOp.derived().nestedExpression(),outer), m_functor(unaryOp.derived().functor())
129  {}
130 
131  EIGEN_STRONG_INLINE ReverseInnerIterator& operator--()
132  { Base::operator--(); return *this; }
133 
134  EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar value() const { return m_functor(Base::value()); }
135  EIGEN_STRONG_INLINE typename CwiseUnaryViewImpl::Scalar& valueRef() { return m_functor(Base::valueRef()); }
136 
137  protected:
138  const ViewOp m_functor;
139 };
140 
141 template<typename Derived>
142 EIGEN_STRONG_INLINE Derived&
144 {
145  for (Index j=0; j<outerSize(); ++j)
146  for (typename Derived::InnerIterator i(derived(),j); i; ++i)
147  i.valueRef() *= other;
148  return derived();
149 }
150 
151 template<typename Derived>
152 EIGEN_STRONG_INLINE Derived&
154 {
155  for (Index j=0; j<outerSize(); ++j)
156  for (typename Derived::InnerIterator i(derived(),j); i; ++i)
157  i.valueRef() /= other;
158  return derived();
159 }
160 
161 } // end namespace Eigen
162 
163 #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H
EIGEN_STRONG_INLINE ReverseInnerIterator(const CwiseUnaryViewImpl &unaryOp, typename CwiseUnaryViewImpl::Index outer)
#define EIGEN_STRONG_INLINE
EIGEN_STRONG_INLINE CwiseUnaryOpImpl::Scalar value() const
internal::traits< Derived >::_MatrixTypeNested _MatrixTypeNested
EIGEN_STRONG_INLINE CwiseUnaryOpImpl::Scalar value() const
EIGEN_STRONG_INLINE ReverseInnerIterator(const CwiseUnaryOpImpl &unaryOp, typename CwiseUnaryOpImpl::Index outer)
Definition: LDLT.h:16
CwiseUnaryViewImpl< ViewOp, MatrixType, Sparse >::MatrixTypeReverseIterator Base
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryViewImpl &unaryOp, typename CwiseUnaryViewImpl::Index outer)
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
Definition: SparseUtil.h:62
Base class of any sparse matrices or sparse expressions.
internal::traits< Derived >::Scalar Scalar
CwiseUnaryViewImpl< ViewOp, MatrixType, Sparse >::MatrixTypeIterator Base
CwiseUnaryOpImpl< UnaryOp, MatrixType, Sparse >::MatrixTypeIterator Base
_MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator
_MatrixTypeNested::ReverseInnerIterator MatrixTypeReverseIterator
internal::traits< Derived >::Index Index
Definition: EigenBase.h:31
EIGEN_STRONG_INLINE CwiseUnaryViewImpl::Scalar value() const
An InnerIterator allows to loop over the element of a sparse (or dense) matrix or expression...
Derived & operator*=(const Scalar &other)
Derived & operator/=(const Scalar &other)
EIGEN_STRONG_INLINE CwiseUnaryViewImpl::Scalar & valueRef()
EIGEN_STRONG_INLINE InnerIterator(const CwiseUnaryOpImpl &unaryOp, typename CwiseUnaryOpImpl::Index outer)
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:59
internal::traits< Derived >::_XprTypeNested _MatrixTypeNested
EIGEN_STRONG_INLINE CwiseUnaryViewImpl::Scalar value() const
CwiseUnaryOpImpl< UnaryOp, MatrixType, Sparse >::MatrixTypeReverseIterator Base


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:40:58