File indexing completed on 2025-01-18 09:56:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_CWISE_UNARY_VIEW_H
0011 #define EIGEN_CWISE_UNARY_VIEW_H
0012
0013 namespace Eigen {
0014
0015 namespace internal {
0016 template<typename ViewOp, typename MatrixType>
0017 struct traits<CwiseUnaryView<ViewOp, MatrixType> >
0018 : traits<MatrixType>
0019 {
0020 typedef typename result_of<
0021 ViewOp(const typename traits<MatrixType>::Scalar&)
0022 >::type Scalar;
0023 typedef typename MatrixType::Nested MatrixTypeNested;
0024 typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
0025 enum {
0026 FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
0027 Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit),
0028 MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret,
0029
0030
0031 InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
0032 ? int(Dynamic)
0033 : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
0034 OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic
0035 ? int(Dynamic)
0036 : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
0037 };
0038 };
0039 }
0040
0041 template<typename ViewOp, typename MatrixType, typename StorageKind>
0042 class CwiseUnaryViewImpl;
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 template<typename ViewOp, typename MatrixType>
0058 class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
0059 {
0060 public:
0061
0062 typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
0063 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
0064 typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
0065 typedef typename internal::remove_all<MatrixType>::type NestedExpression;
0066
0067 explicit EIGEN_DEVICE_FUNC inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp())
0068 : m_matrix(mat), m_functor(func) {}
0069
0070 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
0071
0072 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
0073 Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
0074 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
0075 Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
0076
0077
0078 EIGEN_DEVICE_FUNC const ViewOp& functor() const { return m_functor; }
0079
0080
0081 EIGEN_DEVICE_FUNC const typename internal::remove_all<MatrixTypeNested>::type&
0082 nestedExpression() const { return m_matrix; }
0083
0084
0085 EIGEN_DEVICE_FUNC typename internal::remove_reference<MatrixTypeNested>::type&
0086 nestedExpression() { return m_matrix; }
0087
0088 protected:
0089 MatrixTypeNested m_matrix;
0090 ViewOp m_functor;
0091 };
0092
0093
0094 template<typename ViewOp, typename XprType, typename StorageKind>
0095 class CwiseUnaryViewImpl
0096 : public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type
0097 {
0098 public:
0099 typedef typename internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type Base;
0100 };
0101
0102 template<typename ViewOp, typename MatrixType>
0103 class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
0104 : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
0105 {
0106 public:
0107
0108 typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
0109 typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
0110
0111 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
0112 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
0113
0114 EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); }
0115 EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); }
0116
0117 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const
0118 {
0119 return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
0120 }
0121
0122 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const
0123 {
0124 return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
0125 }
0126 protected:
0127 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
0128 };
0129
0130 }
0131
0132 #endif