11#ifndef EIGEN_CWISE_UNARY_VIEW_H
12#define EIGEN_CWISE_UNARY_VIEW_H
15#include "./InternalHeaderCheck.h"
20template <
typename ViewOp,
typename MatrixType,
typename Str
ideType>
21struct traits<CwiseUnaryView<ViewOp, MatrixType, StrideType> > : traits<MatrixType> {
22 using ScalarRef =
typename result_of<ViewOp(
typename traits<MatrixType>::Scalar&)>::type1;
23 static_assert(std::is_reference<ScalarRef>::value,
"Views must return a reference type.");
24 using Scalar = remove_cvref_t<ScalarRef>;
25 using MatrixTypeNested =
typename MatrixType::Nested;
26 using MatrixTypeNested_ = remove_all_t<MatrixTypeNested>;
28 FlagsLvalueBit = is_lvalue<MatrixType>::value ?
LvalueBit : 0,
30 traits<MatrixTypeNested_>::Flags &
32 MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::value,
35 InnerStrideAtCompileTime =
36 StrideType::InnerStrideAtCompileTime == 0
37 ? (MatrixTypeInnerStride == Dynamic
39 :
int(MatrixTypeInnerStride) *
int(
sizeof(
typename traits<MatrixType>::Scalar) /
sizeof(Scalar)))
40 : int(StrideType::InnerStrideAtCompileTime),
42 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
43 ? (outer_stride_at_compile_time<MatrixType>::value == Dynamic
45 : outer_stride_at_compile_time<MatrixType>::value *
46 int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)))
47 : int(StrideType::OuterStrideAtCompileTime)
52template <
typename ViewOp,
typename XprType,
typename StrideType,
typename StorageKind,
53 bool Mutable = !std::is_const<XprType>::value>
54class CwiseUnaryViewImpl :
public generic_xpr_base<CwiseUnaryView<ViewOp, XprType, StrideType> >::type {
56 using Base =
typename generic_xpr_base<CwiseUnaryView<ViewOp, XprType, StrideType>>::type;
59template <
typename ViewOp,
typename MatrixType,
typename Str
ideType>
60class CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, false>
61 :
public dense_xpr_base<CwiseUnaryView<ViewOp, MatrixType, StrideType> >::type {
63 using Derived = CwiseUnaryView<ViewOp, MatrixType, StrideType>;
64 using Base =
typename dense_xpr_base<CwiseUnaryView<ViewOp, MatrixType, StrideType>>::type;
65 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
66 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
68 EIGEN_DEVICE_FUNC
inline const Scalar* data()
const {
return &(this->coeffRef(0)); }
70 EIGEN_DEVICE_FUNC
constexpr Index innerStride()
const {
71 return StrideType::InnerStrideAtCompileTime != 0
72 ? int(StrideType::InnerStrideAtCompileTime)
73 : derived().nestedExpression().innerStride() * Index(sizeof(typename traits<MatrixType>::Scalar)) /
74 Index(sizeof(Scalar));
77 EIGEN_DEVICE_FUNC
constexpr Index outerStride()
const {
78 return StrideType::OuterStrideAtCompileTime != 0
79 ? int(StrideType::OuterStrideAtCompileTime)
80 : derived().nestedExpression().outerStride() * Index(sizeof(typename traits<MatrixType>::Scalar)) /
81 Index(sizeof(Scalar));
85 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
88 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(Index index)
const {
89 return internal::evaluator<Derived>(derived()).coeffRef(index);
92 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(Index row, Index col)
const {
93 return internal::evaluator<Derived>(derived()).coeffRef(row, col);
97template <
typename ViewOp,
typename MatrixType,
typename Str
ideType>
98class CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, true>
99 :
public CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, false> {
101 using Base = CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, false>;
102 using Derived = CwiseUnaryView<ViewOp, MatrixType, StrideType>;
103 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
104 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
106 using Base::coeffRef;
108 EIGEN_DEVICE_FUNC
inline Scalar* data() {
return &(this->coeffRef(0)); }
110 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) {
111 return internal::evaluator<Derived>(derived()).coeffRef(row, col);
114 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) {
115 return internal::evaluator<Derived>(derived()).coeffRef(index);
119 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
137template <
typename ViewOp,
typename MatrixType,
typename Str
ideType>
138class CwiseUnaryView :
public internal::CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType,
139 typename internal::traits<MatrixType>::StorageKind> {
141 using Base =
typename internal::CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType,
142 typename internal::traits<MatrixType>::StorageKind>::Base;
143 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
144 using MatrixTypeNested =
typename internal::ref_selector<MatrixType>::non_const_type;
145 using NestedExpression = internal::remove_all_t<MatrixType>;
147 explicit EIGEN_DEVICE_FUNC
constexpr inline CwiseUnaryView(MatrixType& mat,
const ViewOp& func = ViewOp())
148 : m_matrix(mat), m_functor(func) {}
150 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
152 EIGEN_DEVICE_FUNC
constexpr Index rows()
const noexcept {
return m_matrix.rows(); }
153 EIGEN_DEVICE_FUNC
constexpr Index cols()
const noexcept {
return m_matrix.cols(); }
156 EIGEN_DEVICE_FUNC
constexpr const ViewOp&
functor()
const {
return m_functor; }
159 EIGEN_DEVICE_FUNC
constexpr const internal::remove_all_t<MatrixTypeNested>&
nestedExpression()
const {
164 EIGEN_DEVICE_FUNC
constexpr std::remove_reference_t<MatrixTypeNested>&
nestedExpression() {
return m_matrix; }
167 MatrixTypeNested m_matrix;
constexpr std::remove_reference_t< MatrixTypeNested > & nestedExpression()
Definition CwiseUnaryView.h:164
constexpr const internal::remove_all_t< MatrixTypeNested > & nestedExpression() const
Definition CwiseUnaryView.h:159
constexpr const ViewOp & functor() const
Definition CwiseUnaryView.h:156
constexpr unsigned int DirectAccessBit
Definition Constants.h:160
constexpr unsigned int LvalueBit
Definition Constants.h:149
constexpr unsigned int RowMajorBit
Definition Constants.h:71