From 350c477161a0d1df94efa02109ae07e6acbc527e Mon Sep 17 00:00:00 2001 From: Gilles Date: Tue, 12 Apr 2016 15:06:35 +0200 Subject: [PATCH] MATH-1355 Use "DiagonalMatrix" class. Thanks to Kazuhiro Koshino for the report. --- .../commons/math4/linear/MatrixUtils.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) 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 19ff724fa..86d74d6e2 100644 --- a/src/main/java/org/apache/commons/math4/linear/MatrixUtils.java +++ b/src/main/java/org/apache/commons/math4/linear/MatrixUtils.java @@ -204,19 +204,16 @@ public class MatrixUtils { } /** - * Returns a diagonal matrix with specified elements. + * Creates a diagonal matrix with the specified diagonal elements. + * + * @param diagonal Diagonal elements of the matrix. + * The array elements will be copied. + * @return a diagonal matrix instance. * - * @param diagonal diagonal elements of the matrix (the array elements - * will be copied) - * @return diagonal matrix * @since 2.0 */ - public static RealMatrix createRealDiagonalMatrix(final double[] diagonal) { - final RealMatrix m = createRealMatrix(diagonal.length, diagonal.length); - for (int i = 0; i < diagonal.length; ++i) { - m.setEntry(i, i, diagonal[i]); - } - return m; + public static DiagonalMatrix createRealDiagonalMatrix(final double[] diagonal) { + return new DiagonalMatrix(diagonal, true); } /**