1
// This file is part of Eigen, a lightweight C++ template library
2
// for linear algebra. Eigen itself is part of the KDE project.
4
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
5
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
7
// Eigen is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Lesser General Public
9
// License as published by the Free Software Foundation; either
10
// version 3 of the License, or (at your option) any later version.
12
// Alternatively, you can redistribute it and/or
13
// modify it under the terms of the GNU General Public License as
14
// published by the Free Software Foundation; either version 2 of
15
// the License, or (at your option) any later version.
17
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20
// GNU General Public License for more details.
22
// You should have received a copy of the GNU Lesser General Public
23
// License and a copy of the GNU General Public License along with
24
// Eigen. If not, see <http://www.gnu.org/licenses/>.
26
#ifndef EIGEN_NESTBYVALUE_H
27
#define EIGEN_NESTBYVALUE_H
29
/** \class NestByValue
31
* \brief Expression which must be nested by value
33
* \param ExpressionType the type of the object of which we are requiring nesting-by-value
35
* This class is the return type of MatrixBase::nestByValue()
36
* and most of the time this is the only way it is used.
38
* \sa MatrixBase::nestByValue()
40
template<typename ExpressionType>
41
struct ei_traits<NestByValue<ExpressionType> > : public ei_traits<ExpressionType>
44
template<typename ExpressionType> class NestByValue
45
: public MatrixBase<NestByValue<ExpressionType> >
49
EIGEN_GENERIC_PUBLIC_INTERFACE(NestByValue)
51
inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {}
53
inline int rows() const { return m_expression.rows(); }
54
inline int cols() const { return m_expression.cols(); }
55
inline int stride() const { return m_expression.stride(); }
57
inline const Scalar coeff(int row, int col) const
59
return m_expression.coeff(row, col);
62
inline Scalar& coeffRef(int row, int col)
64
return m_expression.const_cast_derived().coeffRef(row, col);
67
inline const Scalar coeff(int index) const
69
return m_expression.coeff(index);
72
inline Scalar& coeffRef(int index)
74
return m_expression.const_cast_derived().coeffRef(index);
77
template<int LoadMode>
78
inline const PacketScalar packet(int row, int col) const
80
return m_expression.template packet<LoadMode>(row, col);
83
template<int LoadMode>
84
inline void writePacket(int row, int col, const PacketScalar& x)
86
m_expression.const_cast_derived().template writePacket<LoadMode>(row, col, x);
89
template<int LoadMode>
90
inline const PacketScalar packet(int index) const
92
return m_expression.template packet<LoadMode>(index);
95
template<int LoadMode>
96
inline void writePacket(int index, const PacketScalar& x)
98
m_expression.const_cast_derived().template writePacket<LoadMode>(index, x);
102
const ExpressionType m_expression;
105
NestByValue& operator=(const NestByValue&);
108
/** \returns an expression of the temporary version of *this.
110
template<typename Derived>
111
inline const NestByValue<Derived>
112
MatrixBase<Derived>::nestByValue() const
114
return NestByValue<Derived>(derived());
117
#endif // EIGEN_NESTBYVALUE_H