11 #ifndef EIGEN_DIAGONALMATRIX_H 12 #define EIGEN_DIAGONALMATRIX_H 16 #ifndef EIGEN_PARSED_BY_DOXYGEN 17 template<
typename Derived>
22 typedef typename DiagonalVectorType::Scalar Scalar;
23 typedef typename DiagonalVectorType::RealScalar RealScalar;
28 RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
29 ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
30 MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
31 MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
32 IsVectorAtCompileTime = 0,
41 inline const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
43 inline Derived& derived() {
return *
static_cast<Derived*
>(
this); }
46 DenseMatrixType toDenseMatrix()
const {
return derived(); }
49 inline const DiagonalVectorType& diagonal()
const {
return derived().diagonal(); }
51 inline DiagonalVectorType& diagonal() {
return derived().diagonal(); }
54 inline Index rows()
const {
return diagonal().size(); }
56 inline Index cols()
const {
return diagonal().size(); }
58 template<
typename MatrixDerived>
68 inline const InverseReturnType
71 return InverseReturnType(diagonal().cwiseInverse());
76 operator*(
const Scalar& scalar)
const 82 operator*(
const Scalar& scalar,
const DiagonalBase& other)
104 template<
typename _Scalar,
int SizeAtCompileTime,
int MaxSizeAtCompileTime>
106 :
traits<Matrix<_Scalar,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
115 template<
typename _Scalar,
int SizeAtCompileTime,
int MaxSizeAtCompileTime>
117 :
public DiagonalBase<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime> >
120 #ifndef EIGEN_PARSED_BY_DOXYGEN 123 typedef _Scalar Scalar;
130 DiagonalVectorType m_diagonal;
136 inline const DiagonalVectorType&
diagonal()
const {
return m_diagonal; }
139 inline DiagonalVectorType&
diagonal() {
return m_diagonal; }
155 inline DiagonalMatrix(
const Scalar& x,
const Scalar& y,
const Scalar& z) : m_diagonal(x,y,z) {}
158 template<
typename OtherDerived>
162 #ifndef EIGEN_PARSED_BY_DOXYGEN 168 template<
typename OtherDerived>
174 template<
typename OtherDerived>
178 m_diagonal = other.diagonal();
182 #ifndef EIGEN_PARSED_BY_DOXYGEN 199 inline void setZero() { m_diagonal.setZero(); }
226 template<
typename _DiagonalVectorType>
229 typedef _DiagonalVectorType DiagonalVectorType;
230 typedef typename DiagonalVectorType::Scalar Scalar;
231 typedef typename DiagonalVectorType::StorageIndex StorageIndex;
235 RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
236 ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
237 MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
238 MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
244 template<
typename _DiagonalVectorType>
249 #ifndef EIGEN_PARSED_BY_DOXYGEN 250 typedef _DiagonalVectorType DiagonalVectorType;
256 explicit inline DiagonalWrapper(DiagonalVectorType& a_diagonal) : m_diagonal(a_diagonal) {}
260 const DiagonalVectorType&
diagonal()
const {
return m_diagonal; }
263 typename DiagonalVectorType::Nested m_diagonal;
275 template<
typename Derived>
290 template<
typename Derived>
293 if(cols() != rows())
return false;
294 RealScalar maxAbsOnDiagonal =
static_cast<RealScalar
>(-1);
295 for(
Index j = 0; j < cols(); ++j)
297 RealScalar absOnDiagonal = numext::abs(coeff(j,j));
298 if(absOnDiagonal > maxAbsOnDiagonal) maxAbsOnDiagonal = absOnDiagonal;
300 for(
Index j = 0; j < cols(); ++j)
301 for(
Index i = 0; i < j; ++i)
303 if(!internal::isMuchSmallerThan(coeff(i, j), maxAbsOnDiagonal, prec))
return false;
304 if(!internal::isMuchSmallerThan(coeff(j, i), maxAbsOnDiagonal, prec))
return false;
318 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
323 Index dstRows = src.rows();
324 Index dstCols = src.cols();
325 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
326 dst.resize(dstRows, dstCols);
329 dst.diagonal() = src.diagonal();
333 { dst.diagonal() += src.diagonal(); }
336 { dst.diagonal() -= src.diagonal(); }
343 #endif // EIGEN_DIAGONALMATRIX_H EIGEN_DEVICE_FUNC const DiagonalVectorType & diagonal() const
Definition: DiagonalMatrix.h:260
Definition: NonLinearOptimization.cpp:108
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:71
EIGEN_DEVICE_FUNC const DiagonalVectorType & diagonal() const
const version of diagonal().
Definition: DiagonalMatrix.h:136
Definition: AssignmentFunctors.h:67
const unsigned int LvalueBit
Means the expression has a coeffRef() method, i.e.
Definition: Constants.h:139
Represents a diagonal matrix with its storage.
Definition: DiagonalMatrix.h:116
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
EIGEN_DEVICE_FUNC DiagonalMatrix()
Default constructor without initialization.
Definition: DiagonalMatrix.h:143
EIGEN_DEVICE_FUNC DiagonalMatrix(const Scalar &x, const Scalar &y)
2D constructor.
Definition: DiagonalMatrix.h:151
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
Definition: Constants.h:512
Definition: XprHelper.h:89
Definition: CoreEvaluators.h:29
Definition: AssignmentFunctors.h:21
Definition: AssignEvaluator.h:753
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:28
EIGEN_DEVICE_FUNC DiagonalMatrix(Index dim)
Constructs a diagonal matrix with given dimension.
Definition: DiagonalMatrix.h:147
EIGEN_DEVICE_FUNC void setIdentity(Index size)
Sets this matrix to be the identity matrix of the given size.
Definition: DiagonalMatrix.h:208
Definition: Constants.h:515
EIGEN_DEVICE_FUNC DiagonalMatrix & operator=(const DiagonalMatrix &other)
This is a special case of the templated operator=.
Definition: DiagonalMatrix.h:187
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
bool isDiagonal(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: DiagonalMatrix.h:291
EIGEN_DEVICE_FUNC DiagonalMatrix & operator=(const DiagonalBase< OtherDerived > &other)
Copy operator.
Definition: DiagonalMatrix.h:176
EIGEN_DEVICE_FUNC const DiagonalWrapper< const Derived > asDiagonal() const
Definition: DiagonalMatrix.h:277
EIGEN_DEVICE_FUNC void resize(Index size)
Resizes to given size.
Definition: DiagonalMatrix.h:196
Definition: BandTriangularSolver.h:13
EIGEN_DEVICE_FUNC DiagonalVectorType & diagonal()
Definition: DiagonalMatrix.h:139
Definition: DiagonalMatrix.h:313
Definition: AssignEvaluator.h:740
Definition: DiagonalMatrix.h:18
Expression of a diagonal matrix.
Definition: DiagonalMatrix.h:245
EIGEN_DEVICE_FUNC DiagonalMatrix(const Scalar &x, const Scalar &y, const Scalar &z)
3D constructor.
Definition: DiagonalMatrix.h:155
Definition: AssignmentFunctors.h:46
EIGEN_DEVICE_FUNC void setIdentity()
Sets this matrix to be the identity matrix of the current size.
Definition: DiagonalMatrix.h:205
EIGEN_DEVICE_FUNC DiagonalMatrix(const MatrixBase< OtherDerived > &other)
generic constructor from expression of the diagonal coefficients
Definition: DiagonalMatrix.h:170
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
EIGEN_DEVICE_FUNC Index size() const
Definition: EigenBase.h:65
EIGEN_DEVICE_FUNC DiagonalMatrix(const DiagonalBase< OtherDerived > &other)
Copy constructor.
Definition: DiagonalMatrix.h:160
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:17
EIGEN_DEVICE_FUNC void setZero(Index size)
Resizes and sets all coefficients to zero.
Definition: DiagonalMatrix.h:202
EIGEN_DEVICE_FUNC DiagonalWrapper(DiagonalVectorType &a_diagonal)
Constructor from expression of diagonal coefficients to wrap.
Definition: DiagonalMatrix.h:256
DiagonalMatrix(const DiagonalMatrix &other)
copy constructor.
Definition: DiagonalMatrix.h:164
const unsigned int NoPreferredStorageOrderBit
for an expression, this means that the storage order can be either row-major or column-major.
Definition: Constants.h:173
EIGEN_DEVICE_FUNC void setZero()
Sets all coefficients to zero.
Definition: DiagonalMatrix.h:199