diff --git a/projects/Math/13/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java b/projects/Math/13/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java index 99d86e9..982e559 100644 --- a/projects/Math/13/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java +++ b/projects/Math/13/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java @@ -559,7 +559,16 @@ protected double[] computeResiduals(double[] objectiveValue) { * @return the square-root of the weight matrix. */ private RealMatrix squareRoot(RealMatrix m) { + if (m instanceof DiagonalMatrix) { + final int dim = m.getRowDimension(); + final RealMatrix sqrtM = new DiagonalMatrix(dim); + for (int i = 0; i < dim; i++) { + sqrtM.setEntry(i, i, FastMath.sqrt(m.getEntry(i, i))); + } + return sqrtM; + } else { final EigenDecomposition dec = new EigenDecomposition(m); return dec.getSquareRoot(); + } } }