This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
View | Details | Raw Unified | Return to bug 755
Collapse All | Expand All

(-)a/Eigen/src/Core/CommaInitializer.h (-1 / +52 lines)
Lines 8-23 Link Here
8
// Public License v. 2.0. If a copy of the MPL was not distributed
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/.
9
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
10
11
#ifndef EIGEN_COMMAINITIALIZER_H
11
#ifndef EIGEN_COMMAINITIALIZER_H
12
#define EIGEN_COMMAINITIALIZER_H
12
#define EIGEN_COMMAINITIALIZER_H
13
13
14
namespace Eigen { 
14
namespace Eigen { 
15
15
16
namespace internal {
17
18
19
20
template<typename XprType>
21
struct CommaInitializerRef {
22
  typedef typename XprType::Index Index;
23
  XprType& m_xpr;
24
  Index m_row, m_col, m_currentBlockRows;
25
  
26
  explicit CommaInitializerRef(XprType& xpr, Index row, Index col, Index currentBlockRows)
27
   : m_xpr(xpr), m_row(row), m_col(col), m_currentBlockRows(currentBlockRows) {
28
    std::cout << __PRETTY_FUNCTION__ << std::endl;
29
  }
30
};
31
32
}  // end namespace internal
33
  
16
/** \class CommaInitializer
34
/** \class CommaInitializer
17
  * \ingroup Core_Module
35
  * \ingroup Core_Module
18
  *
36
  *
19
  * \brief Helper class used by the comma initializer operator
37
  * \brief Helper class used by the comma initializer operator
20
  *
38
  *
21
  * This class is internally used to implement the comma initializer feature. It is
39
  * This class is internally used to implement the comma initializer feature. It is
22
  * the return type of MatrixBase::operator<<, and most of the time this is the only
40
  * the return type of MatrixBase::operator<<, and most of the time this is the only
23
  * way it is used.
41
  * way it is used.
Lines 25-46 namespace Eigen { Link Here
25
  * \sa \ref MatrixBaseCommaInitRef "MatrixBase::operator<<", CommaInitializer::finished()
43
  * \sa \ref MatrixBaseCommaInitRef "MatrixBase::operator<<", CommaInitializer::finished()
26
  */
44
  */
27
template<typename XprType>
45
template<typename XprType>
28
struct CommaInitializer
46
struct CommaInitializer
29
{
47
{
30
  typedef typename XprType::Scalar Scalar;
48
  typedef typename XprType::Scalar Scalar;
31
  typedef typename XprType::Index Index;
49
  typedef typename XprType::Index Index;
32
50
51
52
  operator internal::CommaInitializerRef<XprType>()
53
  {
54
    std::cout << __PRETTY_FUNCTION__ << std::endl;
55
    internal::CommaInitializerRef<XprType> ret(m_xpr, m_row, m_col, m_currentBlockRows);
56
    m_row = m_xpr.rows();
57
    m_col = m_xpr.cols();
58
    m_currentBlockRows = 0;
59
    return ret;
60
  }
61
62
  
33
  inline CommaInitializer(XprType& xpr, const Scalar& s)
63
  inline CommaInitializer(XprType& xpr, const Scalar& s)
34
    : m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1)
64
    : m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1)
35
  {
65
  {
36
    m_xpr.coeffRef(0,0) = s;
66
    m_xpr.coeffRef(0,0) = s;
37
  }
67
  }
38
68
  
69
#ifdef EIGEN_HAVE_RVALUE_REFERENCES
70
  inline CommaInitializer(CommaInitializer&& o)
71
#else
72
  inline CommaInitializer(CommaInitializer& o)
73
#endif
74
    : m_xpr(o.m_xpr), m_row(o.m_row), m_col(o.m_col), m_currentBlockRows(o.m_currentBlockRows) {
75
    std::cout << __PRETTY_FUNCTION__ << std::endl;
76
    o.m_row = m_xpr.rows();
77
    o.m_col = m_xpr.cols();
78
    o.m_currentBlockRows = 0;
79
  }
80
  
81
#ifndef EIGEN_HAVE_RVALUE_REFERENCES
82
  inline CommaInitializer(internal::CommaInitializerRef<XprType> o)
83
    : m_xpr(o.m_xpr), 
84
      m_row(o.m_row), 
85
      m_col(o.m_col), 
86
      m_currentBlockRows(o.m_currentBlockRows) {
87
  }
88
#endif
39
  template<typename OtherDerived>
89
  template<typename OtherDerived>
40
  inline CommaInitializer(XprType& xpr, const DenseBase<OtherDerived>& other)
90
  inline CommaInitializer(XprType& xpr, const DenseBase<OtherDerived>& other)
41
    : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows())
91
    : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows())
42
  {
92
  {
43
    m_xpr.block(0, 0, other.rows(), other.cols()) = other;
93
    m_xpr.block(0, 0, other.rows(), other.cols()) = other;
44
  }
94
  }
45
95
46
  /* inserts a scalar value in the target matrix */
96
  /* inserts a scalar value in the target matrix */
Lines 85-100 struct CommaInitializer Link Here
85
    else
135
    else
86
      m_xpr.block(m_row, m_col, other.rows(), other.cols()) = other;
136
      m_xpr.block(m_row, m_col, other.rows(), other.cols()) = other;
87
    m_col += other.cols();
137
    m_col += other.cols();
88
    return *this;
138
    return *this;
89
  }
139
  }
90
140
91
  inline ~CommaInitializer()
141
  inline ~CommaInitializer()
92
  {
142
  {
143
    std::cout << __PRETTY_FUNCTION__ << m_row << std::endl;
93
    eigen_assert((m_row+m_currentBlockRows) == m_xpr.rows()
144
    eigen_assert((m_row+m_currentBlockRows) == m_xpr.rows()
94
         && m_col == m_xpr.cols()
145
         && m_col == m_xpr.cols()
95
         && "Too few coefficients passed to comma initializer (operator<<)");
146
         && "Too few coefficients passed to comma initializer (operator<<)");
96
  }
147
  }
97
148
98
  /** \returns the built matrix once all its coefficients have been set.
149
  /** \returns the built matrix once all its coefficients have been set.
99
    * Calling finished is 100% optional. Its purpose is to write expressions
150
    * Calling finished is 100% optional. Its purpose is to write expressions
100
    * like this:
151
    * like this:

Return to bug 755