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
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
00103
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