You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2021/06/10 16:29:55 UTC

[commons-math] 01/02: Remove dependency "ComplexUtils" class.

This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit ca830af17040c243fb853ca47d507bd2e57d1cb6
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Thu Jun 10 18:24:53 2021 +0200

    Remove dependency "ComplexUtils" class.
    
    Class will not be released as of "Commons Numbers" v1.0 (cf. NUMBERS-25).
---
 .../legacy/analysis/solvers/LaguerreSolver.java    | 23 ++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java
index 0f8b4ad..008e25e 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/solvers/LaguerreSolver.java
@@ -17,7 +17,6 @@
 package org.apache.commons.math4.legacy.analysis.solvers;
 
 import org.apache.commons.numbers.complex.Complex;
-import org.apache.commons.numbers.complex.streams.ComplexUtils;
 import org.apache.commons.math4.legacy.analysis.polynomials.PolynomialFunction;
 import org.apache.commons.math4.legacy.exception.NoBracketingException;
 import org.apache.commons.math4.legacy.exception.NoDataException;
@@ -147,7 +146,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
      * @return the point at which the function value is zero.
      */
     private double laguerre(double lo, double hi) {
-        final Complex c[] = ComplexUtils.real2Complex(getCoefficients());
+        final Complex c[] = real2Complex(getCoefficients());
 
         final Complex initial = Complex.ofCartesian(0.5 * (lo + hi), 0);
         final Complex z = complexSolver.solve(c, initial);
@@ -193,7 +192,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
               Double.NEGATIVE_INFINITY,
               Double.POSITIVE_INFINITY,
               initial);
-        return complexSolver.solveAll(ComplexUtils.real2Complex(coefficients),
+        return complexSolver.solveAll(real2Complex(coefficients),
                                       Complex.ofCartesian(initial, 0d));
     }
 
@@ -223,7 +222,7 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
               Double.NEGATIVE_INFINITY,
               Double.POSITIVE_INFINITY,
               initial);
-        return complexSolver.solve(ComplexUtils.real2Complex(coefficients),
+        return complexSolver.solve(real2Complex(coefficients),
                                    Complex.ofCartesian(initial, 0d));
     }
 
@@ -381,4 +380,20 @@ public class LaguerreSolver extends AbstractPolynomialSolver {
             }
         }
     }
+
+    /**
+     * Converts a {@code double[]} array to a {@code Complex[]} array.
+     *
+     * @param real array of numbers to be converted to their {@code Complex} equivalent
+     * @return {@code Complex} array
+     */
+    private static Complex[] real2Complex(double[] real) {
+        int index = 0;
+        final Complex[] c = new Complex[real.length];
+        for (final double d : real) {
+            c[index] = Complex.ofCartesian(d, 0);
+            index++;
+        }
+        return c;
+    }
 }