commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1190665 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
Date Fri, 28 Oct 2011 23:12:58 GMT
Author: erans
Date: Fri Oct 28 23:12:58 2011
New Revision: 1190665

URL: http://svn.apache.org/viewvc?rev=1190665&view=rev
Log:
MATH-697
Added consistency check on array sizes.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java?rev=1190665&r1=1190664&r2=1190665&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
Fri Oct 28 23:12:58 2011
@@ -21,6 +21,7 @@ import org.apache.commons.math.util.Incr
 import org.apache.commons.math.exception.MaxCountExceededException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;
 import org.apache.commons.math.exception.NullArgumentException;
+import org.apache.commons.math.exception.DimensionMismatchException;
 import org.apache.commons.math.analysis.MultivariateRealFunction;
 import org.apache.commons.math.optimization.BaseMultivariateRealOptimizer;
 import org.apache.commons.math.optimization.GoalType;
@@ -122,6 +123,15 @@ public abstract class BaseAbstractScalar
         if (startPoint == null) {
             throw new NullArgumentException();
         }
+        final int dim = startPoint.length;
+        if (lower != null &&
+            lower.length != dim) {
+            throw new DimensionMismatchException(lower.length, dim);
+        }
+        if (upper != null &&
+            upper.length != dim) {
+            throw new DimensionMismatchException(upper.length, dim);
+        }
 
         // Reset.
         evaluations.setMaximalCount(maxEval);
@@ -131,7 +141,7 @@ public abstract class BaseAbstractScalar
         function = f;
         goal = goalType;
         start = startPoint.clone();
-        final int dim = startPoint.length;
+
         if (lower == null) {
             lowerBound = new double[dim];
             for (int i = 0; i < dim; i++) {



Mime
View raw message