![]() |
Eigen
3.3.3
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> 00005 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> 00006 // 00007 // This Source Code Form is subject to the terms of the Mozilla 00008 // Public License v. 2.0. If a copy of the MPL was not distributed 00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00010 00011 #ifndef EIGEN_CWISE_UNARY_OP_H 00012 #define EIGEN_CWISE_UNARY_OP_H 00013 00014 namespace Eigen { 00015 00016 namespace internal { 00017 template<typename UnaryOp, typename XprType> 00018 struct traits<CwiseUnaryOp<UnaryOp, XprType> > 00019 : traits<XprType> 00020 { 00021 typedef typename result_of< 00022 UnaryOp(const typename XprType::Scalar&) 00023 >::type Scalar; 00024 typedef typename XprType::Nested XprTypeNested; 00025 typedef typename remove_reference<XprTypeNested>::type _XprTypeNested; 00026 enum { 00027 Flags = _XprTypeNested::Flags & RowMajorBit 00028 }; 00029 }; 00030 } 00031 00032 template<typename UnaryOp, typename XprType, typename StorageKind> 00033 class CwiseUnaryOpImpl; 00034 00054 template<typename UnaryOp, typename XprType> 00055 class CwiseUnaryOp : public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>, internal::no_assignment_operator 00056 { 00057 public: 00058 00059 typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base; 00060 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp) 00061 typedef typename internal::ref_selector<XprType>::type XprTypeNested; 00062 typedef typename internal::remove_all<XprType>::type NestedExpression; 00063 00064 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00065 explicit CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp()) 00066 : m_xpr(xpr), m_functor(func) {} 00067 00068 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00069 Index rows() const { return m_xpr.rows(); } 00070 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00071 Index cols() const { return m_xpr.cols(); } 00072 00074 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00075 const UnaryOp& functor() const { return m_functor; } 00076 00078 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00079 const typename internal::remove_all<XprTypeNested>::type& 00080 nestedExpression() const { return m_xpr; } 00081 00083 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00084 typename internal::remove_all<XprTypeNested>::type& 00085 nestedExpression() { return m_xpr; } 00086 00087 protected: 00088 XprTypeNested m_xpr; 00089 const UnaryOp m_functor; 00090 }; 00091 00092 // Generic API dispatcher 00093 template<typename UnaryOp, typename XprType, typename StorageKind> 00094 class CwiseUnaryOpImpl 00095 : public internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type 00096 { 00097 public: 00098 typedef typename internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base; 00099 }; 00100 00101 } // end namespace Eigen 00102 00103 #endif // EIGEN_CWISE_UNARY_OP_H