10 #ifndef EIGEN_CWISE_UNARY_VIEW_H
11 #define EIGEN_CWISE_UNARY_VIEW_H
30 template<
typename ViewOp,
typename MatrixType>
31 struct traits<CwiseUnaryView<ViewOp, MatrixType> >
34 typedef typename result_of<
35 ViewOp(
typename traits<MatrixType>::Scalar)
37 typedef typename MatrixType::Nested MatrixTypeNested;
38 typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
41 CoeffReadCost = EIGEN_ADD_COST(traits<_MatrixTypeNested>::CoeffReadCost, functor_traits<ViewOp>::Cost),
42 MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret,
45 InnerStrideAtCompileTime = MatrixTypeInnerStride ==
Dynamic
47 : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
48 OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret ==
Dynamic
50 : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
55 template<
typename ViewOp,
typename MatrixType,
typename StorageKind>
56 class CwiseUnaryViewImpl;
58 template<
typename ViewOp,
typename MatrixType>
59 class CwiseUnaryView :
public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
63 typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
66 inline CwiseUnaryView(
const MatrixType& mat,
const ViewOp& func = ViewOp())
67 : m_matrix(mat), m_functor(func) {}
71 EIGEN_STRONG_INLINE Index rows()
const {
return m_matrix.rows(); }
72 EIGEN_STRONG_INLINE Index cols()
const {
return m_matrix.cols(); }
75 const ViewOp&
functor()
const {
return m_functor; }
78 const typename internal::remove_all<typename MatrixType::Nested>::type&
82 typename internal::remove_all<typename MatrixType::Nested>::type&
87 typename internal::nested<MatrixType>::type m_matrix;
91 template<
typename ViewOp,
typename MatrixType>
92 class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
93 :
public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
97 typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
98 typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
100 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
101 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
103 inline Scalar* data() {
return &coeffRef(0); }
104 inline const Scalar* data()
const {
return &coeff(0); }
106 inline Index innerStride()
const
108 return derived().nestedExpression().innerStride() *
sizeof(
typename internal::traits<MatrixType>::Scalar) /
sizeof(Scalar);
111 inline Index outerStride()
const
113 return derived().nestedExpression().outerStride() *
sizeof(
typename internal::traits<MatrixType>::Scalar) /
sizeof(Scalar);
116 EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col)
const
118 return derived().functor()(derived().nestedExpression().coeff(row, col));
121 EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const
123 return derived().functor()(derived().nestedExpression().coeff(index));
126 EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col)
128 return derived().functor()(const_cast_derived().nestedExpression().coeffRef(row, col));
131 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
133 return derived().functor()(const_cast_derived().nestedExpression().coeffRef(index));
139 #endif // EIGEN_CWISE_UNARY_VIEW_H
const ViewOp & functor() const
Definition: CwiseUnaryView.h:75
const int Dynamic
Definition: Constants.h:21
internal::remove_all< typename MatrixType::Nested >::type & nestedExpression()
Definition: CwiseUnaryView.h:83
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
Definition: CwiseUnaryView.h:59
const unsigned int LinearAccessBit
Definition: Constants.h:117
const unsigned int LvalueBit
Definition: Constants.h:131
const internal::remove_all< typename MatrixType::Nested >::type & nestedExpression() const
Definition: CwiseUnaryView.h:79
const unsigned int DirectAccessBit
Definition: Constants.h:142