Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef EIGEN_CWISE_UNARY_OP_H
00027 #define EIGEN_CWISE_UNARY_OP_H
00028
00029 namespace Eigen {
00030
00051 namespace internal {
00052 template<typename UnaryOp, typename XprType>
00053 struct traits<CwiseUnaryOp<UnaryOp, XprType> >
00054 : traits<XprType>
00055 {
00056 typedef typename result_of<
00057 UnaryOp(typename XprType::Scalar)
00058 >::type Scalar;
00059 typedef typename XprType::Nested XprTypeNested;
00060 typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
00061 enum {
00062 Flags = _XprTypeNested::Flags & (
00063 HereditaryBits | LinearAccessBit | AlignedBit
00064 | (functor_traits<UnaryOp>::PacketAccess ? PacketAccessBit : 0)),
00065 CoeffReadCost = _XprTypeNested::CoeffReadCost + functor_traits<UnaryOp>::Cost
00066 };
00067 };
00068 }
00069
00070 template<typename UnaryOp, typename XprType, typename StorageKind>
00071 class CwiseUnaryOpImpl;
00072
00073 template<typename UnaryOp, typename XprType>
00074 class CwiseUnaryOp : internal::no_assignment_operator,
00075 public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>
00076 {
00077 public:
00078
00079 typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base;
00080 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
00081
00082 inline CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
00083 : m_xpr(xpr), m_functor(func) {}
00084
00085 EIGEN_STRONG_INLINE Index rows() const { return m_xpr.rows(); }
00086 EIGEN_STRONG_INLINE Index cols() const { return m_xpr.cols(); }
00087
00089 const UnaryOp& functor() const { return m_functor; }
00090
00092 const typename internal::remove_all<typename XprType::Nested>::type&
00093 nestedExpression() const { return m_xpr; }
00094
00096 typename internal::remove_all<typename XprType::Nested>::type&
00097 nestedExpression() { return m_xpr.const_cast_derived(); }
00098
00099 protected:
00100 typename XprType::Nested m_xpr;
00101 const UnaryOp m_functor;
00102 };
00103
00104
00105
00106 template<typename UnaryOp, typename XprType>
00107 class CwiseUnaryOpImpl<UnaryOp,XprType,Dense>
00108 : public internal::dense_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type
00109 {
00110 public:
00111
00112 typedef CwiseUnaryOp<UnaryOp, XprType> Derived;
00113 typedef typename internal::dense_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base;
00114 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
00115
00116 EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const
00117 {
00118 return derived().functor()(derived().nestedExpression().coeff(row, col));
00119 }
00120
00121 template<int LoadMode>
00122 EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const
00123 {
00124 return derived().functor().packetOp(derived().nestedExpression().template packet<LoadMode>(row, col));
00125 }
00126
00127 EIGEN_STRONG_INLINE const Scalar coeff(Index index) const
00128 {
00129 return derived().functor()(derived().nestedExpression().coeff(index));
00130 }
00131
00132 template<int LoadMode>
00133 EIGEN_STRONG_INLINE PacketScalar packet(Index index) const
00134 {
00135 return derived().functor().packetOp(derived().nestedExpression().template packet<LoadMode>(index));
00136 }
00137 };
00138
00139 }
00140
00141 #endif // EIGEN_CWISE_UNARY_OP_H