commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1165809 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/integration/
Date Tue, 06 Sep 2011 20:00:38 GMT
Author: luc
Date: Tue Sep  6 20:00:37 2011
New Revision: 1165809

URL: http://svn.apache.org/viewvc?rev=1165809&view=rev
Log:
removed MathUserException from analysis package

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/BivariateRealFunction.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateMatrixFunction.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateRealFunction.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateVectorialFunction.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/TrivariateRealFunction.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateMatrixFunction.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateRealFunction.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateVectorialFunction.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/MonitoredFunction.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/SumSincFunction.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/BivariateRealFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/BivariateRealFunction.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/BivariateRealFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/BivariateRealFunction.java
Tue Sep  6 20:00:37 2011
@@ -17,8 +17,6 @@
 
 package org.apache.commons.math.analysis;
 
-import org.apache.commons.math.exception.MathUserException;
-
 /**
  * An interface representing a bivariate real function.
  *
@@ -32,9 +30,7 @@ public interface BivariateRealFunction {
      * @param x Abscissa for which the function value should be computed.
      * @param y Ordinate for which the function value should be computed.
      * @return the value.
-     * @throws MathUserException if the function evaluation fails.
      */
-    double value(double x, double y)
-        throws MathUserException;
+    double value(double x, double y);
 
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateMatrixFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateMatrixFunction.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateMatrixFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateMatrixFunction.java
Tue Sep  6 20:00:37 2011
@@ -17,9 +17,6 @@
 
 package org.apache.commons.math.analysis;
 
-import org.apache.commons.math.exception.MathUserException;
-
-
 /**
  * An interface representing a multivariate matrix function.
  * @version $Id$
@@ -31,10 +28,9 @@ public interface MultivariateMatrixFunct
      * Compute the value for the function at the given point.
      * @param point point at which the function must be evaluated
      * @return function value for the given point
-     * @exception MathUserException if the function evaluation fails
      * @exception IllegalArgumentException if points dimension is wrong
      */
     double[][] value(double[] point)
-        throws MathUserException, IllegalArgumentException;
+        throws IllegalArgumentException;
 
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateRealFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateRealFunction.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateRealFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateRealFunction.java
Tue Sep  6 20:00:37 2011
@@ -30,8 +30,6 @@ public interface MultivariateRealFunctio
      *
      * @param point Point at which the function must be evaluated.
      * @return the function value for the given point.
-     * @throws org.apache.commons.math.exception.MathUserException if
-     * the function evaluation fails.
      * @throws org.apache.commons.math.exception.DimensionMismatchException
      * if the parameter's dimension is wrong for the function being evaluated.
      * @throws  org.apache.commons.math.exception.MathIllegalArgumentException

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateVectorialFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateVectorialFunction.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateVectorialFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/MultivariateVectorialFunction.java
Tue Sep  6 20:00:37 2011
@@ -17,8 +17,6 @@
 
 package org.apache.commons.math.analysis;
 
-import org.apache.commons.math.exception.MathUserException;
-
 /**
  * An interface representing a multivariate vectorial function.
  * @version $Id$
@@ -30,10 +28,9 @@ public interface MultivariateVectorialFu
      * Compute the value for the function at the given point.
      * @param point point at which the function must be evaluated
      * @return function value for the given point
-     * @exception MathUserException if the function evaluation fails
      * @exception IllegalArgumentException if points dimension is wrong
      */
     double[] value(double[] point)
-        throws MathUserException, IllegalArgumentException;
+        throws IllegalArgumentException;
 
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/TrivariateRealFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/TrivariateRealFunction.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/TrivariateRealFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/TrivariateRealFunction.java
Tue Sep  6 20:00:37 2011
@@ -17,8 +17,6 @@
 
 package org.apache.commons.math.analysis;
 
-import org.apache.commons.math.exception.MathUserException;
-
 /**
  * An interface representing a trivariate real function.
  *
@@ -33,8 +31,6 @@ public interface TrivariateRealFunction 
      * @param y y-coordinate for which the function value should be computed.
      * @param z z-coordinate for which the function value should be computed.
      * @return the value.
-     * @throws MathUserException if the function evaluation fails.
      */
-    double value(double x, double y, double z)
-        throws MathUserException;
+    double value(double x, double y, double z);
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateMatrixFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateMatrixFunction.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateMatrixFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateMatrixFunction.java
Tue Sep  6 20:00:37 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.math.analysis;
 
-import org.apache.commons.math.exception.MathUserException;
-
 /**
  * An interface representing a univariate matrix function.
  *
@@ -30,8 +28,7 @@ public interface UnivariateMatrixFunctio
      * Compute the value for the function.
      * @param x the point for which the function value should be computed
      * @return the value
-     * @throws MathUserException if the function evaluation fails
      */
-    double[][] value(double x) throws MathUserException;
+    double[][] value(double x);
 
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateRealFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateRealFunction.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateRealFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateRealFunction.java
Tue Sep  6 20:00:37 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.math.analysis;
 
