mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-03 02:30:38 +08:00
Finally fixed the matrix function/exponential warning.
Index fixes.
This commit is contained in:
parent
69b50047d6
commit
bb46a45340
@ -49,11 +49,12 @@ bool equalsIdentity(const MatrixType& A)
|
|||||||
template<typename VectorType>
|
template<typename VectorType>
|
||||||
void testVectorType(const VectorType& base)
|
void testVectorType(const VectorType& base)
|
||||||
{
|
{
|
||||||
|
typedef typename ei_traits<VectorType>::Index Index;
|
||||||
typedef typename ei_traits<VectorType>::Scalar Scalar;
|
typedef typename ei_traits<VectorType>::Scalar Scalar;
|
||||||
Scalar low = ei_random<Scalar>(-500,500);
|
Scalar low = ei_random<Scalar>(-500,500);
|
||||||
Scalar high = ei_random<Scalar>(-500,500);
|
Scalar high = ei_random<Scalar>(-500,500);
|
||||||
if (low>high) std::swap(low,high);
|
if (low>high) std::swap(low,high);
|
||||||
const int size = base.size();
|
const Index size = base.size();
|
||||||
const Scalar step = (high-low)/(size-1);
|
const Scalar step = (high-low)/(size-1);
|
||||||
|
|
||||||
// check whether the result yields what we expect it to do
|
// check whether the result yields what we expect it to do
|
||||||
|
@ -132,7 +132,7 @@ class MatrixExponential {
|
|||||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||||
|
|
||||||
/** \brief Reference to matrix whose exponential is to be computed. */
|
/** \brief Reference to matrix whose exponential is to be computed. */
|
||||||
const typename ei_nested<MatrixType>::type m_M;
|
typename ei_nested<MatrixType>::type m_M;
|
||||||
|
|
||||||
/** \brief Even-degree terms in numerator of Padé approximant. */
|
/** \brief Even-degree terms in numerator of Padé approximant. */
|
||||||
MatrixType m_U;
|
MatrixType m_U;
|
||||||
|
@ -117,7 +117,7 @@ class MatrixFunction<MatrixType, 0>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const typename ei_nested<MatrixType>::type m_A; /**< \brief Reference to argument of matrix function. */
|
typename ei_nested<MatrixType>::type m_A; /**< \brief Reference to argument of matrix function. */
|
||||||
StemFunction *m_f; /**< \brief Stem function for matrix function under consideration */
|
StemFunction *m_f; /**< \brief Stem function for matrix function under consideration */
|
||||||
|
|
||||||
MatrixFunction& operator=(const MatrixFunction&);
|
MatrixFunction& operator=(const MatrixFunction&);
|
||||||
@ -167,7 +167,7 @@ class MatrixFunction<MatrixType, 1>
|
|||||||
void computeOffDiagonal();
|
void computeOffDiagonal();
|
||||||
DynMatrixType solveTriangularSylvester(const DynMatrixType& A, const DynMatrixType& B, const DynMatrixType& C);
|
DynMatrixType solveTriangularSylvester(const DynMatrixType& A, const DynMatrixType& B, const DynMatrixType& C);
|
||||||
|
|
||||||
const typename ei_nested<MatrixType>::type m_A; /**< \brief Reference to argument of matrix function. */
|
typename ei_nested<MatrixType>::type m_A; /**< \brief Reference to argument of matrix function. */
|
||||||
StemFunction *m_f; /**< \brief Stem function for matrix function under consideration */
|
StemFunction *m_f; /**< \brief Stem function for matrix function under consideration */
|
||||||
MatrixType m_T; /**< \brief Triangular part of Schur decomposition */
|
MatrixType m_T; /**< \brief Triangular part of Schur decomposition */
|
||||||
MatrixType m_U; /**< \brief Unitary part of Schur decomposition */
|
MatrixType m_U; /**< \brief Unitary part of Schur decomposition */
|
||||||
@ -529,7 +529,7 @@ template<typename Derived> class MatrixFunctionReturnValue
|
|||||||
Index cols() const { return m_A.cols(); }
|
Index cols() const { return m_A.cols(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const typename ei_nested<Derived>::type m_A;
|
typename ei_nested<Derived>::type m_A;
|
||||||
StemFunction *m_f;
|
StemFunction *m_f;
|
||||||
|
|
||||||
MatrixFunctionReturnValue& operator=(const MatrixFunctionReturnValue&);
|
MatrixFunctionReturnValue& operator=(const MatrixFunctionReturnValue&);
|
||||||
|
@ -38,12 +38,13 @@ inline bool test_isApprox_abs(const Type1& a, const Type2& b)
|
|||||||
|
|
||||||
// Returns a matrix with eigenvalues clustered around 0, 1 and 2.
|
// Returns a matrix with eigenvalues clustered around 0, 1 and 2.
|
||||||
template<typename MatrixType>
|
template<typename MatrixType>
|
||||||
MatrixType randomMatrixWithRealEivals(const int size)
|
MatrixType randomMatrixWithRealEivals(const typename MatrixType::Index size)
|
||||||
{
|
{
|
||||||
|
typedef typename MatrixType::Index Index;
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
typedef typename MatrixType::RealScalar RealScalar;
|
typedef typename MatrixType::RealScalar RealScalar;
|
||||||
MatrixType diag = MatrixType::Zero(size, size);
|
MatrixType diag = MatrixType::Zero(size, size);
|
||||||
for (int i = 0; i < size; ++i) {
|
for (Index i = 0; i < size; ++i) {
|
||||||
diag(i, i) = Scalar(RealScalar(ei_random<int>(0,2)))
|
diag(i, i) = Scalar(RealScalar(ei_random<int>(0,2)))
|
||||||
+ ei_random<Scalar>() * Scalar(RealScalar(0.01));
|
+ ei_random<Scalar>() * Scalar(RealScalar(0.01));
|
||||||
}
|
}
|
||||||
@ -56,20 +57,21 @@ template <typename MatrixType, int IsComplex = NumTraits<typename ei_traits<Matr
|
|||||||
struct randomMatrixWithImagEivals
|
struct randomMatrixWithImagEivals
|
||||||
{
|
{
|
||||||
// Returns a matrix with eigenvalues clustered around 0 and +/- i.
|
// Returns a matrix with eigenvalues clustered around 0 and +/- i.
|
||||||
static MatrixType run(const int size);
|
static MatrixType run(const typename MatrixType::Index size);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Partial specialization for real matrices
|
// Partial specialization for real matrices
|
||||||
template<typename MatrixType>
|
template<typename MatrixType>
|
||||||
struct randomMatrixWithImagEivals<MatrixType, 0>
|
struct randomMatrixWithImagEivals<MatrixType, 0>
|
||||||
{
|
{
|
||||||
static MatrixType run(const int size)
|
static MatrixType run(const typename MatrixType::Index size)
|
||||||
{
|
{
|
||||||
|
typedef typename MatrixType::Index Index;
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
MatrixType diag = MatrixType::Zero(size, size);
|
MatrixType diag = MatrixType::Zero(size, size);
|
||||||
int i = 0;
|
Index i = 0;
|
||||||
while (i < size) {
|
while (i < size) {
|
||||||
int randomInt = ei_random<int>(-1, 1);
|
Index randomInt = ei_random<Index>(-1, 1);
|
||||||
if (randomInt == 0 || i == size-1) {
|
if (randomInt == 0 || i == size-1) {
|
||||||
diag(i, i) = ei_random<Scalar>() * Scalar(0.01);
|
diag(i, i) = ei_random<Scalar>() * Scalar(0.01);
|
||||||
++i;
|
++i;
|
||||||
@ -90,14 +92,14 @@ struct randomMatrixWithImagEivals<MatrixType, 0>
|
|||||||
template<typename MatrixType>
|
template<typename MatrixType>
|
||||||
struct randomMatrixWithImagEivals<MatrixType, 1>
|
struct randomMatrixWithImagEivals<MatrixType, 1>
|
||||||
{
|
{
|
||||||
static MatrixType run(const int size)
|
static MatrixType run(const typename MatrixType::Index size)
|
||||||
{
|
{
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
typedef typename MatrixType::RealScalar RealScalar;
|
typedef typename MatrixType::RealScalar RealScalar;
|
||||||
const Scalar imagUnit(0, 1);
|
const Scalar imagUnit(0, 1);
|
||||||
MatrixType diag = MatrixType::Zero(size, size);
|
MatrixType diag = MatrixType::Zero(size, size);
|
||||||
for (int i = 0; i < size; ++i) {
|
for (Index i = 0; i < size; ++i) {
|
||||||
diag(i, i) = Scalar(RealScalar(ei_random<int>(-1, 1))) * imagUnit
|
diag(i, i) = Scalar(RealScalar(ei_random<Index>(-1, 1))) * imagUnit
|
||||||
+ ei_random<Scalar>() * Scalar(RealScalar(0.01));
|
+ ei_random<Scalar>() * Scalar(RealScalar(0.01));
|
||||||
}
|
}
|
||||||
MatrixType A = MatrixType::Random(size, size);
|
MatrixType A = MatrixType::Random(size, size);
|
||||||
@ -163,8 +165,9 @@ void testMatrixType(const MatrixType& m)
|
|||||||
{
|
{
|
||||||
// Matrices with clustered eigenvalue lead to different code paths
|
// Matrices with clustered eigenvalue lead to different code paths
|
||||||
// in MatrixFunction.h and are thus useful for testing.
|
// in MatrixFunction.h and are thus useful for testing.
|
||||||
|
typedef typename MatrixType::Index Index;
|
||||||
|
|
||||||
const int size = m.rows();
|
const Index size = m.rows();
|
||||||
for (int i = 0; i < g_repeat; i++) {
|
for (int i = 0; i < g_repeat; i++) {
|
||||||
testMatrix(MatrixType::Random(size, size).eval());
|
testMatrix(MatrixType::Random(size, size).eval());
|
||||||
testMatrix(randomMatrixWithRealEivals<MatrixType>(size));
|
testMatrix(randomMatrixWithRealEivals<MatrixType>(size));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user