1 | // This file is part of Eigen, a lightweight C++ template library
|
---|
2 | // for linear algebra.
|
---|
3 | //
|
---|
4 | // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
---|
5 | // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
---|
6 | //
|
---|
7 | // This Source Code Form is subject to the terms of the Mozilla
|
---|
8 | // Public License v. 2.0. If a copy of the MPL was not distributed
|
---|
9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
---|
10 |
|
---|
11 | #ifndef EIGEN_NESTBYVALUE_H
|
---|
12 | #define EIGEN_NESTBYVALUE_H
|
---|
13 |
|
---|
14 | namespace Eigen {
|
---|
15 |
|
---|
16 | /** \class NestByValue
|
---|
17 | * \ingroup Core_Module
|
---|
18 | *
|
---|
19 | * \brief Expression which must be nested by value
|
---|
20 | *
|
---|
21 | * \param ExpressionType the type of the object of which we are requiring nesting-by-value
|
---|
22 | *
|
---|
23 | * This class is the return type of MatrixBase::nestByValue()
|
---|
24 | * and most of the time this is the only way it is used.
|
---|
25 | *
|
---|
26 | * \sa MatrixBase::nestByValue()
|
---|
27 | */
|
---|
28 |
|
---|
29 | namespace internal {
|
---|
30 | template<typename ExpressionType>
|
---|
31 | struct traits<NestByValue<ExpressionType> > : public traits<ExpressionType>
|
---|
32 | {};
|
---|
33 | }
|
---|
34 |
|
---|
35 | template<typename ExpressionType> class NestByValue
|
---|
36 | : public internal::dense_xpr_base< NestByValue<ExpressionType> >::type
|
---|
37 | {
|
---|
38 | public:
|
---|
39 |
|
---|
40 | typedef typename internal::dense_xpr_base<NestByValue>::type Base;
|
---|
41 | EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue)
|
---|
42 |
|
---|
43 | inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {}
|
---|
44 |
|
---|
45 | inline Index rows() const { return m_expression.rows(); }
|
---|
46 | inline Index cols() const { return m_expression.cols(); }
|
---|
47 | inline Index outerStride() const { return m_expression.outerStride(); }
|
---|
48 | inline Index innerStride() const { return m_expression.innerStride(); }
|
---|
49 |
|
---|
50 | inline const CoeffReturnType coeff(Index row, Index col) const
|
---|
51 | {
|
---|
52 | return m_expression.coeff(row, col);
|
---|
53 | }
|
---|
54 |
|
---|
55 | inline Scalar& coeffRef(Index row, Index col)
|
---|
56 | {
|
---|
57 | return m_expression.const_cast_derived().coeffRef(row, col);
|
---|
58 | }
|
---|
59 |
|
---|
60 | inline const CoeffReturnType coeff(Index index) const
|
---|
61 | {
|
---|
62 | return m_expression.coeff(index);
|
---|
63 | }
|
---|
64 |
|
---|
65 | inline Scalar& coeffRef(Index index)
|
---|
66 | {
|
---|
67 | return m_expression.const_cast_derived().coeffRef(index);
|
---|
68 | }
|
---|
69 |
|
---|
70 | template<int LoadMode>
|
---|
71 | inline const PacketScalar packet(Index row, Index col) const
|
---|
72 | {
|
---|
73 | return m_expression.template packet<LoadMode>(row, col);
|
---|
74 | }
|
---|
75 |
|
---|
76 | template<int LoadMode>
|
---|
77 | inline void writePacket(Index row, Index col, const PacketScalar& x)
|
---|
78 | {
|
---|
79 | m_expression.const_cast_derived().template writePacket<LoadMode>(row, col, x);
|
---|
80 | }
|
---|
81 |
|
---|
82 | template<int LoadMode>
|
---|
83 | inline const PacketScalar packet(Index index) const
|
---|
84 | {
|
---|
85 | return m_expression.template packet<LoadMode>(index);
|
---|
86 | }
|
---|
87 |
|
---|
88 | template<int LoadMode>
|
---|
89 | inline void writePacket(Index index, const PacketScalar& x)
|
---|
90 | {
|
---|
91 | m_expression.const_cast_derived().template writePacket<LoadMode>(index, x);
|
---|
92 | }
|
---|
93 |
|
---|
94 | operator const ExpressionType&() const { return m_expression; }
|
---|
95 |
|
---|
96 | protected:
|
---|
97 | const ExpressionType m_expression;
|
---|
98 | };
|
---|
99 |
|
---|
100 | /** \returns an expression of the temporary version of *this.
|
---|
101 | */
|
---|
102 | template<typename Derived>
|
---|
103 | inline const NestByValue<Derived>
|
---|
104 | DenseBase<Derived>::nestByValue() const
|
---|
105 | {
|
---|
106 | return NestByValue<Derived>(derived());
|
---|
107 | }
|
---|
108 |
|
---|
109 | } // end namespace Eigen
|
---|
110 |
|
---|
111 | #endif // EIGEN_NESTBYVALUE_H
|
---|