WPILibC++ 2023.4.3-108-ge5452e3
CwiseUnaryView.h
Go to the documentation of this file.
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
13namespace Eigen {
14
15namespace internal {
16template<typename ViewOp, typename MatrixType>
17struct traits<CwiseUnaryView<ViewOp, MatrixType> >
18 : traits<MatrixType>
19{
20 typedef typename result_of<
21 ViewOp(const typename traits<MatrixType>::Scalar&)
23 typedef typename MatrixType::Nested MatrixTypeNested;
25 enum {
27 Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions
29 // need to cast the sizeof's from size_t to int explicitly, otherwise:
30 // "error: no integral type can represent all of the enumerator values
31 InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
32 ? int(Dynamic)
33 : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
34 OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic
35 ? int(Dynamic)
36 : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
37 };
38};
39}
40
41template<typename ViewOp, typename MatrixType, typename StorageKind>
43
44/** \class CwiseUnaryView
45 * \ingroup Core_Module
46 *
47 * \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector
48 *
49 * \tparam ViewOp template functor implementing the view
50 * \tparam MatrixType the type of the matrix we are applying the unary operator
51 *
52 * This class represents a lvalue expression of a generic unary view operator of a matrix or a vector.
53 * It is the return type of real() and imag(), and most of the time this is the only way it is used.
54 *
55 * \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp
56 */
57template<typename ViewOp, typename MatrixType>
58class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
59{
60 public:
61
64 typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
65 typedef typename internal::remove_all<MatrixType>::type NestedExpression;
66
67 explicit EIGEN_DEVICE_FUNC inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp())
68 : m_matrix(mat), m_functor(func) {}
69
71
73 Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
75 Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
76
77 /** \returns the functor representing unary operation */
78 EIGEN_DEVICE_FUNC const ViewOp& functor() const { return m_functor; }
79
80 /** \returns the nested expression */
82 nestedExpression() const { return m_matrix; }
83
84 /** \returns the nested expression */
86 nestedExpression() { return m_matrix; }
87
88 protected:
90 ViewOp m_functor;
91};
92
93// Generic API dispatcher
94template<typename ViewOp, typename XprType, typename StorageKind>
96 : public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type
97{
98public:
100};
101
102template<typename ViewOp, typename MatrixType>
103class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
104 : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
105{
106 public:
107
110
113
114 EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); }
115 EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); }
116
118 {
119 return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
120 }
121
123 {
124 return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
125 }
126 protected:
128};
129
130} // end namespace Eigen
131
132#endif // EIGEN_CWISE_UNARY_VIEW_H
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
Just a side note.
Definition: Macros.h:1274
#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived)
Definition: Macros.h:1257
#define EIGEN_NOEXCEPT
Definition: Macros.h:1428
#define EIGEN_CONSTEXPR
Definition: Macros.h:797
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:986
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1293
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: Macros.h:1241
#define EIGEN_STRONG_INLINE
Definition: Macros.h:927
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
Definition: CwiseUnaryView.h:59
EIGEN_DEVICE_FUNC const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: CwiseUnaryView.h:82
EIGEN_DEVICE_FUNC const ViewOp & functor() const
Definition: CwiseUnaryView.h:78
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: CwiseUnaryView.h:75
ViewOp m_functor
Definition: CwiseUnaryView.h:90
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: CwiseUnaryView.h:73
CwiseUnaryViewImpl< ViewOp, MatrixType, typenameinternal::traits< MatrixType >::StorageKind >::Base Base
Definition: CwiseUnaryView.h:62
EIGEN_DEVICE_FUNC internal::remove_reference< MatrixTypeNested >::type & nestedExpression()
Definition: CwiseUnaryView.h:86
internal::remove_all< MatrixType >::type NestedExpression
Definition: CwiseUnaryView.h:65
MatrixTypeNested m_matrix
Definition: CwiseUnaryView.h:89
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const
Definition: CwiseUnaryView.h:122
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerStride() const
Definition: CwiseUnaryView.h:117
CwiseUnaryView< ViewOp, MatrixType > Derived
Definition: CwiseUnaryView.h:108
internal::dense_xpr_base< CwiseUnaryView< ViewOp, MatrixType > >::type Base
Definition: CwiseUnaryView.h:109
EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: CwiseUnaryView.h:115
Definition: CwiseUnaryView.h:97
internal::generic_xpr_base< CwiseUnaryView< ViewOp, XprType > >::type Base
Definition: CwiseUnaryView.h:99
type
Definition: core.h:575
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array.
Definition: Constants.h:155
const unsigned int LvalueBit
Means the expression has a coeffRef() method, i.e.
Definition: Constants.h:144
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:66
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time,...
Definition: Constants.h:22
Definition: Eigen_Colamd.h:50
The type used to identify a dense storage.
Definition: Constants.h:507
Definition: XprHelper.h:484
Definition: XprHelper.h:501
Definition: DenseCoeffsBase.h:659
Definition: XprHelper.h:660
Definition: DenseCoeffsBase.h:671
T type
Definition: Meta.h:126
T type
Definition: Meta.h:114
Definition: Meta.h:513
result_of< ViewOp(consttypenametraits< MatrixType >::Scalar &)>::type Scalar
Definition: CwiseUnaryView.h:22
MatrixType::Nested MatrixTypeNested
Definition: CwiseUnaryView.h:23
remove_all< MatrixTypeNested >::type _MatrixTypeNested
Definition: CwiseUnaryView.h:24
Definition: ForwardDeclarations.h:17
Definition: Meta.h:96
Definition: format.h:1552