11 #ifndef EIGEN_DIAGONALMATRIX_H
12 #define EIGEN_DIAGONALMATRIX_H
31 template<
typename Derived>
36 typedef typename DiagonalVectorType::Scalar
Scalar;
37 typedef typename DiagonalVectorType::RealScalar
RealScalar;
38 typedef typename internal::traits<Derived>::StorageKind
StorageKind;
39 typedef typename internal::traits<Derived>::StorageIndex
StorageIndex;
56 inline const Derived&
derived()
const {
return *
static_cast<const Derived*
>(
this); }
59 inline Derived&
derived() {
return *
static_cast<Derived*
>(
this); }
90 template<
typename MatrixDerived>
98 template <
typename OtherDerived>
103 template <
typename OtherDerived>
122 return (
diagonal() * scalar).asDiagonal();
131 return (scalar * other.
diagonal()).asDiagonal();
134 template <
typename OtherDerived>
139 template <
typename OtherDerived>
145 template <
typename OtherDerived>
150 template <
typename OtherDerived>
171 template<
typename Scalar_,
int SizeAtCompileTime,
int MaxSizeAtCompileTime>
172 struct traits<DiagonalMatrix<Scalar_,SizeAtCompileTime,MaxSizeAtCompileTime> >
173 : traits<Matrix<Scalar_,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
175 typedef Matrix<Scalar_,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType;
176 typedef DiagonalShape StorageKind;
182 template<
typename Scalar_,
int SizeAtCompileTime,
int MaxSizeAtCompileTime>
184 :
public DiagonalBase<DiagonalMatrix<Scalar_,SizeAtCompileTime,MaxSizeAtCompileTime> >
187 #ifndef EIGEN_PARSED_BY_DOXYGEN
188 typedef typename internal::traits<DiagonalMatrix>::DiagonalVectorType
DiagonalVectorType;
191 typedef typename internal::traits<DiagonalMatrix>::StorageKind
StorageKind;
192 typedef typename internal::traits<DiagonalMatrix>::StorageIndex
StorageIndex;
232 template <
typename... ArgTypes>
241 explicit EIGEN_STRONG_INLINE
DiagonalMatrix(
const std::initializer_list<std::initializer_list<Scalar>>& list)
249 template<
typename OtherDerived>
253 #ifndef EIGEN_PARSED_BY_DOXYGEN
259 template<
typename OtherDerived>
265 template<
typename OtherDerived>
273 #ifndef EIGEN_PARSED_BY_DOXYGEN
333 template<
typename DiagonalVectorType_>
334 struct traits<DiagonalWrapper<DiagonalVectorType_> >
336 typedef DiagonalVectorType_ DiagonalVectorType;
337 typedef typename DiagonalVectorType::Scalar Scalar;
338 typedef typename DiagonalVectorType::StorageIndex StorageIndex;
339 typedef DiagonalShape StorageKind;
340 typedef typename traits<DiagonalVectorType>::XprKind XprKind;
342 RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
343 ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
344 MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
345 MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime,
351 template<
typename DiagonalVectorType_>
353 :
public DiagonalBase<DiagonalWrapper<DiagonalVectorType_> >, internal::no_assignment_operator
356 #ifndef EIGEN_PARSED_BY_DOXYGEN
382 template<
typename Derived>
397 template<
typename Derived>
405 if(absOnDiagonal > maxAbsOnDiagonal) maxAbsOnDiagonal = absOnDiagonal;
420 struct Diagonal2Dense {};
422 template<>
struct AssignmentKind<DenseShape,DiagonalShape> {
typedef Diagonal2Dense Kind; };
425 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
426 struct Assignment<DstXprType, SrcXprType, Functor, Diagonal2Dense>
428 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &)
430 Index dstRows = src.rows();
431 Index dstCols = src.cols();
432 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
433 dst.resize(dstRows, dstCols);
436 dst.diagonal() = src.diagonal();
439 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::add_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &)
440 { dst.diagonal() += src.diagonal(); }
442 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::sub_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &)
443 { dst.diagonal() -= src.diagonal(); }
RowXpr row(Index i)
This is the const version of row(). */.
ColXpr col(Index i)
This is the const version of col().
#define EIGEN_CWISE_BINARY_RETURN_TYPE(LHS, RHS, OPNAME)
#define EIGEN_DEVICE_FUNC
#define EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(EXPR, SCALAR, OPNAME)
#define EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(SCALAR, EXPR, OPNAME)
NumTraits< Scalar >::Real RealScalar
Base class for diagonal matrices and expressions.
EIGEN_CONSTEXPR Index cols() const
internal::traits< Derived >::StorageIndex StorageIndex
internal::traits< Derived >::StorageKind StorageKind
DiagonalMatrix< Scalar, DiagonalVectorType::SizeAtCompileTime, DiagonalVectorType::MaxSizeAtCompileTime > PlainObject
const DiagonalProductReturnType< OtherDerived > operator*(const DiagonalBase< OtherDerived > &other) const
DiagonalVectorType::Scalar Scalar
internal::traits< Derived >::DiagonalVectorType DiagonalVectorType
const DiagonalDifferenceReturnType< OtherDerived > operator-(const DiagonalBase< OtherDerived > &other) const
friend const ScaleDiagonalReturnType operator*(const Scalar &scalar, const DiagonalBase &other)
const DiagonalVectorType & diagonal() const
DenseMatrixType toDenseMatrix() const
Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTime, 0, MaxRowsAtCompileTime, MaxColsAtCompileTime > DenseMatrixType
DiagonalVectorType & diagonal()
const Product< Derived, MatrixDerived, LazyProduct > operator*(const MatrixBase< MatrixDerived > &matrix) const
Scalar coeff(Index row, Index col) const
const DiagonalSumReturnType< OtherDerived > operator+(const DiagonalBase< OtherDerived > &other) const
const Derived & derived() const
const DiagonalInverseReturnType inverse() const
DiagonalVectorType::RealScalar RealScalar
EIGEN_CONSTEXPR Index rows() const
DenseMatrixType DenseType
const DiagonalScaleReturnType operator*(const Scalar &scalar) const
Represents a diagonal matrix with its storage.
static const InitializeReturnType Identity(Index size)
DiagonalVectorType & diagonal()
DiagonalWrapper< const CwiseNullaryOp< internal::scalar_constant_op< Scalar >, DiagonalVectorType > > InitializeReturnType
DiagonalMatrix(const Scalar &x, const Scalar &y)
static const InitializeReturnType Identity()
DiagonalMatrix(const Scalar &x, const Scalar &y, const Scalar &z)
DiagonalMatrix(DiagonalVectorType &&diag)
Constructs a DiagonalMatrix from an r-value diagonal vector type.
void setIdentity(Index size)
const DiagonalVectorType & diagonal() const
DiagonalMatrix(const DiagonalBase< OtherDerived > &other)
DiagonalMatrix(Index dim)
static const InitializeReturnType Zero()
DiagonalMatrix(const std::initializer_list< std::initializer_list< Scalar >> &list)
Constructs a DiagonalMatrix and initializes it by elements given by an initializer list of initialize...
static const InitializeReturnType Zero(Index size)
DiagonalMatrix(const MatrixBase< OtherDerived > &other)
DiagonalVectorType m_diagonal
DiagonalMatrix & operator=(const DiagonalBase< OtherDerived > &other)
DiagonalMatrix(const Scalar &a0, const Scalar &a1, const Scalar &a2, const ArgTypes &... args)
Construct a diagonal matrix with fixed size from an arbitrary number of coefficients.
Expression of a diagonal matrix.
DiagonalVectorType::Nested m_diagonal
const DiagonalVectorType & diagonal() const
DiagonalWrapper(DiagonalVectorType &a_diagonal)
Base class for all dense matrices, vectors, and expressions.
const DiagonalWrapper< const Derived > asDiagonal() const
bool isDiagonal(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
The matrix class, also used for vectors and row-vectors.
Expression of the product of two arbitrary matrices or vectors.
const unsigned int NoPreferredStorageOrderBit
const unsigned int LvalueBit
bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
EIGEN_ALWAYS_INLINE std::enable_if_t< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real > abs(const T &x)
const unsigned int NestByRefBit
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Eigen::Index Index
The interface type of indices.
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT