Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 74ADC19D61 for ; Fri, 22 Apr 2016 01:39:42 +0000 (UTC) Received: (qmail 1114 invoked by uid 500); 22 Apr 2016 01:39:37 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 1033 invoked by uid 500); 22 Apr 2016 01:39:37 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 1018 invoked by uid 99); 22 Apr 2016 01:39:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Apr 2016 01:39:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 05E65E0103; Fri, 22 Apr 2016 01:39:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: erans@apache.org To: commits@commons.apache.org Date: Fri, 22 Apr 2016 01:39:37 -0000 Message-Id: <857d4cbedadc4b879487686ebe3cf568@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] [math] Fixed failing tests. 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 Authored: Fri Apr 22 03:33:53 2016 +0200 Committer: Gilles 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 the type of the field elements