Fixed failing tests.
Source of failure was MATH-1355: "EigenDecomposition" was assuming that a diagonal matrix could be made non-diagonal. Added a utility method that creates a dense matrix from an array specifying its diagonal elements.
This commit is contained in:
parent
84143c4629
commit
f16d5b1722
|
@ -189,7 +189,7 @@ public class EigenDecomposition {
|
||||||
|
|
||||||
if (cachedD == null) {
|
if (cachedD == null) {
|
||||||
// cache the matrix for subsequent calls
|
// cache the matrix for subsequent calls
|
||||||
cachedD = MatrixUtils.createRealDiagonalMatrix(realEigenvalues);
|
cachedD = MatrixUtils.createRealMatrixWithDiagonal(realEigenvalues);
|
||||||
|
|
||||||
for (int i = 0; i < imagEigenvalues.length; i++) {
|
for (int i = 0; i < imagEigenvalues.length; i++) {
|
||||||
if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) > 0) {
|
if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) > 0) {
|
||||||
|
|
|
@ -210,12 +210,31 @@ public class MatrixUtils {
|
||||||
* The array elements will be copied.
|
* The array elements will be copied.
|
||||||
* @return a diagonal matrix instance.
|
* @return a diagonal matrix instance.
|
||||||
*
|
*
|
||||||
|
* @see #createRealMatrixWithDiagonal(double[])
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public static DiagonalMatrix createRealDiagonalMatrix(final double[] diagonal) {
|
public static DiagonalMatrix createRealDiagonalMatrix(final double[] diagonal) {
|
||||||
return new DiagonalMatrix(diagonal, true);
|
return new DiagonalMatrix(diagonal, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a dense matrix with the specified diagonal elements.
|
||||||
|
*
|
||||||
|
* @param diagonal Diagonal elements of the matrix.
|
||||||
|
* @return a matrix instance.
|
||||||
|
*
|
||||||
|
* @see #createRealDiagonalMatrix(double[])
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public static RealMatrix createRealMatrixWithDiagonal(final double[] diagonal) {
|
||||||
|
final int size = diagonal.length;
|
||||||
|
final RealMatrix m = createRealMatrix(size, size);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
m.setEntry(i, i, diagonal[i]);
|
||||||
|
}
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a diagonal matrix with specified elements.
|
* Returns a diagonal matrix with specified elements.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue