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