26 #ifndef EIGEN_DIAGONALMATRIX_H
27 #define EIGEN_DIAGONALMATRIX_H
31 #ifndef EIGEN_PARSED_BY_DOXYGEN
32 template<
typename Derived>
36 typedef typename internal::traits<Derived>::DiagonalVectorType DiagonalVectorType;
37 typedef typename DiagonalVectorType::Scalar Scalar;
38 typedef typename internal::traits<Derived>::StorageKind StorageKind;
39 typedef typename internal::traits<Derived>::Index Index;
42 RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
43 ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
44 MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
45 MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
46 IsVectorAtCompileTime = 0,
50 typedef Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, 0, MaxRowsAtCompileTime, MaxColsAtCompileTime> DenseMatrixType;
51 typedef DenseMatrixType DenseType;
52 typedef DiagonalMatrix<Scalar,DiagonalVectorType::SizeAtCompileTime,DiagonalVectorType::MaxSizeAtCompileTime> PlainObject;
54 inline const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
55 inline Derived& derived() {
return *
static_cast<Derived*
>(
this); }
57 DenseMatrixType toDenseMatrix()
const {
return derived(); }
58 template<
typename DenseDerived>
59 void evalTo(MatrixBase<DenseDerived> &other)
const;
60 template<
typename DenseDerived>
61 void addTo(MatrixBase<DenseDerived> &other)
const
62 { other.diagonal() += diagonal(); }
63 template<
typename DenseDerived>
64 void subTo(MatrixBase<DenseDerived> &other)
const
65 { other.diagonal() -= diagonal(); }
67 inline const DiagonalVectorType& diagonal()
const {
return derived().diagonal(); }
68 inline DiagonalVectorType& diagonal() {
return derived().diagonal(); }
70 inline Index rows()
const {
return diagonal().size(); }
71 inline Index cols()
const {
return diagonal().size(); }
73 template<
typename MatrixDerived>
74 const DiagonalProduct<MatrixDerived, Derived, OnTheLeft>
75 operator*(
const MatrixBase<MatrixDerived> &matrix)
const;
77 inline const DiagonalWrapper<const CwiseUnaryOp<internal::scalar_inverse_op<Scalar>,
const DiagonalVectorType> >
80 return diagonal().cwiseInverse();
84 template<
typename OtherDerived>
87 return diagonal().isApprox(other.diagonal(), precision);
89 template<
typename OtherDerived>
92 return toDenseMatrix().isApprox(other, precision);
97 template<
typename Derived>
98 template<
typename DenseDerived>
102 other.diagonal() = diagonal();
120 template<
typename _Scalar,
int SizeAtCompileTime,
int MaxSizeAtCompileTime>
121 struct traits<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime> >
122 :
traits<Matrix<_Scalar,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
124 typedef Matrix<_Scalar,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType;
125 typedef Dense StorageKind;
132 template<
typename _Scalar,
int SizeAtCompileTime,
int MaxSizeAtCompileTime>
134 :
public DiagonalBase<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime> >
137 #ifndef EIGEN_PARSED_BY_DOXYGEN
138 typedef typename internal::traits<DiagonalMatrix>::DiagonalVectorType DiagonalVectorType;
140 typedef _Scalar Scalar;
141 typedef typename internal::traits<DiagonalMatrix>::StorageKind StorageKind;
142 typedef typename internal::traits<DiagonalMatrix>::Index Index;
169 template<
typename OtherDerived>
172 #ifndef EIGEN_PARSED_BY_DOXYGEN
178 template<
typename OtherDerived>
183 template<
typename OtherDerived>
190 #ifndef EIGEN_PARSED_BY_DOXYGEN
228 template<
typename _DiagonalVectorType>
229 struct traits<DiagonalWrapper<_DiagonalVectorType> >
231 typedef _DiagonalVectorType DiagonalVectorType;
232 typedef typename DiagonalVectorType::Scalar Scalar;
233 typedef typename DiagonalVectorType::Index Index;
234 typedef typename DiagonalVectorType::StorageKind StorageKind;
236 RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
237 ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
238 MaxRowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
239 MaxColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
245 template<
typename _DiagonalVectorType>
247 :
public DiagonalBase<DiagonalWrapper<_DiagonalVectorType> >, internal::no_assignment_operator
250 #ifndef EIGEN_PARSED_BY_DOXYGEN
251 typedef _DiagonalVectorType DiagonalVectorType;
274 template<
typename Derived>
289 template<
typename Derived>
292 if(cols() != rows())
return false;
294 for(
Index j = 0; j < cols(); ++j)
297 if(absOnDiagonal > maxAbsOnDiagonal) maxAbsOnDiagonal = absOnDiagonal;
299 for(
Index j = 0; j < cols(); ++j)
300 for(
Index i = 0; i < j; ++i)
310 #endif // EIGEN_DIAGONALMATRIX_H