Eigen  3.2.92
CwiseUnaryOp.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_CWISE_UNARY_OP_H
12 #define EIGEN_CWISE_UNARY_OP_H
13 
14 namespace Eigen {
15 
36 namespace internal {
37 template<typename UnaryOp, typename XprType>
38 struct traits<CwiseUnaryOp<UnaryOp, XprType> >
39  : traits<XprType>
40 {
41  typedef typename result_of<
42  UnaryOp(typename XprType::Scalar)
43  >::type Scalar;
44  typedef typename XprType::Nested XprTypeNested;
45  typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
46  enum {
47  Flags = _XprTypeNested::Flags & RowMajorBit
48  };
49 };
50 }
51 
52 template<typename UnaryOp, typename XprType, typename StorageKind>
53 class CwiseUnaryOpImpl;
54 
55 template<typename UnaryOp, typename XprType>
56 class CwiseUnaryOp : public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>, internal::no_assignment_operator
57 {
58  public:
59 
60  typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base;
61  EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
62  typedef typename internal::remove_all<XprType>::type NestedExpression;
63 
64  EIGEN_DEVICE_FUNC
65  explicit inline CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
66  : m_xpr(xpr), m_functor(func) {}
67 
68  EIGEN_DEVICE_FUNC
69  EIGEN_STRONG_INLINE Index rows() const { return m_xpr.rows(); }
70  EIGEN_DEVICE_FUNC
71  EIGEN_STRONG_INLINE Index cols() const { return m_xpr.cols(); }
72 
74  EIGEN_DEVICE_FUNC
75  const UnaryOp& functor() const { return m_functor; }
76 
78  EIGEN_DEVICE_FUNC
79  const typename internal::remove_all<typename XprType::Nested>::type&
80  nestedExpression() const { return m_xpr; }
81 
83  EIGEN_DEVICE_FUNC
84  typename internal::remove_all<typename XprType::Nested>::type&
85  nestedExpression() { return m_xpr.const_cast_derived(); }
86 
87  protected:
88  typename XprType::Nested m_xpr;
89  const UnaryOp m_functor;
90 };
91 
92 // Generic API dispatcher
93 template<typename UnaryOp, typename XprType, typename StorageKind>
94 class CwiseUnaryOpImpl
95  : public internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type
96 {
97 public:
98  typedef typename internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base;
99 };
100 
101 } // end namespace Eigen
102 
103 #endif // EIGEN_CWISE_UNARY_OP_H
const UnaryOp & functor() const
Definition: CwiseUnaryOp.h:75
const internal::remove_all< typename XprType::Nested >::type & nestedExpression() const
Definition: CwiseUnaryOp.h:80
Definition: LDLT.h:16
const unsigned int RowMajorBit
Definition: Constants.h:61
internal::remove_all< typename XprType::Nested >::type & nestedExpression()
Definition: CwiseUnaryOp.h:85
Definition: Eigen_Colamd.h:54
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:56