commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1145004 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/ main/java/org/apache/commons/math/random/ main/java/org/apache/commons/math/util/ site/xdoc/
Date Mon, 11 Jul 2011 01:14:55 GMT
Author: psteitz
Date: Mon Jul 11 01:14:55 2011
New Revision: 1145004

URL: http://svn.apache.org/viewvc?rev=1145004&view=rev
Log:
Improved efficiency in RandomDataImpl, LaguerreSolver, FastMath and
OutlineExtractor by moving conditional code into blocks where it is needed.

JIRA: MATH-609
Reported and patched by Dave Brosius

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java?rev=1145004&r1=1145003&r2=1145004&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
Mon Jul 11 01:14:55 2011
@@ -181,10 +181,12 @@ public class LaguerreSolver extends Abst
          * @return {@code true} if z is a real zero.
          */
         public boolean isRoot(double min, double max, Complex z) {
-            double tolerance = FastMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy());
-            return (isSequence(min, z.getReal(), max)) &&
-                (FastMath.abs(z.getImaginary()) <= tolerance ||
-                 z.abs() <= getFunctionValueAccuracy());
+            if (isSequence(min, z.getReal(), max)) {
+                double tolerance = FastMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy());
+                return ((FastMath.abs(z.getImaginary()) <= tolerance) ||
+                     (z.abs() <= getFunctionValueAccuracy()));
+            }
+            return false;
         }
 
         /**

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java?rev=1145004&r1=1145003&r2=1145004&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
Mon Jul 11 01:14:55 2011
@@ -404,10 +404,9 @@ public class RandomDataImpl implements R
             throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
         }
 
-        final RandomGenerator generator = getRan();
-
         final double pivot = 40.0d;
         if (mean < pivot) {
+            final RandomGenerator generator = getRan();
             double p = FastMath.exp(-mean);
             long n = 0;
             double r = 1.0d;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java?rev=1145004&r1=1145003&r2=1145004&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java Mon
Jul 11 01:14:55 2011
@@ -1489,8 +1489,6 @@ public class FastMath {
      * @return log(1 + x)
      */
     public static double log1p(final double x) {
-        double xpa = 1.0 + x;
-        double xpb = -(xpa - 1.0 - x);
 
         if (x == -1) {
             return x/0.0;   // -Infinity
@@ -1501,6 +1499,9 @@ public class FastMath {
         }
 
         if (x>1e-6 || x<-1e-6) {
+            double xpa = 1.0 + x;
+            double xpb = -(xpa - 1.0 - x);
+
             double hiPrec[] = new double[2];
 
             final double lores = log(xpa, hiPrec);

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1145004&r1=1145003&r2=1145004&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon Jul 11 01:14:55 2011
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="psteitz" type="update" issue="MATH-609" due-to="Dave Brosius">
+        Improved efficiency in RandomDataImpl, LaguerreSolver, FastMath and OutlineExtractor
by
+        moving conditional code into blocks where it is needed.
+      </action>
       <action dev="luc" type="fix" issue="MATH-603" due-to="Dennis Hendriks">
         Prevent step normalizer to output twice the last point in MULTIPLES mode.
       </action>



Mime
View raw message