Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,26 @@ public void CanSolveForRandomMatrixAndSymmetricMatrixWhenResultMatrixGiven([Valu
AssertHelpers.AlmostEqual(ACopy, A, 14);
AssertHelpers.AlmostEqual(BCopy, B, 14);
}

/// <summary>
/// Factorizing a defective matrix with a repeated eigenvalue throws
/// NonConvergenceException instead of looping forever (see issue #11).
/// This exercises the managed provider path used by DenseMatrix.Evd().
/// </summary>
[Test]
public void DefectiveMatrixThrowsNonConvergenceException()
{
// Lower-triangular with a single eigenvalue (0.9275488) of algebraic
// multiplicity 3 - a defective (non-diagonalizable) matrix that the
// non-symmetric complex QR iteration cannot converge on.
var matrix = Matrix<Complex>.Build.DenseOfArray(new[,]
{
{ new Complex(0.9275488, 0), Complex.Zero, Complex.Zero },
{ new Complex(-0.9275488, 0), new Complex(0.9275488, 0), Complex.Zero },
{ Complex.Zero, new Complex(-0.9275488, 0), new Complex(0.9275488, 0) }
});

Assert.Throws<NonConvergenceException>(() => matrix.Evd());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,25 @@ public void CanSolveForRandomMatrixAndSymmetricMatrixWhenResultMatrixGiven([Valu
AssertHelpers.AlmostEqual(ACopy, A, 14);
AssertHelpers.AlmostEqual(BCopy, B, 14);
}

/// <summary>
/// Factorizing a defective matrix with a repeated eigenvalue throws
/// NonConvergenceException instead of looping forever (see issue #11).
/// </summary>
[Test]
public void DefectiveMatrixThrowsNonConvergenceException()
{
// Lower-triangular with a single eigenvalue (0.9275488) of algebraic
// multiplicity 3 - a defective (non-diagonalizable) matrix that the
// non-symmetric complex QR iteration cannot converge on.
var matrixA = new UserDefinedMatrix(new[,]
{
{ new Complex(0.9275488, 0), Complex.Zero, Complex.Zero },
{ new Complex(-0.9275488, 0), new Complex(0.9275488, 0), Complex.Zero },
{ Complex.Zero, new Complex(-0.9275488, 0), new Complex(0.9275488, 0) }
});

Assert.Throws<NonConvergenceException>(() => matrixA.Evd());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,26 @@ public void CanSolveForRandomMatrixAndSymmetricMatrixWhenResultMatrixGiven([Valu
AssertHelpers.AlmostEqual(ACopy, A, 14);
AssertHelpers.AlmostEqual(BCopy, B, 14);
}

/// <summary>
/// Factorizing a defective matrix with a repeated eigenvalue throws
/// NonConvergenceException instead of looping forever (see issue #11).
/// This exercises the managed provider path used by DenseMatrix.Evd().
/// </summary>
[Test]
public void DefectiveMatrixThrowsNonConvergenceException()
{
// Lower-triangular with a single eigenvalue (0.9275488) of algebraic
// multiplicity 3 - a defective (non-diagonalizable) matrix that the
// non-symmetric complex QR iteration cannot converge on.
var matrix = Matrix<Complex32>.Build.DenseOfArray(new[,]
{
{ new Complex32(0.9275488f, 0f), Complex32.Zero, Complex32.Zero },
{ new Complex32(-0.9275488f, 0f), new Complex32(0.9275488f, 0f), Complex32.Zero },
{ Complex32.Zero, new Complex32(-0.9275488f, 0f), new Complex32(0.9275488f, 0f) }
});

Assert.Throws<NonConvergenceException>(() => matrix.Evd());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,25 @@ public void CanSolveForRandomMatrixAndSymmetricMatrixWhenResultMatrixGiven([Valu
AssertHelpers.AlmostEqual(ACopy, A, 14);
AssertHelpers.AlmostEqual(BCopy, B, 14);
}

/// <summary>
/// Factorizing a defective matrix with a repeated eigenvalue throws
/// NonConvergenceException instead of looping forever (see issue #11).
/// </summary>
[Test]
public void DefectiveMatrixThrowsNonConvergenceException()
{
// Lower-triangular with a single eigenvalue (0.9275488) of algebraic
// multiplicity 3 - a defective (non-diagonalizable) matrix that the
// non-symmetric complex QR iteration cannot converge on.
var matrixA = new UserDefinedMatrix(new[,]
{
{ new Complex32(0.9275488f, 0f), Complex32.Zero, Complex32.Zero },
{ new Complex32(-0.9275488f, 0f), new Complex32(0.9275488f, 0f), Complex32.Zero },
{ Complex32.Zero, new Complex32(-0.9275488f, 0f), new Complex32(0.9275488f, 0f) }
});

Assert.Throws<NonConvergenceException>(() => matrixA.Evd());
}
}
}
4 changes: 4 additions & 0 deletions src/Numerics/LinearAlgebra/Complex/Factorization/UserEvd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ static void NonsymmetricReduceHessenberToRealSchur(Matrix<Complex> eigenVectors,

exshift += s;
iter++;
if (iter >= 30*order)
{
throw new NonConvergenceException();
}

// Reduce to triangle (rows)
for (var i = l + 1; i <= n; i++)
Expand Down
4 changes: 4 additions & 0 deletions src/Numerics/LinearAlgebra/Complex32/Factorization/UserEvd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ static void NonsymmetricReduceHessenberToRealSchur(Matrix<Complex32> eigenVector

exshift += s;
iter++;
if (iter >= 30*order)
{
throw new NonConvergenceException();
}

// Reduce to triangle (rows)
for (var i = l + 1; i <= n; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3055,6 +3055,10 @@ internal static void NonsymmetricReduceHessenberToRealSchur(Complex[] vectorV, C

exshift += s;
iter++;
if (iter >= 30*order)
{
throw new NonConvergenceException();
}

// Reduce to triangle (rows)
for (var i = l + 1; i <= n; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3057,6 +3057,10 @@ internal static void NonsymmetricReduceHessenberToRealSchur(Complex32[] vectorV,

exshift += s;
iter++;
if (iter >= 30*order)
{
throw new NonConvergenceException();
}

// Reduce to triangle (rows)
for (var i = l + 1; i <= n; i++)
Expand Down