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 ? int(StrideType::InnerStrideAtCompileTime)
72 : derived().nestedExpression().innerStride() *
73 sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar);
76 EIGEN_DEVICE_FUNC
constexpr Index outerStride()
const {
77 return StrideType::OuterStrideAtCompileTime != 0 ? int(StrideType::OuterStrideAtCompileTime)
78 : derived().nestedExpression().outerStride() *
79 sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar);
83 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
86 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(Index index)
const {
87 return internal::evaluator<Derived>(derived()).coeffRef(index);
90 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(Index row, Index col)
const {
91 return internal::evaluator<Derived>(derived()).coeffRef(row, col);
95template <
typename ViewOp,
typename MatrixType,
typename Str
ideType>
96class CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, true>
97 :
public CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, false> {
99 using Base = CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType, Dense, false>;
100 using Derived = CwiseUnaryView<ViewOp, MatrixType, StrideType>;
101 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
102 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
104 using Base::coeffRef;
106 EIGEN_DEVICE_FUNC
inline Scalar* data() {
return &(this->coeffRef(0)); }
108 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) {
109 return internal::evaluator<Derived>(derived()).coeffRef(row, col);
112 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) {
113 return internal::evaluator<Derived>(derived()).coeffRef(index);
117 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
135template <
typename ViewOp,
typename MatrixType,
typename Str
ideType>
136class CwiseUnaryView :
public internal::CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType,
137 typename internal::traits<MatrixType>::StorageKind> {
139 using Base =
typename internal::CwiseUnaryViewImpl<ViewOp, MatrixType, StrideType,
140 typename internal::traits<MatrixType>::StorageKind>::Base;
141 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
142 using MatrixTypeNested =
typename internal::ref_selector<MatrixType>::non_const_type;
143 using NestedExpression = internal::remove_all_t<MatrixType>;
145 explicit EIGEN_DEVICE_FUNC
constexpr inline CwiseUnaryView(MatrixType& mat,
const ViewOp& func = ViewOp())
146 : m_matrix(mat), m_functor(func) {}
148 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
150 EIGEN_DEVICE_FUNC
constexpr Index rows()
const noexcept {
return m_matrix.rows(); }
151 EIGEN_DEVICE_FUNC
constexpr Index cols()
const noexcept {
return m_matrix.cols(); }
154 EIGEN_DEVICE_FUNC
constexpr const ViewOp&
functor()
const {
return m_functor; }
157 EIGEN_DEVICE_FUNC
constexpr const internal::remove_all_t<MatrixTypeNested>&
nestedExpression()
const {
162 EIGEN_DEVICE_FUNC
constexpr std::remove_reference_t<MatrixTypeNested>&
nestedExpression() {
return m_matrix; }
165 MatrixTypeNested m_matrix;
constexpr std::remove_reference_t< MatrixTypeNested > & nestedExpression()
Definition CwiseUnaryView.h:162
constexpr const internal::remove_all_t< MatrixTypeNested > & nestedExpression() const
Definition CwiseUnaryView.h:157
constexpr const ViewOp & functor() const
Definition CwiseUnaryView.h:154
constexpr unsigned int DirectAccessBit
Definition Constants.h:160
constexpr unsigned int LvalueBit
Definition Constants.h:149
constexpr unsigned int RowMajorBit
Definition Constants.h:71