10#ifndef EIGEN_CWISE_UNARY_VIEW_H
11#define EIGEN_CWISE_UNARY_VIEW_H
14#include "./InternalHeaderCheck.h"
19template <
typename ViewOp,
typename MatrixType,
typename Str
ideType>
20struct traits<CwiseUnaryView<ViewOp, MatrixType, StrideType> > : traits<MatrixType> {
21 typedef typename result_of<ViewOp(
typename traits<MatrixType>::Scalar&)>::type1 ScalarRef;
22 static_assert(std::is_reference<ScalarRef>::value,
"Views must return a reference type.");
23 typedef remove_all_t<ScalarRef> Scalar;
24 typedef typename MatrixType::Nested MatrixTypeNested;
25 typedef remove_all_t<MatrixTypeNested> MatrixTypeNested_;
27 FlagsLvalueBit = is_lvalue<MatrixType>::value ?
LvalueBit : 0,
29 traits<MatrixTypeNested_>::Flags &
31 MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret,
34 InnerStrideAtCompileTime =
35 StrideType::InnerStrideAtCompileTime == 0
36 ? (MatrixTypeInnerStride == Dynamic
38 : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)))
39 : int(StrideType::InnerStrideAtCompileTime),
41 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
42 ? (outer_stride_at_compile_time<MatrixType>::ret ==
Dynamic
44 : outer_stride_at_compile_time<MatrixType>::ret *
45 int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)))
46 : int(StrideType::OuterStrideAtCompileTime)
51template <
typename ViewOp,
typename XprType,
typename StrideType,
typename StorageKind,
52 bool Mutable = !std::is_const<XprType>::value>
53class CwiseUnaryViewImpl :
public generic_xpr_base<CwiseUnaryView<ViewOp, XprType, StrideType> >::type {
55 typedef typename generic_xpr_base<CwiseUnaryView<ViewOp, XprType, StrideType> >::type Base;
58template <
typename ViewOp,
typename MatrixType,
typename Str
ideType>
59class CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, false>
60 :
public dense_xpr_base<CwiseUnaryView<ViewOp, MatrixType, StrideType> >::type {
62 typedef CwiseUnaryView<ViewOp, MatrixType, StrideType> Derived;
63 typedef typename dense_xpr_base<CwiseUnaryView<ViewOp, MatrixType, StrideType> >::type Base;
64 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
65 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
67 EIGEN_DEVICE_FUNC
inline const Scalar* data()
const {
return &(this->coeffRef(0)); }
69 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index innerStride()
const {
70 return StrideType::InnerStrideAtCompileTime != 0 ? int(StrideType::InnerStrideAtCompileTime)
71 : derived().nestedExpression().innerStride() *
72 sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar);
75 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index outerStride()
const {
76 return StrideType::OuterStrideAtCompileTime != 0 ? int(StrideType::OuterStrideAtCompileTime)
77 : derived().nestedExpression().outerStride() *
78 sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar);
82 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
85 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(Index index)
const {
86 return internal::evaluator<Derived>(derived()).coeffRef(index);
89 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(Index row, Index col)
const {
90 return internal::evaluator<Derived>(derived()).coeffRef(row, col);
94template <
typename ViewOp,
typename MatrixType,
typename Str
ideType>
95class CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, true>
96 :
public CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, false> {
98 typedef CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, false> Base;
99 typedef CwiseUnaryView<ViewOp, MatrixType, StrideType> Derived;
100 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
101 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
104 EIGEN_DEVICE_FUNC
inline Scalar* data() {
return &(this->coeffRef(0)); }
106 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) {
107 return internal::evaluator<Derived>(derived()).coeffRef(row, col);
110 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) {
111 return internal::evaluator<Derived>(derived()).coeffRef(index);
115 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
133template <
typename ViewOp,
typename MatrixType,
typename Str
ideType>
134class CwiseUnaryView :
public internal::CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType,
135 typename internal::traits<MatrixType>::StorageKind> {
137 typedef typename internal::CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType,
138 typename internal::traits<MatrixType>::StorageKind>::Base Base;
140 typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
141 typedef internal::remove_all_t<MatrixType> NestedExpression;
143 explicit EIGEN_DEVICE_FUNC
inline CwiseUnaryView(MatrixType& mat,
const ViewOp& func = ViewOp())
144 : m_matrix(mat), m_functor(func) {}
148 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
Index rows()
const EIGEN_NOEXCEPT {
return m_matrix.rows(); }
149 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
Index cols()
const EIGEN_NOEXCEPT {
return m_matrix.cols(); }
152 EIGEN_DEVICE_FUNC
const ViewOp&
functor()
const {
return m_functor; }
155 EIGEN_DEVICE_FUNC
const internal::remove_all_t<MatrixTypeNested>&
nestedExpression()
const {
return m_matrix; }
158 EIGEN_DEVICE_FUNC std::remove_reference_t<MatrixTypeNested>&
nestedExpression() {
return m_matrix; }
161 MatrixTypeNested m_matrix;
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
Definition CwiseUnaryView.h:135
std::remove_reference_t< MatrixTypeNested > & nestedExpression()
Definition CwiseUnaryView.h:158
const internal::remove_all_t< MatrixTypeNested > & nestedExpression() const
Definition CwiseUnaryView.h:155
const ViewOp & functor() const
Definition CwiseUnaryView.h:152
const unsigned int DirectAccessBit
Definition Constants.h:159
const unsigned int LvalueBit
Definition Constants.h:148
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition Core:137
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:83
const int Dynamic
Definition Constants.h:25