File indexing completed on 2025-01-18 09:56:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EIGEN_COMMAINITIALIZER_H
0012 #define EIGEN_COMMAINITIALIZER_H
0013
0014 namespace Eigen {
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 template<typename XprType>
0028 struct CommaInitializer
0029 {
0030 typedef typename XprType::Scalar Scalar;
0031
0032 EIGEN_DEVICE_FUNC
0033 inline CommaInitializer(XprType& xpr, const Scalar& s)
0034 : m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1)
0035 {
0036 eigen_assert(m_xpr.rows() > 0 && m_xpr.cols() > 0
0037 && "Cannot comma-initialize a 0x0 matrix (operator<<)");
0038 m_xpr.coeffRef(0,0) = s;
0039 }
0040
0041 template<typename OtherDerived>
0042 EIGEN_DEVICE_FUNC
0043 inline CommaInitializer(XprType& xpr, const DenseBase<OtherDerived>& other)
0044 : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows())
0045 {
0046 eigen_assert(m_xpr.rows() >= other.rows() && m_xpr.cols() >= other.cols()
0047 && "Cannot comma-initialize a 0x0 matrix (operator<<)");
0048 m_xpr.block(0, 0, other.rows(), other.cols()) = other;
0049 }
0050
0051
0052
0053
0054 EIGEN_DEVICE_FUNC
0055 inline CommaInitializer(const CommaInitializer& o)
0056 : m_xpr(o.m_xpr), m_row(o.m_row), m_col(o.m_col), m_currentBlockRows(o.m_currentBlockRows) {
0057
0058 const_cast<CommaInitializer&>(o).m_row = m_xpr.rows();
0059 const_cast<CommaInitializer&>(o).m_col = m_xpr.cols();
0060 const_cast<CommaInitializer&>(o).m_currentBlockRows = 0;
0061 }
0062
0063
0064 EIGEN_DEVICE_FUNC
0065 CommaInitializer& operator,(const Scalar& s)
0066 {
0067 if (m_col==m_xpr.cols())
0068 {
0069 m_row+=m_currentBlockRows;
0070 m_col = 0;
0071 m_currentBlockRows = 1;
0072 eigen_assert(m_row<m_xpr.rows()
0073 && "Too many rows passed to comma initializer (operator<<)");
0074 }
0075 eigen_assert(m_col<m_xpr.cols()
0076 && "Too many coefficients passed to comma initializer (operator<<)");
0077 eigen_assert(m_currentBlockRows==1);
0078 m_xpr.coeffRef(m_row, m_col++) = s;
0079 return *this;
0080 }
0081
0082
0083 template<typename OtherDerived>
0084 EIGEN_DEVICE_FUNC
0085 CommaInitializer& operator,(const DenseBase<OtherDerived>& other)
0086 {
0087 if (m_col==m_xpr.cols() && (other.cols()!=0 || other.rows()!=m_currentBlockRows))
0088 {
0089 m_row+=m_currentBlockRows;
0090 m_col = 0;
0091 m_currentBlockRows = other.rows();
0092 eigen_assert(m_row+m_currentBlockRows<=m_xpr.rows()
0093 && "Too many rows passed to comma initializer (operator<<)");
0094 }
0095 eigen_assert((m_col + other.cols() <= m_xpr.cols())
0096 && "Too many coefficients passed to comma initializer (operator<<)");
0097 eigen_assert(m_currentBlockRows==other.rows());
0098 m_xpr.template block<OtherDerived::RowsAtCompileTime, OtherDerived::ColsAtCompileTime>
0099 (m_row, m_col, other.rows(), other.cols()) = other;
0100 m_col += other.cols();
0101 return *this;
0102 }
0103
0104 EIGEN_DEVICE_FUNC
0105 inline ~CommaInitializer()
0106 #if defined VERIFY_RAISES_ASSERT && (!defined EIGEN_NO_ASSERTION_CHECKING) && defined EIGEN_EXCEPTIONS
0107 EIGEN_EXCEPTION_SPEC(Eigen::eigen_assert_exception)
0108 #endif
0109 {
0110 finished();
0111 }
0112
0113
0114
0115
0116
0117
0118
0119
0120 EIGEN_DEVICE_FUNC
0121 inline XprType& finished() {
0122 eigen_assert(((m_row+m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0)
0123 && m_col == m_xpr.cols()
0124 && "Too few coefficients passed to comma initializer (operator<<)");
0125 return m_xpr;
0126 }
0127
0128 XprType& m_xpr;
0129 Index m_row;
0130 Index m_col;
0131 Index m_currentBlockRows;
0132 };
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147 template<typename Derived>
0148 EIGEN_DEVICE_FUNC inline CommaInitializer<Derived> DenseBase<Derived>::operator<< (const Scalar& s)
0149 {
0150 return CommaInitializer<Derived>(*static_cast<Derived*>(this), s);
0151 }
0152
0153
0154 template<typename Derived>
0155 template<typename OtherDerived>
0156 EIGEN_DEVICE_FUNC inline CommaInitializer<Derived>
0157 DenseBase<Derived>::operator<<(const DenseBase<OtherDerived>& other)
0158 {
0159 return CommaInitializer<Derived>(*static_cast<Derived *>(this), other);
0160 }
0161
0162 }
0163
0164 #endif