NestByValue.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #ifndef EIGEN_NESTBYVALUE_H
  11. #define EIGEN_NESTBYVALUE_H
  12. namespace Eigen {
  13. namespace internal {
  14. template<typename ExpressionType>
  15. struct traits<NestByValue<ExpressionType> > : public traits<ExpressionType>
  16. {};
  17. }
  18. /** \class NestByValue
  19. * \ingroup Core_Module
  20. *
  21. * \brief Expression which must be nested by value
  22. *
  23. * \tparam ExpressionType the type of the object of which we are requiring nesting-by-value
  24. *
  25. * This class is the return type of MatrixBase::nestByValue()
  26. * and most of the time this is the only way it is used.
  27. *
  28. * \sa MatrixBase::nestByValue()
  29. */
  30. template<typename ExpressionType> class NestByValue
  31. : public internal::dense_xpr_base< NestByValue<ExpressionType> >::type
  32. {
  33. public:
  34. typedef typename internal::dense_xpr_base<NestByValue>::type Base;
  35. EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue)
  36. EIGEN_DEVICE_FUNC explicit inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {}
  37. EIGEN_DEVICE_FUNC inline Index rows() const { return m_expression.rows(); }
  38. EIGEN_DEVICE_FUNC inline Index cols() const { return m_expression.cols(); }
  39. EIGEN_DEVICE_FUNC inline Index outerStride() const { return m_expression.outerStride(); }
  40. EIGEN_DEVICE_FUNC inline Index innerStride() const { return m_expression.innerStride(); }
  41. EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index row, Index col) const
  42. {
  43. return m_expression.coeff(row, col);
  44. }
  45. EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index col)
  46. {
  47. return m_expression.const_cast_derived().coeffRef(row, col);
  48. }
  49. EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index index) const
  50. {
  51. return m_expression.coeff(index);
  52. }
  53. EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index index)
  54. {
  55. return m_expression.const_cast_derived().coeffRef(index);
  56. }
  57. template<int LoadMode>
  58. inline const PacketScalar packet(Index row, Index col) const
  59. {
  60. return m_expression.template packet<LoadMode>(row, col);
  61. }
  62. template<int LoadMode>
  63. inline void writePacket(Index row, Index col, const PacketScalar& x)
  64. {
  65. m_expression.const_cast_derived().template writePacket<LoadMode>(row, col, x);
  66. }
  67. template<int LoadMode>
  68. inline const PacketScalar packet(Index index) const
  69. {
  70. return m_expression.template packet<LoadMode>(index);
  71. }
  72. template<int LoadMode>
  73. inline void writePacket(Index index, const PacketScalar& x)
  74. {
  75. m_expression.const_cast_derived().template writePacket<LoadMode>(index, x);
  76. }
  77. EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; }
  78. protected:
  79. const ExpressionType m_expression;
  80. };
  81. /** \returns an expression of the temporary version of *this.
  82. */
  83. template<typename Derived>
  84. inline const NestByValue<Derived>
  85. DenseBase<Derived>::nestByValue() const
  86. {
  87. return NestByValue<Derived>(derived());
  88. }
  89. } // end namespace Eigen
  90. #endif // EIGEN_NESTBYVALUE_H