mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-10 18:59:01 +08:00
add DiagonalMatrix setZero and resize functions
This commit is contained in:
parent
666ade0c93
commit
e0be020622
@ -36,9 +36,9 @@ class DiagonalMatrixBase : ei_no_assignment_operator,
|
|||||||
typedef typename ei_traits<Derived>::Scalar Scalar;
|
typedef typename ei_traits<Derived>::Scalar Scalar;
|
||||||
typedef typename Base::PacketScalar PacketScalar;
|
typedef typename Base::PacketScalar PacketScalar;
|
||||||
using Base::derived;
|
using Base::derived;
|
||||||
|
typedef typename ei_cleantype<CoeffsVectorType>::type _CoeffsVectorType;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef typename ei_cleantype<CoeffsVectorType>::type _CoeffsVectorType;
|
|
||||||
|
|
||||||
// MSVC gets crazy if we define default parameters
|
// MSVC gets crazy if we define default parameters
|
||||||
template<typename OtherDerived, bool IsVector, bool IsDiagonal> struct construct_from_expression;
|
template<typename OtherDerived, bool IsVector, bool IsDiagonal> struct construct_from_expression;
|
||||||
@ -105,7 +105,7 @@ class DiagonalMatrixBase : ei_no_assignment_operator,
|
|||||||
return row == col ? m_coeffs.coeff(row) : static_cast<Scalar>(0);
|
return row == col ? m_coeffs.coeff(row) : static_cast<Scalar>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Scalar coeffRef(int row, int col) const
|
inline Scalar& coeffRef(int row, int col)
|
||||||
{
|
{
|
||||||
ei_assert(row==col);
|
ei_assert(row==col);
|
||||||
return m_coeffs.coeffRef(row);
|
return m_coeffs.coeffRef(row);
|
||||||
@ -196,6 +196,19 @@ class DiagonalMatrix
|
|||||||
m_coeffs = other.diagonal();
|
m_coeffs = other.diagonal();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void resize(int size)
|
||||||
|
{
|
||||||
|
m_coeffs.resize(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void resize(int rows, int cols)
|
||||||
|
{
|
||||||
|
ei_assert(rows==cols && "a diagonal matrix must be square");
|
||||||
|
m_coeffs.resize(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setZero() { m_coeffs.setZero(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \class DiagonalMatrixWrapper
|
/** \class DiagonalMatrixWrapper
|
||||||
|
Loading…
x
Reference in New Issue
Block a user