CwiseUnaryOp.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008-2010 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 
00036 namespace internal {
00037 template<typename UnaryOp, typename XprType>
00038 struct traits<CwiseUnaryOp<UnaryOp, XprType> >
00039  : traits<XprType>
00040 {
00041   typedef typename result_of<
00042                      UnaryOp(typename XprType::Scalar)
00043                    >::type Scalar;
00044   typedef typename XprType::Nested XprTypeNested;
00045   typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
00046   enum {
00047     Flags = _XprTypeNested::Flags & (
00048       HereditaryBits | LinearAccessBit | AlignedBit
00049       | (functor_traits<UnaryOp>::PacketAccess ? PacketAccessBit : 0)),
00050     CoeffReadCost = _XprTypeNested::CoeffReadCost + functor_traits<UnaryOp>::Cost
00051   };
00052 };
00053 }
00054 
00055 template<typename UnaryOp, typename XprType, typename StorageKind>
00056 class CwiseUnaryOpImpl;
00057 
00058 template<typename UnaryOp, typename XprType>
00059 class CwiseUnaryOp : internal::no_assignment_operator,
00060   public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>
00061 {
00062   public:
00063 
00064     typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base;
00065     EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
00066 
00067     inline CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
00068       : m_xpr(xpr), m_functor(func) {}
00069 
00070     EIGEN_STRONG_INLINE Index rows() const { return m_xpr.rows(); }
00071     EIGEN_STRONG_INLINE Index cols() const { return m_xpr.cols(); }
00072 
00074     const UnaryOp& functor() const { return m_functor; }
00075 
00077     const typename internal::remove_all<typename XprType::Nested>::type&
00078     nestedExpression() const { return m_xpr; }
00079 
00081     typename internal::remove_all<typename XprType::Nested>::type&
00082     nestedExpression() { return m_xpr.const_cast_derived(); }
00083 
00084   protected:
00085     typename XprType::Nested m_xpr;
00086     const UnaryOp m_functor;
00087 };
00088 
00089 // This is the generic implementation for dense storage.
00090 // It can be used for any expression types implementing the dense concept.
00091 template<typename UnaryOp, typename XprType>
00092 class CwiseUnaryOpImpl<UnaryOp,XprType,Dense>
00093   : public internal::dense_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type
00094 {
00095   public:
00096 
00097     typedef CwiseUnaryOp<UnaryOp, XprType> Derived;
00098     typedef typename internal::dense_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base;
00099     EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
00100 
00101     EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const
00102     {
00103       return derived().functor()(derived().nestedExpression().coeff(row, col));
00104     }
00105 
00106     template<int LoadMode>
00107     EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const
00108     {
00109       return derived().functor().packetOp(derived().nestedExpression().template packet<LoadMode>(row, col));
00110     }
00111 
00112     EIGEN_STRONG_INLINE const Scalar coeff(Index index) const
00113     {
00114       return derived().functor()(derived().nestedExpression().coeff(index));
00115     }
00116 
00117     template<int LoadMode>
00118     EIGEN_STRONG_INLINE PacketScalar packet(Index index) const
00119     {
00120       return derived().functor().packetOp(derived().nestedExpression().template packet<LoadMode>(index));
00121     }
00122 };
00123 
00124 } // end namespace Eigen
00125 
00126 #endif // EIGEN_CWISE_UNARY_OP_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:10:29