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/07/21 17:53:40 UTC

[commons-math] branch master updated (3ed7fab -> d0ed03c)

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 3ed7fab  Unused "import" statement.
     new 9e24ff7  Use static final int for IEEE exponent shift constant.
     new 11b0e96  Constant is an implementation detail.
     new d0ed03c  Use "final" (and other nits).

The 3 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:
 .../commons/math4/optim/linear/SimplexTableau.java | 39 ++++++++++++----------
 1 file changed, 22 insertions(+), 17 deletions(-)


[commons-math] 01/03: Use static final int for IEEE exponent shift constant.

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 9e24ff70a782eaa96c4f24e7058b2605958a73c9
Author: Mohammad Rezaei <mo...@rezaei.cc>
AuthorDate: Tue Jul 21 10:35:13 2020 -0400

    Use static final int for IEEE exponent shift constant.
    
    Closes #156.
---
 .../java/org/apache/commons/math4/optim/linear/SimplexTableau.java  | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java b/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java
index 9525f25..0913604 100644
--- a/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java
+++ b/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java
@@ -87,6 +87,8 @@ class SimplexTableau implements Serializable {
     private static final int MIN_IEEE_EXP = 0;
     /** IEEE exponent is kept in an offset form, 1023 is zero **/
     private static final int OFFSET_IEEE_EXP = 1023;
+    /** double exponent shift per IEEE standard **/
+    public static final int IEEE_EXPONENT_SHIFT = 52;
 
     /** Linear objective function. */
     private final LinearObjectiveFunction f;
@@ -421,7 +423,7 @@ class SimplexTableau implements Serializable {
      */
     private static int exponent(double d) {
         long bits = Double.doubleToLongBits(d);
-        return (int) ((bits & EXPN) >>> 52);
+        return (int) ((bits & EXPN) >>> IEEE_EXPONENT_SHIFT);
     }
 
     /**
@@ -436,7 +438,7 @@ class SimplexTableau implements Serializable {
             return d;
         }
         long bits = Double.doubleToLongBits(d);
-        return Double.longBitsToDouble((bits & FRAC) | ((((bits & EXPN) >>> 52) + exp) << 52));
+        return Double.longBitsToDouble((bits & FRAC) | ((((bits & EXPN) >>> IEEE_EXPONENT_SHIFT) + exp) << IEEE_EXPONENT_SHIFT));
     }
 
     /**


[commons-math] 03/03: Use "final" (and other nits).

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 d0ed03c953bf436fc4dc32260c6018a7791c9efc
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Tue Jul 21 19:52:04 2020 +0200

    Use "final" (and other nits).
---
 .../commons/math4/optim/linear/SimplexTableau.java | 33 ++++++++++++----------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java b/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java
index 38d81f5..e757679 100644
--- a/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java
+++ b/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java
@@ -274,8 +274,8 @@ class SimplexTableau implements Serializable {
         int slackVar = 0;
         int artificialVar = 0;
         for (int i = 0; i < constraints.size(); i++) {
-            LinearConstraint constraint = constraints.get(i);
-            int row = getNumObjectiveFunctions() + i;
+            final LinearConstraint constraint = constraints.get(i);
+            final int row = getNumObjectiveFunctions() + i;
 
             // decision variable coefficients
             copyArray(scaled[i + 1], matrix.getDataRef()[row]);
@@ -327,7 +327,7 @@ class SimplexTableau implements Serializable {
         for (int i = 0; i < scaled.length; i++) {
             int minExp = MAX_IEEE_EXP + 1;
             int maxExp = MIN_IEEE_EXP - 1;
-            for(double d: scaled[i]) {
+            for (double d: scaled[i]) {
                 if (d != 0) {
                     int e = exponent(d);
                     if (e < minExp) {
@@ -339,7 +339,7 @@ class SimplexTableau implements Serializable {
                 }
             }
             if (scaledRhs[i] != 0) {
-                int e = exponent(scaledRhs[i]);
+                final int e = exponent(scaledRhs[i]);
                 if (e < minExp) {
                     minExp = e;
                 }
@@ -347,7 +347,7 @@ class SimplexTableau implements Serializable {
                     maxExp = e;
                 }
             }
-            int expChange = computeExpChange(minExp, maxExp);
+            final int expChange = computeExpChange(minExp, maxExp);
             if (expChange != 0) {
                 scaledRhs[i] = updateExponent(scaledRhs[i], expChange);
                 updateExponent(scaled[i], expChange);
@@ -363,8 +363,8 @@ class SimplexTableau implements Serializable {
             int minExp = MAX_IEEE_EXP + 1;
             int maxExp = MIN_IEEE_EXP - 1;
 
-            for(double[] coefficients: scaled) {
-                double d = coefficients[i];
+            for (double[] coefficients : scaled) {
+                final double d = coefficients[i];
                 if (d != 0) {
                     int e = exponent(d);
                     if (e < minExp) {
@@ -375,10 +375,10 @@ class SimplexTableau implements Serializable {
                     }
                 }
             }
-            int expChange = computeExpChange(minExp, maxExp);
+            final int expChange = computeExpChange(minExp, maxExp);
             variableExpChange[i] = expChange;
             if (expChange != 0) {
-                for(double[] coefficients: scaled) {
+                for (double[] coefficients : scaled) {
                      coefficients[i] = updateExponent(coefficients[i], expChange);
                 }
             }
@@ -406,7 +406,8 @@ class SimplexTableau implements Serializable {
     }
 
     /**
-     * Change the exponent of every member of the array dar by the amount exp
+     * Changes the exponent of every member of the array by the given amount.
+     *
      * @param dar array of doubles to change
      * @param exp exponent value to change
      */
@@ -417,17 +418,19 @@ class SimplexTableau implements Serializable {
     }
 
     /**
-     * extract the exponent of a double
+     * Extract the exponent of a {@code double}.
+     *
      * @param d value to extract the exponent from
      * @return the IEEE exponent in the EXPN bits, as an integer
      */
     private static int exponent(double d) {
-        long bits = Double.doubleToLongBits(d);
+        final long bits = Double.doubleToLongBits(d);
         return (int) ((bits & EXPN) >>> IEEE_EXPONENT_SHIFT);
     }
 
     /**
-     * Change the exponent of the input d by the value exp
+     * Changes the exponent of a number by the given amount.
+     *
      * @param d value to change
      * @param exp exponent to add to the existing exponent (may be negative)
      * @return a double with the same sign/mantissa bits as d, but exponent changed by exp
@@ -437,7 +440,7 @@ class SimplexTableau implements Serializable {
             exp == 0) {
             return d;
         }
-        long bits = Double.doubleToLongBits(d);
+        final long bits = Double.doubleToLongBits(d);
         return Double.longBitsToDouble((bits & FRAC) | ((((bits & EXPN) >>> IEEE_EXPONENT_SHIFT) + exp) << IEEE_EXPONENT_SHIFT));
     }
 
@@ -447,7 +450,7 @@ class SimplexTableau implements Serializable {
      * @return new versions of the constraints
      */
     public List<LinearConstraint> normalizeConstraints(Collection<LinearConstraint> originalConstraints) {
-        List<LinearConstraint> normalized = new ArrayList<>(originalConstraints.size());
+        final List<LinearConstraint> normalized = new ArrayList<>(originalConstraints.size());
         for (LinearConstraint constraint : originalConstraints) {
             normalized.add(normalize(constraint));
         }


[commons-math] 02/03: Constant is an implementation detail.

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 11b0e96cf42b3918965189b2ca9a0de7b9756fe7
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Tue Jul 21 19:34:44 2020 +0200

    Constant is an implementation detail.
---
 src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java b/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java
index 0913604..38d81f5 100644
--- a/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java
+++ b/src/main/java/org/apache/commons/math4/optim/linear/SimplexTableau.java
@@ -88,7 +88,7 @@ class SimplexTableau implements Serializable {
     /** IEEE exponent is kept in an offset form, 1023 is zero **/
     private static final int OFFSET_IEEE_EXP = 1023;
     /** double exponent shift per IEEE standard **/
-    public static final int IEEE_EXPONENT_SHIFT = 52;
+    private static final int IEEE_EXPONENT_SHIFT = 52;
 
     /** Linear objective function. */
     private final LinearObjectiveFunction f;