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 2020/04/07 17:23:38 UTC

[commons-math] branch master updated (00f4de0 -> 7b00584)

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

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


    from 00f4de0  Track changes.
     new 8d36e18  Array declaration.
     new 54c4ee3  Redundant assignments.
     new 6a06f4f  Avoid multiple accesses to the same array's location.
     new 75d19f3  Formatting nit.
     new 9c6ed83  MATH-1530: Loop rewrite.
     new 7b00584  Fixed "CheckStyle" warnings.

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../BaseAbstractUnivariateIntegrator.java          |  5 +-
 .../analysis/interpolation/SplineInterpolator.java | 53 +++++++++++++---------
 .../analysis/polynomials/PolynomialsUtils.java     | 12 ++---
 3 files changed, 39 insertions(+), 31 deletions(-)


[commons-math] 04/06: Formatting nit.

Posted by er...@apache.org.
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 75d19f307733a42a99be411fc28f1a926c358ddf
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Mon Apr 6 13:37:04 2020 +0200

    Formatting nit.
---
 .../apache/commons/math4/analysis/interpolation/SplineInterpolator.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
index 22f4586..8da99b8 100644
--- a/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
@@ -106,7 +106,7 @@ public class SplineInterpolator implements UnivariateInterpolator {
         final double[] c = new double[n + 1];
         final double[] d = new double[n];
 
-        for (int j = n -1; j >=0; j--) {
+        for (int j = n - 1; j >= 0; j--) {
             final double cJp1 = c[j + 1];
             final double cJ = z[j] - mu[j] * cJp1;
             final double hJ = h[j];


[commons-math] 01/06: Array declaration.

Posted by er...@apache.org.
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 8d36e18b2107a579924dbfb68a15e6a8f1843e35
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Mon Apr 6 12:49:40 2020 +0200

    Array declaration.
---
 .../math4/analysis/interpolation/SplineInterpolator.java | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
index 9515dde..626d9ad 100644
--- a/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
@@ -82,13 +82,13 @@ public class SplineInterpolator implements UnivariateInterpolator {
         MathArrays.checkOrder(x);
 
         // Differences between knot points
-        final double h[] = new double[n];
+        final double[] h = new double[n];
         for (int i = 0; i < n; i++) {
             h[i] = x[i + 1] - x[i];
         }
 
-        final double mu[] = new double[n];
-        final double z[] = new double[n + 1];
+        final double[] mu = new double[n];
+        final double[] z = new double[n + 1];
         mu[0] = 0d;
         z[0] = 0d;
         double g = 0;
@@ -100,9 +100,9 @@ public class SplineInterpolator implements UnivariateInterpolator {
         }
 
         // cubic spline coefficients --  b is linear, c quadratic, d is cubic (original y's are constants)
-        final double b[] = new double[n];
-        final double c[] = new double[n + 1];
-        final double d[] = new double[n];
+        final double[] b = new double[n];
+        final double[] c = new double[n + 1];
+        final double[] d = new double[n];
 
         z[n] = 0d;
         c[n] = 0d;
@@ -113,8 +113,8 @@ public class SplineInterpolator implements UnivariateInterpolator {
             d[j] = (c[j + 1] - c[j]) / (3d * h[j]);
         }
 
-        final PolynomialFunction polynomials[] = new PolynomialFunction[n];
-        final double coefficients[] = new double[4];
+        final PolynomialFunction[] polynomials = new PolynomialFunction[n];
+        final double[] coefficients = new double[4];
         for (int i = 0; i < n; i++) {
             coefficients[0] = y[i];
             coefficients[1] = b[i];


[commons-math] 05/06: MATH-1530: Loop rewrite.

Posted by er...@apache.org.
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 9c6ed8311fcb30518cc8935146d72a5b9126d41c
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Mon Apr 6 19:06:12 2020 +0200

    MATH-1530: Loop rewrite.
---
 .../analysis/interpolation/SplineInterpolator.java | 25 ++++++++++++++--------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
index 8da99b8..b0c8c8b 100644
--- a/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
@@ -90,15 +90,22 @@ public class SplineInterpolator implements UnivariateInterpolator {
         final double[] mu = new double[n];
         final double[] z = new double[n + 1];
         double g = 0;
-        for (int i = 1; i < n; i++) {
-            final double xIp1 = x[i + 1];
-            final double xIm1 = x[i - 1];
-            final double hIm1 = h[i - 1];
-            final double hI = h[i];
-            g = 2d * (xIp1  - xIm1) - hIm1 * mu[i -1];
-            mu[i] = hI / g;
-            z[i] = (3d * (y[i + 1] * hIm1 - y[i] * (xIp1 - xIm1)+ y[i - 1] * hI) /
-                    (hIm1 * hI) - hIm1 * z[i - 1]) / g;
+        int indexM1 = 0;
+        int index = 1;
+        int indexP1 = 2;
+        while (index < n) {
+            final double xIp1 = x[indexP1];
+            final double xIm1 = x[indexM1];
+            final double hIm1 = h[indexM1];
+            final double hI = h[index];
+            g = 2d * (xIp1 - xIm1) - hIm1 * mu[indexM1];
+            mu[index] = hI / g;
+            z[index] = (3d * (y[indexP1] * hIm1 - y[index] * (xIp1 - xIm1)+ y[indexM1] * hI) /
+                        (hIm1 * hI) - hIm1 * z[indexM1]) / g;
+
+            indexM1 = index;
+            index = indexP1;
+            indexP1 = indexP1 + 1;
         }
 
         // cubic spline coefficients --  b is linear, c quadratic, d is cubic (original y's are constants)


[commons-math] 03/06: Avoid multiple accesses to the same array's location.

Posted by er...@apache.org.
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 6a06f4fdaac13ac1fff12fd4ac47539f9541193b
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Mon Apr 6 13:35:19 2020 +0200

    Avoid multiple accesses to the same array's location.
---
 .../analysis/interpolation/SplineInterpolator.java  | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
index 1b23bba..22f4586 100644
--- a/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
@@ -91,10 +91,14 @@ public class SplineInterpolator implements UnivariateInterpolator {
         final double[] z = new double[n + 1];
         double g = 0;
         for (int i = 1; i < n; i++) {
-            g = 2d * (x[i+1]  - x[i - 1]) - h[i - 1] * mu[i -1];
-            mu[i] = h[i] / g;
-            z[i] = (3d * (y[i + 1] * h[i - 1] - y[i] * (x[i + 1] - x[i - 1])+ y[i - 1] * h[i]) /
-                    (h[i - 1] * h[i]) - h[i - 1] * z[i - 1]) / g;
+            final double xIp1 = x[i + 1];
+            final double xIm1 = x[i - 1];
+            final double hIm1 = h[i - 1];
+            final double hI = h[i];
+            g = 2d * (xIp1  - xIm1) - hIm1 * mu[i -1];
+            mu[i] = hI / g;
+            z[i] = (3d * (y[i + 1] * hIm1 - y[i] * (xIp1 - xIm1)+ y[i - 1] * hI) /
+                    (hIm1 * hI) - hIm1 * z[i - 1]) / g;
         }
 
         // cubic spline coefficients --  b is linear, c quadratic, d is cubic (original y's are constants)
@@ -103,9 +107,12 @@ public class SplineInterpolator implements UnivariateInterpolator {
         final double[] d = new double[n];
 
         for (int j = n -1; j >=0; j--) {
-            c[j] = z[j] - mu[j] * c[j + 1];
-            b[j] = (y[j + 1] - y[j]) / h[j] - h[j] * (c[j + 1] + 2d * c[j]) / 3d;
-            d[j] = (c[j + 1] - c[j]) / (3d * h[j]);
+            final double cJp1 = c[j + 1];
+            final double cJ = z[j] - mu[j] * cJp1;
+            final double hJ = h[j];
+            b[j] = (y[j + 1] - y[j]) / hJ - hJ * (cJp1 + 2d * cJ) / 3d;
+            c[j] = cJ;
+            d[j] = (cJp1 - cJ) / (3d * hJ);
         }
 
         final PolynomialFunction[] polynomials = new PolynomialFunction[n];


[commons-math] 06/06: Fixed "CheckStyle" warnings.

Posted by er...@apache.org.
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 7b005845af41746e938b713b6fc8f45ff98a8e60
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Tue Apr 7 19:18:11 2020 +0200

    Fixed "CheckStyle" warnings.
---
 .../integration/BaseAbstractUnivariateIntegrator.java        |  5 ++---
 .../commons/math4/analysis/polynomials/PolynomialsUtils.java | 12 ++++++------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java b/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java
index fadb1d0..e9a4cb2 100644
--- a/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java
@@ -44,6 +44,8 @@ public abstract class BaseAbstractUnivariateIntegrator implements UnivariateInte
     /** Default maximal iteration count. */
     public static final int DEFAULT_MAX_ITERATIONS_COUNT = Integer.MAX_VALUE;
 
+    /** The iteration count. */
+    protected IntegerSequence.Incrementor iterations;
 
     /** Maximum absolute error. */
     private final double absoluteAccuracy;
@@ -56,9 +58,6 @@ public abstract class BaseAbstractUnivariateIntegrator implements UnivariateInte
     /** maximum number of iterations */
     private final int maximalIterationCount;
 
-    /** The iteration count. */
-    protected IntegerSequence.Incrementor iterations;
-
     /** The functions evaluation count. */
     private IntegerSequence.Incrementor evaluations;
 
diff --git a/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialsUtils.java b/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialsUtils.java
index 2076ef7..69b2900 100644
--- a/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialsUtils.java
+++ b/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialsUtils.java
@@ -32,9 +32,9 @@ import org.apache.commons.math4.util.FastMath;
  */
 public class PolynomialsUtils {
     /** -1 */
-    private static final BigFraction BF__MINUS_ONE = BigFraction.of(-1);
+    private static final BigFraction BF_MINUS_ONE = BigFraction.of(-1);
     /** 2 */
-    private static final BigFraction BF__TWO = BigFraction.of(2);
+    private static final BigFraction BF_TWO = BigFraction.of(2);
 
     /** Coefficients for Chebyshev polynomials. */
     private static final List<BigFraction> CHEBYSHEV_COEFFICIENTS;
@@ -65,14 +65,14 @@ public class PolynomialsUtils {
         HERMITE_COEFFICIENTS = new ArrayList<>();
         HERMITE_COEFFICIENTS.add(BigFraction.ONE);
         HERMITE_COEFFICIENTS.add(BigFraction.ZERO);
-        HERMITE_COEFFICIENTS.add(BF__TWO);
+        HERMITE_COEFFICIENTS.add(BF_TWO);
 
         // initialize recurrence for Laguerre polynomials
         // L0(X) = 1, L1(X) = 1 - 1 * X
         LAGUERRE_COEFFICIENTS = new ArrayList<>();
         LAGUERRE_COEFFICIENTS.add(BigFraction.ONE);
         LAGUERRE_COEFFICIENTS.add(BigFraction.ONE);
-        LAGUERRE_COEFFICIENTS.add(BF__MINUS_ONE);
+        LAGUERRE_COEFFICIENTS.add(BF_MINUS_ONE);
 
         // initialize recurrence for Legendre polynomials
         // P0(X) = 1, P1(X) = 0 + 1 * X
@@ -110,7 +110,7 @@ public class PolynomialsUtils {
         return buildPolynomial(degree, CHEBYSHEV_COEFFICIENTS,
                 new RecurrenceCoefficientsGenerator() {
             /** Fixed recurrence coefficients. */
-            private final BigFraction[] coeffs = { BigFraction.ZERO, BF__TWO, BigFraction.ONE };
+            private final BigFraction[] coeffs = { BigFraction.ZERO, BF_TWO, BigFraction.ONE };
             /** {@inheritDoc} */
             @Override
             public BigFraction[] generate(int k) {
@@ -142,7 +142,7 @@ public class PolynomialsUtils {
             public BigFraction[] generate(int k) {
                 return new BigFraction[] {
                         BigFraction.ZERO,
-                        BF__TWO,
+                        BF_TWO,
                         BigFraction.of(2 * k)};
             }
         });


[commons-math] 02/06: Redundant assignments.

Posted by er...@apache.org.
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 54c4ee34af4b366a898176190813152d446095e1
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Mon Apr 6 12:50:50 2020 +0200

    Redundant assignments.
---
 .../commons/math4/analysis/interpolation/SplineInterpolator.java     | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
index 626d9ad..1b23bba 100644
--- a/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java
@@ -89,8 +89,6 @@ public class SplineInterpolator implements UnivariateInterpolator {
 
         final double[] mu = new double[n];
         final double[] z = new double[n + 1];
-        mu[0] = 0d;
-        z[0] = 0d;
         double g = 0;
         for (int i = 1; i < n; i++) {
             g = 2d * (x[i+1]  - x[i - 1]) - h[i - 1] * mu[i -1];
@@ -104,9 +102,6 @@ public class SplineInterpolator implements UnivariateInterpolator {
         final double[] c = new double[n + 1];
         final double[] d = new double[n];
 
-        z[n] = 0d;
-        c[n] = 0d;
-
         for (int j = n -1; j >=0; j--) {
             c[j] = z[j] - mu[j] * c[j + 1];
             b[j] = (y[j + 1] - y[j]) / h[j] - h[j] * (c[j + 1] + 2d * c[j]) / 3d;