commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [2/2] [math] Fixed failing tests.
Date Fri, 22 Apr 2016 01:39:37 GMT
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.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/f16d5b17
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/f16d5b17
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/f16d5b17

Branch: refs/heads/develop
Commit: f16d5b1722eb55c2d55eb623999f16799b088b98
Parents: 84143c4
Author: Gilles <erans@apache.org>
Authored: Fri Apr 22 03:33:53 2016 +0200
Committer: Gilles <erans@apache.org>
Committed: Fri Apr 22 03:33:53 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/linear/EigenDecomposition.java |  2 +-
 .../apache/commons/math4/linear/MatrixUtils.java | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/f16d5b17/src/main/java/org/apache/commons/math4/linear/EigenDecomposition.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/linear/EigenDecomposition.java b/src/main/java/org/apache/commons/math4/linear/EigenDecomposition.java
index aa92b5e..f9afeb7 100644
--- a/src/main/java/org/apache/commons/math4/linear/EigenDecomposition.java
+++ b/src/main/java/org/apache/commons/math4/linear/EigenDecomposition.java
@@ -189,7 +189,7 @@ public class EigenDecomposition {
 
         if (cachedD == null) {
             // cache the matrix for subsequent calls
-            cachedD = MatrixUtils.createRealDiagonalMatrix(realEigenvalues);
+            cachedD = MatrixUtils.createRealMatrixWithDiagonal(realEigenvalues);
 
             for (int i = 0; i < imagEigenvalues.length; i++) {
                 if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) > 0) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/f16d5b17/src/main/java/org/apache/commons/math4/linear/MatrixUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/linear/MatrixUtils.java b/src/main/java/org/apache/commons/math4/linear/MatrixUtils.java
index 86d74d6..7b41561 100644
--- a/src/main/java/org/apache/commons/math4/linear/MatrixUtils.java
+++ b/src/main/java/org/apache/commons/math4/linear/MatrixUtils.java
@@ -210,6 +210,7 @@ public class MatrixUtils {
      * The array elements will be copied.
      * @return a diagonal matrix instance.
      *
+     * @see #createRealMatrixWithDiagonal(double[])
      * @since 2.0
      */
     public static DiagonalMatrix createRealDiagonalMatrix(final double[] diagonal) {
@@ -217,6 +218,24 @@ public class MatrixUtils {
     }
 
     /**
+     * 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.
      *
      * @param <T> the type of the field elements


Mime
View raw message