Eigen  3.4.90 (git rev a4098ac676528a83cfb73d4d26ce1b42ec05f47c)
CwiseUnaryView.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_CWISE_UNARY_VIEW_H
11#define EIGEN_CWISE_UNARY_VIEW_H
12
13#include "./InternalHeaderCheck.h"
14
15namespace Eigen {
16
17namespace internal {
18template<typename ViewOp, typename MatrixType>
19struct traits<CwiseUnaryView<ViewOp, MatrixType> >
20 : traits<MatrixType>
21{
22 typedef typename result_of<
23 ViewOp(const typename traits<MatrixType>::Scalar&)
24 >::type Scalar;
25 typedef typename MatrixType::Nested MatrixTypeNested;
26 typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
27 enum {
28 FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
29 Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions
30 MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret,
31 // need to cast the sizeof's from size_t to int explicitly, otherwise:
32 // "error: no integral type can represent all of the enumerator values
33 InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
34 ? int(Dynamic)
35 : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
36 OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic
37 ? int(Dynamic)
38 : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
39 };
40};
41}
42
43template<typename ViewOp, typename MatrixType, typename StorageKind>
44class CwiseUnaryViewImpl;
45
59template<typename ViewOp, typename MatrixType>
60class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
61{
62 public:
63
64 typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
65 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
66 typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
67 typedef typename internal::remove_all<MatrixType>::type NestedExpression;
68
69 explicit EIGEN_DEVICE_FUNC inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp())
70 : m_matrix(mat), m_functor(func) {}
71
72 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
73
74 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
75 Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
76 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
77 Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
78
80 EIGEN_DEVICE_FUNC const ViewOp& functor() const { return m_functor; }
81
83 EIGEN_DEVICE_FUNC const typename internal::remove_all<MatrixTypeNested>::type&
84 nestedExpression() const { return m_matrix; }
85
87 EIGEN_DEVICE_FUNC typename internal::remove_reference<MatrixTypeNested>::type&
88 nestedExpression() { return m_matrix; }
89
90 protected:
91 MatrixTypeNested m_matrix;
92 ViewOp m_functor;
93};
94
95// Generic API dispatcher
96template<typename ViewOp, typename XprType, typename StorageKind>
97class CwiseUnaryViewImpl
98 : public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type
99{
100public:
101 typedef typename internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type Base;
102};
103
104template<typename ViewOp, typename MatrixType>
105class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
106 : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
107{
108 public:
109
110 typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
111 typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
112
113 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
114 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
115
116 EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); }
117 EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); }
118
119 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const
120 {
121 return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
122 }
123
124 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const
125 {
126 return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
127 }
128 protected:
129 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
130};
131
132} // end namespace Eigen
133
134#endif // EIGEN_CWISE_UNARY_VIEW_H
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
Definition: CwiseUnaryView.h:61
const ViewOp & functor() const
Definition: CwiseUnaryView.h:80
internal::remove_reference< MatrixTypeNested >::type & nestedExpression()
Definition: CwiseUnaryView.h:88
const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: CwiseUnaryView.h:84
const unsigned int DirectAccessBit
Definition: Constants.h:157
const unsigned int LvalueBit
Definition: Constants.h:146
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24