TR-mbed 1.0
Loading...
Searching...
No Matches
CommaInitializer.h
Go to the documentation of this file.
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_COMMAINITIALIZER_H
12#define EIGEN_COMMAINITIALIZER_H
13
14namespace Eigen {
15
27template<typename XprType>
29{
30 typedef typename XprType::Scalar Scalar;
31
33 inline CommaInitializer(XprType& xpr, const Scalar& s)
34 : m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1)
35 {
36 eigen_assert(m_xpr.rows() > 0 && m_xpr.cols() > 0
37 && "Cannot comma-initialize a 0x0 matrix (operator<<)");
38 m_xpr.coeffRef(0,0) = s;
39 }
40
41 template<typename OtherDerived>
44 : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows())
45 {
46 eigen_assert(m_xpr.rows() >= other.rows() && m_xpr.cols() >= other.cols()
47 && "Cannot comma-initialize a 0x0 matrix (operator<<)");
48 m_xpr.block(0, 0, other.rows(), other.cols()) = other;
49 }
50
51 /* Copy/Move constructor which transfers ownership. This is crucial in
52 * absence of return value optimization to avoid assertions during destruction. */
53 // FIXME in C++11 mode this could be replaced by a proper RValue constructor
57 // Mark original object as finished. In absence of R-value references we need to const_cast:
58 const_cast<CommaInitializer&>(o).m_row = m_xpr.rows();
59 const_cast<CommaInitializer&>(o).m_col = m_xpr.cols();
60 const_cast<CommaInitializer&>(o).m_currentBlockRows = 0;
61 }
62
63 /* inserts a scalar value in the target matrix */
66 {
67 if (m_col==m_xpr.cols())
68 {
70 m_col = 0;
73 && "Too many rows passed to comma initializer (operator<<)");
74 }
76 && "Too many coefficients passed to comma initializer (operator<<)");
78 m_xpr.coeffRef(m_row, m_col++) = s;
79 return *this;
80 }
81
82 /* inserts a matrix expression in the target matrix */
83 template<typename OtherDerived>
86 {
87 if (m_col==m_xpr.cols() && (other.cols()!=0 || other.rows()!=m_currentBlockRows))
88 {
90 m_col = 0;
91 m_currentBlockRows = other.rows();
93 && "Too many rows passed to comma initializer (operator<<)");
94 }
95 eigen_assert((m_col + other.cols() <= m_xpr.cols())
96 && "Too many coefficients passed to comma initializer (operator<<)");
97 eigen_assert(m_currentBlockRows==other.rows());
98 m_xpr.template block<OtherDerived::RowsAtCompileTime, OtherDerived::ColsAtCompileTime>
99 (m_row, m_col, other.rows(), other.cols()) = other;
100 m_col += other.cols();
101 return *this;
102 }
103
106#if defined VERIFY_RAISES_ASSERT && (!defined EIGEN_NO_ASSERTION_CHECKING) && defined EIGEN_EXCEPTIONS
108#endif
109 {
110 finished();
111 }
112
121 inline XprType& finished() {
122 eigen_assert(((m_row+m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0)
123 && m_col == m_xpr.cols()
124 && "Too few coefficients passed to comma initializer (operator<<)");
125 return m_xpr;
126 }
127
128 XprType& m_xpr; // target expression
129 Index m_row; // current row id
130 Index m_col; // current col id
131 Index m_currentBlockRows; // current block height
132};
133
147template<typename Derived>
149{
150 return CommaInitializer<Derived>(*static_cast<Derived*>(this), s);
151}
152
154template<typename Derived>
155template<typename OtherDerived>
158{
159 return CommaInitializer<Derived>(*static_cast<Derived *>(this), other);
160}
161
162} // end namespace Eigen
163
164#endif // EIGEN_COMMAINITIALIZER_H
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define EIGEN_EXCEPTION_SPEC(X)
Definition Macros.h:1426
#define eigen_assert(x)
Definition Macros.h:1037
int rows
Definition Tutorial_commainit_02.cpp:1
int cols
Definition Tutorial_commainit_02.cpp:1
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:47
internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:66
EIGEN_DEVICE_FUNC CommaInitializer< Derived > operator<<(const Scalar &s)
Definition CommaInitializer.h:148
RealScalar s
Definition level1_cplx_impl.h:126
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
CwiseBinaryOp< internal::scalar_sum_op< double, double >, const CpyMatrixXd, const CpyMatrixXd > XprType
Definition nestbyvalue.cpp:15
Helper class used by the comma initializer operator.
Definition CommaInitializer.h:29
EIGEN_DEVICE_FUNC CommaInitializer(const CommaInitializer &o)
Definition CommaInitializer.h:55
XprType & m_xpr
Definition CommaInitializer.h:128
XprType::Scalar Scalar
Definition CommaInitializer.h:30
EIGEN_DEVICE_FUNC CommaInitializer(XprType &xpr, const DenseBase< OtherDerived > &other)
Definition CommaInitializer.h:43
EIGEN_DEVICE_FUNC CommaInitializer & operator,(const Scalar &s)
Definition CommaInitializer.h:65
EIGEN_DEVICE_FUNC XprType & finished()
Definition CommaInitializer.h:121
Index m_currentBlockRows
Definition CommaInitializer.h:131
Index m_col
Definition CommaInitializer.h:130
EIGEN_DEVICE_FUNC ~CommaInitializer()
Definition CommaInitializer.h:105
EIGEN_DEVICE_FUNC CommaInitializer & operator,(const DenseBase< OtherDerived > &other)
Definition CommaInitializer.h:85
EIGEN_DEVICE_FUNC CommaInitializer(XprType &xpr, const Scalar &s)
Definition CommaInitializer.h:33
Index m_row
Definition CommaInitializer.h:129
Definition main.h:229