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 #ifndef EIGEN_CWISE_UNARY_VIEW_H
00026 #define EIGEN_CWISE_UNARY_VIEW_H
00027
00042 namespace internal {
00043 template<typename ViewOp, typename MatrixType>
00044 struct traits<CwiseUnaryView<ViewOp, MatrixType> >
00045 : traits<MatrixType>
00046 {
00047 typedef typename result_of<
00048 ViewOp(typename traits<MatrixType>::Scalar)
00049 >::type Scalar;
00050 typedef typename MatrixType::Nested MatrixTypeNested;
00051 typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
00052 enum {
00053 Flags = (traits<_MatrixTypeNested>::Flags & (HereditaryBits | LvalueBit | LinearAccessBit | DirectAccessBit)),
00054 CoeffReadCost = traits<_MatrixTypeNested>::CoeffReadCost + functor_traits<ViewOp>::Cost,
00055 MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret,
00056
00057
00058 InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
00059 ? int(Dynamic)
00060 : int(MatrixTypeInnerStride)
00061 * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
00062 OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret
00063 };
00064 };
00065 }
00066
00067 template<typename ViewOp, typename MatrixType, typename StorageKind>
00068 class CwiseUnaryViewImpl;
00069
00070 template<typename ViewOp, typename MatrixType>
00071 class CwiseUnaryView : internal::no_assignment_operator,
00072 public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
00073 {
00074 public:
00075
00076 typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
00077 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
00078
00079 inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp())
00080 : m_matrix(mat), m_functor(func) {}
00081
00082 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
00083
00084 EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); }
00085 EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); }
00086
00088 const ViewOp& functor() const { return m_functor; }
00089
00091 const typename internal::remove_all<typename MatrixType::Nested>::type&
00092 nestedExpression() const { return m_matrix; }
00093
00095 typename internal::remove_all<typename MatrixType::Nested>::type&
00096 nestedExpression() { return m_matrix.const_cast_derived(); }
00097
00098 protected:
00099
00100 const typename internal::nested<MatrixType>::type m_matrix;
00101 ViewOp m_functor;
00102 };
00103
00104 template<typename ViewOp, typename MatrixType>
00105 class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
00106 : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
00107 {
00108 public:
00109
00110 typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
00111 typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
00112
00113 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
00114
00115 inline Index innerStride() const
00116 {
00117 return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
00118 }
00119
00120 inline Index outerStride() const
00121 {
00122 return derived().nestedExpression().outerStride();
00123 }
00124
00125 EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const
00126 {
00127 return derived().functor()(derived().nestedExpression().coeff(row, col));
00128 }
00129
00130 EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
00131 {
00132 return derived().functor()(derived().nestedExpression().coeff(index));
00133 }
00134
00135 EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col)
00136 {
00137 return derived().functor()(const_cast_derived().nestedExpression().coeffRef(row, col));
00138 }
00139
00140 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
00141 {
00142 return derived().functor()(const_cast_derived().nestedExpression().coeffRef(index));
00143 }
00144 };
00145
00146
00147
00148 #endif // EIGEN_CWISE_UNARY_VIEW_H