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 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_CWISE_UNARY_OP_H
00027 #define EIGEN_CWISE_UNARY_OP_H
00028 
00049 namespace internal {
00050 template<typename UnaryOp, typename XprType>
00051 struct traits<CwiseUnaryOp<UnaryOp, XprType> >
00052  : traits<XprType>
00053 {
00054   typedef typename result_of<
00055                      UnaryOp(typename XprType::Scalar)
00056                    >::type Scalar;
00057   typedef typename XprType::Nested XprTypeNested;
00058   typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
00059   enum {
00060     Flags = _XprTypeNested::Flags & (
00061       HereditaryBits | LinearAccessBit | AlignedBit
00062       | (functor_traits<UnaryOp>::PacketAccess ? PacketAccessBit : 0)),
00063     CoeffReadCost = _XprTypeNested::CoeffReadCost + functor_traits<UnaryOp>::Cost
00064   };
00065 };
00066 }
00067 
00068 template<typename UnaryOp, typename XprType, typename StorageKind>
00069 class CwiseUnaryOpImpl;
00070 
00071 template<typename UnaryOp, typename XprType>
00072 class CwiseUnaryOp : internal::no_assignment_operator,
00073   public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>
00074 {
00075   public:
00076 
00077     typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base;
00078     EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
00079 
00080     inline CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
00081       : m_xpr(xpr), m_functor(func) {}
00082 
00083     EIGEN_STRONG_INLINE Index rows() const { return m_xpr.rows(); }
00084     EIGEN_STRONG_INLINE Index cols() const { return m_xpr.cols(); }
00085 
00087     const UnaryOp& functor() const { return m_functor; }
00088 
00090     const typename internal::remove_all<typename XprType::Nested>::type&
00091     nestedExpression() const { return m_xpr; }
00092 
00094     typename internal::remove_all<typename XprType::Nested>::type&
00095     nestedExpression() { return m_xpr.const_cast_derived(); }
00096 
00097   protected:
00098     const typename XprType::Nested m_xpr;
00099     const UnaryOp m_functor;
00100 };
00101 
00102 // This is the generic implementation for dense storage.
00103 // It can be used for any expression types implementing the dense concept.
00104 template<typename UnaryOp, typename XprType>
00105 class CwiseUnaryOpImpl<UnaryOp,XprType,Dense>
00106   : public internal::dense_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type
00107 {
00108   public:
00109 
00110     typedef CwiseUnaryOp<UnaryOp, XprType> Derived;
00111     typedef typename internal::dense_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base;
00112     EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
00113 
00114     EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const
00115     {
00116       return derived().functor()(derived().nestedExpression().coeff(row, col));
00117     }
00118 
00119     template<int LoadMode>
00120     EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const
00121     {
00122       return derived().functor().packetOp(derived().nestedExpression().template packet<LoadMode>(row, col));
00123     }
00124 
00125     EIGEN_STRONG_INLINE const Scalar coeff(Index index) const
00126     {
00127       return derived().functor()(derived().nestedExpression().coeff(index));
00128     }
00129 
00130     template<int LoadMode>
00131     EIGEN_STRONG_INLINE PacketScalar packet(Index index) const
00132     {
00133       return derived().functor().packetOp(derived().nestedExpression().template packet<LoadMode>(index));
00134     }
00135 };
00136 
00137 #endif // EIGEN_CWISE_UNARY_OP_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:36