-import org.apache.commons.math.exception.MathUserException;
-
 /**
  * An interface representing a univariate real function.
  *
@@ -27,6 +25,52 @@ public interface UnivariateRealFunction 
     /**
      * Compute the value of the function.
      *
+     * <p>
+     * For user-defined functions, when the method encounters an error
+     * during evaluation, users must use their <em>own</em> unchecked exceptions.
+     * The following example shows the recommended way to do that, using root
+     * solving as the example (the same construct should be used for ODE
+     * integrators or for optimizations).
+     * </p>
+     * <pre>
+     * private static class LocalException extends RuntimeException {
+     *
+     *   // the x value that caused the problem
+     *   private final double x;
+     *
+     *   public LocalException(double x) {
+     *     this.x = x;
+     *   }
+     *
+     *   public double getX() {
+     *     return x;
+     *   }
+     *
+     * }
+     *
+     * private static class MyFunction implements UnivariateRealFunction {
+     *   public double value(double x) {
+     *     double y = hugeFormula(x);
+     *     if (somethingBadHappens) {
+     *       throw new LocalException(x);
+     *     }
+     *     return y;
+     *   }
+     * }
+     *
+     * public void compute() {
+     *   try {
+     *     solver.solve(maxEval, new MyFunction(a, b, c), min, max);
+     *   } catch (LocalException le) {
+     *     // retrieve the x value
+     *   }
+     * }
+     * </pre>
+     *
+     * <p>
+     * As shown in this example the exception is really something local to user code
+     * and there is a guarantee Apache Commons Math will not mess with it. The user is safe.
+     * </p>
      * @param x Point at which the function value should be computed.
      * @return the value.
      * @throws IllegalArgumentException when the activated method itself can
@@ -35,15 +79,6 @@ public interface UnivariateRealFunction 
      * majority of cases where Commons-Math throws IllegalArgumentException,
      * it is the result of argument checking of actual parameters immediately
      * passed to a method.
-     * @throws MathUserException when the method may encounter errors during evaluation.
-     * This should be thrown only in circumstances where, at the level of the
-     * activated function, IllegalArgumentException is not appropriate and it
-     * should indicate that while formal preconditions of the method have not
-     * been violated, an irrecoverable error has occurred evaluating a
-     * function at some (usually lower) level of the call stack.
-     * Convergence failures, runtime exceptions (even IllegalArgumentException)
-     * in user code or lower level methods can cause (and should be wrapped in)
-     * a MathUserException.
      */
-    double value(double x) throws MathUserException;
+    double value(double x);
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateVectorialFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateVectorialFunction.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateVectorialFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/UnivariateVectorialFunction.java
Tue Sep  6 20:00:37 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.math.analysis;
 
-import org.apache.commons.math.exception.MathUserException;
-
 /**
  * An interface representing a univariate vectorial function.
  *
@@ -30,8 +28,7 @@ public interface UnivariateVectorialFunc
      * Compute the value for the function.
      * @param x the point for which the function value should be computed
      * @return the value
-     * @throws MathUserException if the function evaluation fails
      */
-    double[] value(double x) throws MathUserException;
+    double[] value(double x);
 
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/MonitoredFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/MonitoredFunction.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/MonitoredFunction.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/MonitoredFunction.java
Tue Sep  6 20:00:37 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.math.analysis;
 
-import org.apache.commons.math.exception.MathUserException;
-
 /**
  * Wrapper class for counting functions calls.
  *
@@ -38,7 +36,7 @@ public class MonitoredFunction implement
         return callsCount;
     }
 
-    public double value(double x) throws MathUserException {
+    public double value(double x) {
         ++callsCount;
         return f.value(x);
     }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/SumSincFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/SumSincFunction.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/SumSincFunction.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/SumSincFunction.java
Tue Sep  6 20:00:37 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.math.analysis;
 
-import org.apache.commons.math.exception.MathUserException;
-
 /**
  * Auxiliary class for testing optimizers.
  *
@@ -43,7 +41,7 @@ public class SumSincFunction implements 
      * @param point Argument.
      * @return the value of this function at point {@code x}.
      */
-    public double value(double[] point) throws MathUserException {
+    public double value(double[] point) {
         double sum = 0;
         for (int i = 0, max = point.length; i < max; i++) {
             final double x = point[i];
@@ -58,7 +56,7 @@ public class SumSincFunction implements 
      */
     public MultivariateRealFunction partialDerivative(final int k) {
         return new MultivariateRealFunction() {
-            public double value(double[] point) throws MathUserException {
+            public double value(double[] point) {
                 return sincDeriv.value(point[k]);
             }
         };
@@ -69,8 +67,7 @@ public class SumSincFunction implements 
      */
     public MultivariateVectorialFunction gradient() {
         return new MultivariateVectorialFunction() {
-            public double[] value(double[] point)
-                throws MathUserException {
+            public double[] value(double[] point) {
                 final int n = point.length;
                 final double[] r = new double[n];
                 for (int i = 0; i < n; i++) {

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java?rev=1165809&r1=1165808&r2=1165809&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java
Tue Sep  6 20:00:37 2011
@@ -24,7 +24,6 @@ import org.apache.commons.math.analysis.
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
-import org.apache.commons.math.exception.MathUserException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;
 import org.apache.commons.math.util.FastMath;
 import org.junit.Assert;
@@ -78,7 +77,7 @@ public class LegendreGaussIntegratorTest
 
     @Test
     public void testExactIntegration()
-        throws ConvergenceException, MathUserException {
+        throws ConvergenceException {
         Random random = new Random(86343623467878363l);
         for (int n = 2; n < 6; ++n) {
             LegendreGaussIntegrator integrator =



Mime
View raw message