commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1162629 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/linear/ main/java/org/apache/commons/math/optimization/linear/ test/java/org/apache/commons/math/analysis/solvers/ test/java/org/apache/commons/math/linear/
Date Mon, 29 Aug 2011 01:44:25 GMT
Author: erans
Date: Mon Aug 29 01:44:24 2011
New Revision: 1162629

URL: http://svn.apache.org/viewvc?rev=1162629&view=rev
Log:
MATH-653
"RealVector": Removed methods taking a "double[]" argument whenever another
exists that takes a "RealVector" argument.
Modified subclasses and unit tests accordingly.
Fixed a bug in method "subtract(RealVector)" (in class "RealVector").

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java?rev=1162629&r1=1162628&r2=1162629&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java Mon Aug 29 01:44:24 2011
@@ -47,9 +47,8 @@ public class ArrayRealVector extends Rea
      * Zero-length vectors may be used to initialized construction of vectors
      * by data gathering. We start with zero-length and use either the {@link
      * #ArrayRealVector(ArrayRealVector, ArrayRealVector)} constructor
-     * or one of the {@code append} method ({@link #append(double)}, {@link
-     * #append(double[])}, {@link #append(ArrayRealVector)}) to gather data
-     * into this vector.
+     * or one of the {@code append} method ({@link #append(double)},
+     * {@link #append(ArrayRealVector)}) to gather data into this vector.
      */
     public ArrayRealVector() {
         data = new double[0];
@@ -286,7 +285,7 @@ public class ArrayRealVector extends Rea
 
     /** {@inheritDoc} */
     @Override
-    public RealVector add(RealVector v) {
+    public ArrayRealVector add(RealVector v) {
         if (v instanceof ArrayRealVector) {
             return add(((ArrayRealVector) v).data);
         } else {
@@ -301,9 +300,16 @@ public class ArrayRealVector extends Rea
         }
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public RealVector add(double[] v) {
+    /**
+     * Compute the sum of this vector and {@code v}.
+     * Returns a new vector. Does not change instance data.
+     *
+     * @param v Vector to be added.
+     * @return {@code this} + {@code v}.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if {@code v} is not the same size as this vector.
+     */
+    public ArrayRealVector add(double[] v) {
         final int dim = v.length;
         checkVectorDimensions(dim);
         ArrayRealVector result = new ArrayRealVector(dim);
@@ -314,21 +320,9 @@ public class ArrayRealVector extends Rea
         return result;
     }
 
-    /**
-     * Add {@code v} to this vector.
-     *
-     * @param v Vector to be added
-     * @return {@code this} + v.
-     * @throws DimensionMismatchException if {@code v} is not the same
-     * size as this vector.
-     */
-    public ArrayRealVector add(ArrayRealVector v) {
-        return (ArrayRealVector) add(v.data);
-    }
-
     /** {@inheritDoc} */
     @Override
-    public RealVector subtract(RealVector v) {
+    public ArrayRealVector subtract(RealVector v) {
         if (v instanceof ArrayRealVector) {
             return subtract(((ArrayRealVector) v).data);
         } else {
@@ -343,9 +337,16 @@ public class ArrayRealVector extends Rea
         }
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public RealVector subtract(double[] v) {
+    /**
+     * Subtract {@code v} from this vector.
+     * Returns a new vector. Does not change instance data.
+     *
+     * @param v Vector to be subtracted.
+     * @return {@code this} - {@code v}.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if {@code v} is not the same size as this vector.
+     */
+    public ArrayRealVector subtract(double[] v) {
         final int dim = v.length;
         checkVectorDimensions(dim);
         ArrayRealVector result = new ArrayRealVector(dim);
@@ -356,18 +357,6 @@ public class ArrayRealVector extends Rea
         return result;
     }
 
-    /**
-     * Subtract {@code v} from this vector.
-     *
-     * @param v Vector to be subtracted.
-     * @return {@code this} - v.
-     * @throws DimensionMismatchException if {@code v} is not the
-     * same size as this vector.
-     */
-    public ArrayRealVector subtract(ArrayRealVector v) {
-        return (ArrayRealVector) subtract(v.data);
-    }
-
     /** {@inheritDoc} */
     @Override
     public ArrayRealVector map(UnivariateRealFunction function) {
@@ -420,7 +409,8 @@ public class ArrayRealVector extends Rea
     }
 
     /** {@inheritDoc} */
-    public RealVector ebeMultiply(RealVector v) {
+    @Override
+    public ArrayRealVector ebeMultiply(RealVector v) {
         if (v instanceof ArrayRealVector) {
             return ebeMultiply(((ArrayRealVector) v).data);
         } else {
@@ -433,9 +423,15 @@ public class ArrayRealVector extends Rea
         }
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public RealVector ebeMultiply(double[] v) {
+    /**
+     * Element-by-element multiplication.
+     *
+     * @param v Vector by which instance elements must be multiplied.
+     * @return a Vector containing {@code this[i] * v[i]} for all {@code i}.
+     * @throws DimensionMismatchException if {@code v} is not the same
+     * size as this vector.
+     */
+    public ArrayRealVector ebeMultiply(double[] v) {
         final int dim = v.length;
         checkVectorDimensions(dim);
         ArrayRealVector result = new ArrayRealVector(dim);
@@ -446,19 +442,8 @@ public class ArrayRealVector extends Rea
         return result;
     }
 
-    /**
-     * Element-by-element multiplication.
-     * @param v Vector by which instance elements must be multiplied.
-     * @return a Vector containing {@code this[i] * v[i]} for all {@code i}.
-     * @exception DimensionMismatchException if {@code v} is not the same
-     * size as this vector.
-     */
-    public ArrayRealVector ebeMultiply(ArrayRealVector v) {
-        return (ArrayRealVector) ebeMultiply(v.data);
-    }
-
     /** {@inheritDoc} */
-    public RealVector ebeDivide(RealVector v) {
+    public ArrayRealVector ebeDivide(RealVector v) {
         if (v instanceof ArrayRealVector) {
             return ebeDivide(((ArrayRealVector) v).data);
         } else {
@@ -471,19 +456,6 @@ public class ArrayRealVector extends Rea
         }
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public RealVector ebeDivide(double[] v) {
-        final int dim = v.length;
-        checkVectorDimensions(dim);
-        ArrayRealVector result = new ArrayRealVector(dim);
-        double[] resultData = result.data;
-        for (int i = 0; i < dim; i++) {
-            resultData[i] = data[i] / v[i];
-        }
-        return result;
-    }
-
     /**
      * Element-by-element division.
      *
@@ -492,8 +464,15 @@ public class ArrayRealVector extends Rea
      * @exception DimensionMismatchException if {@code v} is not the same
      * size as this vector.
      */
-    public ArrayRealVector ebeDivide(ArrayRealVector v) {
-        return (ArrayRealVector) ebeDivide(v.data);
+    public ArrayRealVector ebeDivide(double[] v) {
+        final int dim = v.length;
+        checkVectorDimensions(dim);
+        ArrayRealVector result = new ArrayRealVector(dim);
+        double[] resultData = result.data;
+        for (int i = 0; i < dim; i++) {
+            resultData[i] = data[i] / v[i];
+        }
+        return result;
     }
 
     /** {@inheritDoc} */
@@ -529,17 +508,6 @@ public class ArrayRealVector extends Rea
         }
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public double dotProduct(double[] v) {
-        checkVectorDimensions(v.length);
-        double dot = 0;
-        for (int i = 0; i < data.length; i++) {
-            dot += data[i] * v[i];
-        }
-        return dot;
-    }
-
     /**
      * Compute the dot product.
      *
@@ -548,8 +516,13 @@ public class ArrayRealVector extends Rea
      * @throws DimensionMismatchException if {@code v} is not the same
      * size as this vector.
      */
-    public double dotProduct(ArrayRealVector v) {
-        return dotProduct(v.data);
+    public double dotProduct(double[] v) {
+        checkVectorDimensions(v.length);
+        double dot = 0;
+        for (int i = 0; i < data.length; i++) {
+            dot += data[i] * v[i];
+        }
+        return dot;
     }
 
     /** {@inheritDoc} */
@@ -598,19 +571,7 @@ public class ArrayRealVector extends Rea
         }
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public double getDistance(double[] v) {
-        checkVectorDimensions(v.length);
-        double sum = 0;
-        for (int i = 0; i < data.length; ++i) {
-            final double delta = data[i] - v[i];
-            sum += delta * delta;
-        }
-        return FastMath.sqrt(sum);
-    }
-
-   /**
+    /**
      * Distance between two vectors.
      * This method computes the distance consistent with the
      * L<sub>2</sub> norm, i.e. the square root of the sum of
@@ -621,12 +582,16 @@ public class ArrayRealVector extends Rea
      * @throws DimensionMismatchException if {@code v} is not the same size as
      * this vector.
      * @see #getDistance(RealVector)
-     * @see #getL1Distance(ArrayRealVector)
-     * @see #getLInfDistance(ArrayRealVector)
      * @see #getNorm()
      */
-    public double getDistance(ArrayRealVector v) {
-        return getDistance(v.data);
+    public double getDistance(double[] v) {
+        checkVectorDimensions(v.length);
+        double sum = 0;
+        for (int i = 0; i < data.length; ++i) {
+            final double delta = data[i] - v[i];
+            sum += delta * delta;
+        }
+        return FastMath.sqrt(sum);
     }
 
     /** {@inheritDoc} */
@@ -645,18 +610,6 @@ public class ArrayRealVector extends Rea
         }
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public double getL1Distance(double[] v) {
-        checkVectorDimensions(v.length);
-        double sum = 0;
-        for (int i = 0; i < data.length; ++i) {
-            final double delta = data[i] - v[i];
-            sum += FastMath.abs(delta);
-        }
-        return sum;
-    }
-
     /**
      * Distance between two vectors.
      * This method computes the distance consistent with
@@ -668,12 +621,16 @@ public class ArrayRealVector extends Rea
      * @throws DimensionMismatchException if {@code v} is not the same size
      * as this vector.
      * @see #getDistance(RealVector)
-     * @see #getL1Distance(ArrayRealVector)
-     * @see #getLInfDistance(ArrayRealVector)
      * @see #getNorm()
      */
-    public double getL1Distance(ArrayRealVector v) {
-        return getL1Distance(v.data);
+    public double getL1Distance(double[] v) {
+        checkVectorDimensions(v.length);
+        double sum = 0;
+        for (int i = 0; i < data.length; ++i) {
+            final double delta = data[i] - v[i];
+            sum += FastMath.abs(delta);
+        }
+        return sum;
     }
 
     /** {@inheritDoc} */
@@ -692,18 +649,6 @@ public class ArrayRealVector extends Rea
         }
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public double getLInfDistance(double[] v) {
-        checkVectorDimensions(v.length);
-        double max = 0;
-        for (int i = 0; i < data.length; ++i) {
-            final double delta = data[i] - v[i];
-            max = FastMath.max(max, FastMath.abs(delta));
-        }
-        return max;
-    }
-
     /**
      * Distance between two vectors.
      * This method computes the distance consistent with
@@ -714,12 +659,16 @@ public class ArrayRealVector extends Rea
      * @return the distance between two vectors.
      * @exception IllegalArgumentException if {@code v} is not the same size as this
      * @see #getDistance(RealVector)
-     * @see #getL1Distance(ArrayRealVector)
-     * @see #getLInfDistance(ArrayRealVector)
      * @see #getNorm()
      */
-    public double getLInfDistance(ArrayRealVector v) {
-        return getLInfDistance(v.data);
+    public double getLInfDistance(double[] v) {
+        checkVectorDimensions(v.length);
+        double max = 0;
+        for (int i = 0; i < data.length; ++i) {
+            final double delta = data[i] - v[i];
+            max = FastMath.max(max, FastMath.abs(delta));
+        }
+        return max;
     }
 
     /** {@inheritDoc} */
@@ -749,24 +698,6 @@ public class ArrayRealVector extends Rea
 
     /** {@inheritDoc} */
     @Override
-    public RealVector projection(double[] v) {
-        return projection(new ArrayRealVector(v, false));
-    }
-
-    /**
-     * Find the orthogonal projection of this vector onto another vector.
-     *
-     * @param v Vector onto which instance must be projected.
-     * @return Projection of this instance onto {@code v}.
-     * @throws DimensionMismatchException if {@code v} is not the same size as
-     * this vector.
-     */
-    public ArrayRealVector projection(ArrayRealVector v) {
-        return (ArrayRealVector) v.mapMultiply(dotProduct(v) / v.dotProduct(v));
-    }
-
-    /** {@inheritDoc} */
-    @Override
     public RealMatrix outerProduct(RealVector v) {
         if (v instanceof ArrayRealVector) {
             return outerProduct(((ArrayRealVector) v).data);
@@ -790,12 +721,6 @@ public class ArrayRealVector extends Rea
      * @throws DimensionMismatchException if {@code v} is not the same
      * size as this vector.
      */
-    public RealMatrix outerProduct(ArrayRealVector v) {
-        return outerProduct(v.data);
-    }
-
-    /** {@inheritDoc} */
-    @Override
     public RealMatrix outerProduct(double[] v) {
         final int m = data.length;
         final int n = v.length;
@@ -846,11 +771,6 @@ public class ArrayRealVector extends Rea
     }
 
     /** {@inheritDoc} */
-    public RealVector append(double[] in) {
-        return new ArrayRealVector(this, in);
-    }
-
-    /** {@inheritDoc} */
     public RealVector getSubVector(int index, int n) {
         ArrayRealVector out = new ArrayRealVector(n);
         try {
@@ -874,28 +794,17 @@ public class ArrayRealVector extends Rea
     /** {@inheritDoc} */
     @Override
     public void setSubVector(int index, RealVector v) {
-        try {
+        if (v instanceof ArrayRealVector) {
+            setSubVector(index, ((ArrayRealVector) v).data);
+        } else {
             try {
-                set(index, (ArrayRealVector) v);
-            } catch (ClassCastException cce) {
                 for (int i = index; i < index + v.getDimension(); ++i) {
                     data[i] = v.getEntry(i - index);
                 }
+            } catch (IndexOutOfBoundsException e) {
+                checkIndex(index);
+                checkIndex(index + v.getDimension() - 1);
             }
-        } catch (IndexOutOfBoundsException e) {
-            checkIndex(index);
-            checkIndex(index + v.getDimension() - 1);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public void setSubVector(int index, double[] v) {
-        try {
-            System.arraycopy(v, 0, data, index, v.length);
-        } catch (IndexOutOfBoundsException e) {
-            checkIndex(index);
-            checkIndex(index + v.length - 1);
         }
     }
 
@@ -907,8 +816,13 @@ public class ArrayRealVector extends Rea
      * @throws org.apache.commons.math.exception.OutOfRangeException
      * if the index is inconsistent with the vector size.
      */
-    public void set(int index, ArrayRealVector v) {
-        setSubVector(index, v.data);
+    public void setSubVector(int index, double[] v) {
+        try {
+            System.arraycopy(v, 0, data, index, v.length);
+        } catch (IndexOutOfBoundsException e) {
+            checkIndex(index);
+            checkIndex(index + v.length - 1);
+        }
     }
 
     /** {@inheritDoc} */
@@ -1047,28 +961,25 @@ public class ArrayRealVector extends Rea
     }
 
     /**
-     * Returns the linear combination of {@code this} and {@code y}.
+     * Updates {@code this} with the linear combination of {@code this} and
+     * {@code y}.
      *
      * @param a Weight of {@code this}.
      * @param b Weight of {@code y}.
      * @param y Vector with which {@code this} is linearly combined.
-     * @return a vector containing {@code a * this[i] + b * y[i]} for all
-     * {@code i}.
+     * @return {@code this}, with components equal to
+     * {@code a * this[i] + b * y[i]} for all {@code i}.
      * @throws org.apache.commons.math.exception.DimensionMismatchException
      * if {@code y} is not the same size as this vector.
      */
-    public ArrayRealVector combine(double a, double b, ArrayRealVector y) {
-        return (ArrayRealVector) copy().combineToSelf(a, b, y.data);
+    public ArrayRealVector combine(double a, double b, double[] y) {
+        return copy().combineToSelf(a, b, y);
     }
 
     /** {@inheritDoc} */
     @Override
-    public RealVector combineToSelf(double a, double b, double[] y) {
-        checkVectorDimensions(y.length);
-        for (int i = 0; i < this.data.length; i++) {
-            data[i] = a * data[i] + b * y[i];
-        }
-        return this;
+    public ArrayRealVector combine(double a, double b, RealVector y) {
+        return copy().combineToSelf(a, b, y);
     }
 
     /**
@@ -1083,14 +994,17 @@ public class ArrayRealVector extends Rea
      * @throws org.apache.commons.math.exception.DimensionMismatchException
      * if {@code y} is not the same size as this vector.
      */
-    public ArrayRealVector combineToSelf(double a, double b, ArrayRealVector y) {
-        combineToSelf(a, b, y.data);
+    public ArrayRealVector combineToSelf(double a, double b, double[] y) {
+        checkVectorDimensions(y.length);
+        for (int i = 0; i < this.data.length; i++) {
+            data[i] = a * data[i] + b * y[i];
+        }
         return this;
     }
 
     /** {@inheritDoc} */
     @Override
-    public RealVector combineToSelf(double a, double b, RealVector y) {
+    public ArrayRealVector combineToSelf(double a, double b, RealVector y) {
         if (y instanceof ArrayRealVector) {
             return combineToSelf(a, b, ((ArrayRealVector) y).data);
         } else {

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java?rev=1162629&r1=1162628&r2=1162629&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/OpenMapRealVector.java Mon Aug 29 01:44:24 2011
@@ -48,9 +48,8 @@ public class OpenMapRealVector extends S
      * Zero-length vectors may be used to initialized construction of vectors
      * by data gathering. We start with zero-length and use either the {@link
      * #OpenMapRealVector(OpenMapRealVector, int)} constructor
-     * or one of the {@code append} method ({@link #append(double)}, {@link
-     * #append(double[])}, {@link #append(RealVector)}) to gather data
-     * into this vector.
+     * or one of the {@code append} method ({@link #append(double)},
+     * {@link #append(RealVector)}) to gather data into this vector.
      */
     public OpenMapRealVector() {
         this(0, DEFAULT_ZERO_TOLERANCE);
@@ -222,7 +221,7 @@ public class OpenMapRealVector extends S
 
     /** {@inheritDoc} */
     @Override
-        public RealVector add(RealVector v) {
+    public RealVector add(RealVector v) {
         checkVectorDimensions(v.getDimension());
         if (v instanceof OpenMapRealVector) {
             return add((OpenMapRealVector) v);
@@ -277,8 +276,13 @@ public class OpenMapRealVector extends S
     public OpenMapRealVector append(RealVector v) {
         if (v instanceof OpenMapRealVector) {
             return append((OpenMapRealVector) v);
+        } else {
+            final OpenMapRealVector res = new OpenMapRealVector(this, v.getDimension());
+            for (int i = 0; i < v.getDimension(); i++) {
+                res.setEntry(i + virtualSize, v.getEntry(i));
+            }
+            return res;
         }
-        return append(v.getData());
     }
 
     /** {@inheritDoc} */
@@ -288,15 +292,6 @@ public class OpenMapRealVector extends S
         return res;
     }
 
-    /** {@inheritDoc} */
-    public OpenMapRealVector append(double[] a) {
-        OpenMapRealVector res = new OpenMapRealVector(this, a.length);
-        for (int i = 0; i < a.length; i++) {
-            res.setEntry(i + virtualSize, a[i]);
-        }
-        return res;
-    }
-
     /**
      * {@inheritDoc}
      * @since 2.1
@@ -351,19 +346,6 @@ public class OpenMapRealVector extends S
     }
 
     /** {@inheritDoc} */
-    @Override
-    public OpenMapRealVector ebeDivide(double[] v) {
-        checkVectorDimensions(v.length);
-        OpenMapRealVector res = new OpenMapRealVector(this);
-        Iterator iter = entries.iterator();
-        while (iter.hasNext()) {
-            iter.advance();
-            res.setEntry(iter.key(), iter.value() / v[iter.key()]);
-        }
-        return res;
-    }
-
-    /** {@inheritDoc} */
     public OpenMapRealVector ebeMultiply(RealVector v) {
         checkVectorDimensions(v.getDimension());
         OpenMapRealVector res = new OpenMapRealVector(this);
@@ -376,19 +358,6 @@ public class OpenMapRealVector extends S
     }
 
     /** {@inheritDoc} */
-    @Override
-    public OpenMapRealVector ebeMultiply(double[] v) {
-        checkVectorDimensions(v.length);
-        OpenMapRealVector res = new OpenMapRealVector(this);
-        Iterator iter = entries.iterator();
-        while (iter.hasNext()) {
-            iter.advance();
-            res.setEntry(iter.key(), iter.value() * v[iter.key()]);
-        }
-        return res;
-    }
-
-    /** {@inheritDoc} */
     public OpenMapRealVector getSubVector(int index, int n) {
         checkIndex(index);
         checkIndex(index + n - 1);
@@ -458,20 +427,9 @@ public class OpenMapRealVector extends S
         checkVectorDimensions(v.getDimension());
         if (v instanceof OpenMapRealVector) {
             return getDistance((OpenMapRealVector) v);
+        } else {
+            return super.getDistance(v);
         }
-        return getDistance(v.getData());
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public double getDistance(double[] v) {
-        checkVectorDimensions(v.length);
-        double res = 0;
-        for (int i = 0; i < v.length; i++) {
-            double delta = entries.get(i) - v[i];
-            res += delta * delta;
-        }
-        return FastMath.sqrt(res);
     }
 
     /** {@inheritDoc} */
@@ -515,20 +473,9 @@ public class OpenMapRealVector extends S
         checkVectorDimensions(v.getDimension());
         if (v instanceof OpenMapRealVector) {
             return getL1Distance((OpenMapRealVector) v);
+        } else {
+            return super.getL1Distance(v);
         }
-        return getL1Distance(v.getData());
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public double getL1Distance(double[] v) {
-        checkVectorDimensions(v.length);
-        double max = 0;
-        for (int i = 0; i < v.length; i++) {
-            double delta = FastMath.abs(getEntry(i) - v[i]);
-            max += delta;
-        }
-        return max;
     }
 
     /**
@@ -566,22 +513,9 @@ public class OpenMapRealVector extends S
         checkVectorDimensions(v.getDimension());
         if (v instanceof OpenMapRealVector) {
             return getLInfDistance((OpenMapRealVector) v);
+        } else {
+            return super.getLInfDistance(v);
         }
-        return getLInfDistance(v.getData());
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public double getLInfDistance(double[] v) {
-        checkVectorDimensions(v.length);
-        double max = 0;
-        for (int i = 0; i < v.length; i++) {
-            double delta = FastMath.abs(getEntry(i) - v[i]);
-            if (delta > max) {
-                max = delta;
-            }
-        }
-        return max;
     }
 
     /** {@inheritDoc} */
@@ -628,23 +562,6 @@ public class OpenMapRealVector extends S
         return this;
     }
 
-     /** {@inheritDoc} */
-    @Override
-    public RealMatrix outerProduct(double[] v) {
-        final int n = v.length;
-        RealMatrix res = new OpenMapRealMatrix(virtualSize, n);
-        Iterator iter = entries.iterator();
-        while (iter.hasNext()) {
-            iter.advance();
-            int row = iter.key();
-            double value = iter.value();
-            for (int col = 0; col < n; col++) {
-                res.setEntry(row, col, value * v[col]);
-            }
-        }
-        return res;
-    }
-
     /** {@inheritDoc} */
     public RealVector projection(RealVector v) {
         checkVectorDimensions(v.getDimension());
@@ -652,13 +569,6 @@ public class OpenMapRealVector extends S
     }
 
     /** {@inheritDoc} */
-    @Override
-    public OpenMapRealVector projection(double[] v) {
-        checkVectorDimensions(v.length);
-        return (OpenMapRealVector) projection(new OpenMapRealVector(v));
-    }
-
-    /** {@inheritDoc} */
     public void setEntry(int index, double value) {
         checkIndex(index);
         if (!isDefaultValue(value)) {
@@ -673,16 +583,8 @@ public class OpenMapRealVector extends S
     public void setSubVector(int index, RealVector v) {
         checkIndex(index);
         checkIndex(index + v.getDimension() - 1);
-        setSubVector(index, v.getData());
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public void setSubVector(int index, double[] v) {
-        checkIndex(index);
-        checkIndex(index + v.length - 1);
-        for (int i = 0; i < v.length; i++) {
-            setEntry(i + index, v[i]);
+        for (int i = 0; i < v.getDimension(); i++) {
+            setEntry(i + index, v.getEntry(i));
         }
     }
 
@@ -720,30 +622,15 @@ public class OpenMapRealVector extends S
 
     /** {@inheritDoc} */
     @Override
-    public OpenMapRealVector subtract(RealVector v) {
+    public RealVector subtract(RealVector v) {
         checkVectorDimensions(v.getDimension());
         if (v instanceof OpenMapRealVector) {
             return subtract((OpenMapRealVector) v);
+        } else {
+            return super.subtract(v);
         }
-        return subtract(v.getData());
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public OpenMapRealVector subtract(double[] v) {
-        checkVectorDimensions(v.length);
-        OpenMapRealVector res = new OpenMapRealVector(this);
-        for (int i = 0; i < v.length; i++) {
-            if (entries.containsKey(i)) {
-                res.setEntry(i, entries.get(i) - v[i]);
-            } else {
-                res.setEntry(i, -v[i]);
-            }
-        }
-        return res;
     }
 
-
     /** {@inheritDoc} */
     @Override
     public OpenMapRealVector unitVector() {

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java?rev=1162629&r1=1162628&r2=1162629&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/RealVector.java Mon Aug 29 01:44:24 2011
@@ -102,14 +102,6 @@ public abstract class RealVector {
     public abstract RealVector append(double d);
 
     /**
-     * Construct a new vector by appending a double array to this vector.
-     *
-     * @param a double array to append.
-     * @return a new vector.
-     */
-    public abstract RealVector append(double[] a);
-
-    /**
      * Get a subvector from consecutive elements.
      *
      * @param index index of first element.
@@ -127,22 +119,10 @@ public abstract class RealVector {
      * @param v vector containing the values to set.
      * @throws org.apache.commons.math.exception.OutOfRangeException
      * if the index is not valid.
-     * @see #setSubVector(int, double[])
      */
     public abstract void setSubVector(int index, RealVector v);
 
     /**
-     * Set a sequence of consecutive elements.
-     *
-     * @param index index of first element to be set.
-     * @param v vector containing the values to set.
-     * @throws org.apache.commons.math.exception.OutOfRangeException
-     * if the index is not valid.
-     * @see #setSubVector(int, RealVector)
-     */
-    public abstract void setSubVector(int index, double[] v);
-
-    /**
      * Check whether any coordinate of this vector is {@code NaN}.
      *
      * @return {@code true} if any coordinate of this vector is {@code NaN},
@@ -206,30 +186,7 @@ public abstract class RealVector {
      * @throws org.apache.commons.math.exception.DimensionMismatchException
      * if {@code v} is not the same size as this vector.
      */
-    public RealVector add(double[] v) {
-        double[] result = v.clone();
-        Iterator<Entry> it = sparseIterator();
-        Entry e;
-        while (it.hasNext() && (e = it.next()) != null) {
-            result[e.getIndex()] += e.getValue();
-        }
-        return new ArrayRealVector(result, false);
-    }
-
-    /**
-     * Compute the sum of this vector and {@code v}.
-     * Returns a new vector. Does not change instance data.
-     *
-     * @param v Vector to be added.
-     * @return {@code this} + {@code v}.
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code v} is not the same size as this vector.
-     */
     public RealVector add(RealVector v) {
-        if (v instanceof ArrayRealVector) {
-            double[] values = ((ArrayRealVector)v).getDataRef();
-            return add(values);
-        }
         RealVector result = v.copy();
         Iterator<Entry> it = sparseIterator();
         Entry e;
@@ -249,37 +206,13 @@ public abstract class RealVector {
      * @throws org.apache.commons.math.exception.DimensionMismatchException
      * if {@code v} is not the same size as this vector.
      */
-    public RealVector subtract(double[] v) {
-        double[] result = v.clone();
-        Iterator<Entry> it = sparseIterator();
-        Entry e;
-        while (it.hasNext() && (e = it.next()) != null) {
-            final int index = e.getIndex();
-            result[index] = e.getValue() - result[index];
-        }
-        return new ArrayRealVector(result, false);
-    }
-
-    /**
-     * Subtract {@code v} from this vector.
-     * Returns a new vector. Does not change instance data.
-     *
-     * @param v Vector to be subtracted.
-     * @return {@code this} - {@code v}.
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code v} is not the same size as this vector.
-     */
     public RealVector subtract(RealVector v) {
-        if (v instanceof ArrayRealVector) {
-            double[] values = ((ArrayRealVector)v).getDataRef();
-            return add(values);
-        }
         RealVector result = v.copy();
         Iterator<Entry> it = sparseIterator();
         Entry e;
         while (it.hasNext() && (e = it.next()) != null) {
             final int index = e.getIndex();
-            v.setEntry(index, e.getValue() - result.getEntry(index));
+            result.setEntry(index, e.getValue() - result.getEntry(index));
         }
         return result;
     }
@@ -317,19 +250,6 @@ public abstract class RealVector {
     public abstract RealVector copy();
 
     /**
-     * Compute the dot product of this vector with a vector built from the
-     * entries in {@code v}.
-     *
-     * @param v vector with which dot product should be computed
-     * @return the scalar dot product between instance and v
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code v} is not the same size as this vector.
-     */
-    public double dotProduct(double[] v) {
-        return dotProduct(new ArrayRealVector(v, false));
-    }
-
-    /**
      * Compute the dot product of this vector with {@code v}.
      *
      * @param v Vector with which dot product should be computed
@@ -367,17 +287,6 @@ public abstract class RealVector {
     }
 
     /**
-     * Computes the cosine of the angle between this vector and the
-     * vector whose components are given as argument.
-     *
-     * @param v Components of a vector.
-     * @return the cosine of the angle between this vector and {@code v}.
-     */
-    public double cosine(double[] v) {
-        return cosine(new ArrayRealVector(v, false));
-    }
-
-    /**
      * Element-by-element division.
      *
      * @param v Vector by which instance elements must be divided.
@@ -388,19 +297,6 @@ public abstract class RealVector {
     public abstract RealVector ebeDivide(RealVector v);
 
     /**
-     * Element-by-element division.
-     * Returns a new vector. Does not change instance data.
-     *
-     * @param v Vector by which instance elements must be divided
-     * @return a vector containing this[i] / v[i] for all i.
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code v} is not the same size as this vector.
-     */
-    public RealVector ebeDivide(double[] v) {
-        return ebeDivide(new ArrayRealVector(v, false));
-    }
-
-    /**
      * Element-by-element multiplication.
      *
      * @param v Vector by which instance elements must be multiplied
@@ -411,19 +307,6 @@ public abstract class RealVector {
     public abstract RealVector ebeMultiply(RealVector v);
 
     /**
-     * Element-by-element multiplication.
-     * Returns a new vector. Does not change instance data.
-     *
-     * @param v Vector by which instance elements must be multiplied
-     * @return a vector containing this[i] * v[i] for all i.
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code v} is not the same size as this vector.
-     */
-    public RealVector ebeMultiply(double[] v) {
-        return ebeMultiply(new ArrayRealVector(v, false));
-    }
-
-    /**
      * Distance between two vectors.
      * <p>This method computes the distance consistent with the
      * L<sub>2</sub> norm, i.e. the square root of the sum of
@@ -450,24 +333,6 @@ public abstract class RealVector {
     }
 
     /**
-     * Distance between two vectors.
-     * <p>This method computes the distance consistent with the
-     * L<sub>2</sub> norm, i.e. the square root of the sum of
-     * element differences, or Euclidian distance.</p>
-     *
-     * @param v Vector to which distance is requested.
-     * @return the distance between two vectors.
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code v} is not the same size as this vector.
-     * @see #getL1Distance(double[])
-     * @see #getLInfDistance(double[])
-     * @see #getNorm()
-     */
-    public double getDistance(double[] v) {
-        return getDistance(new ArrayRealVector(v,false));
-    }
-
-    /**
      * Returns the L<sub>2</sub> norm of the vector.
      * <p>The L<sub>2</sub> norm is the root of the sum of
      * the squared elements.</p>
@@ -538,9 +403,6 @@ public abstract class RealVector {
      * @return the distance between two vectors.
      * @throws org.apache.commons.math.exception.DimensionMismatchException
      * if {@code v} is not the same size as this vector.
-     * @see #getDistance(double[])
-     * @see #getLInfDistance(double[])
-     * @see #getL1Norm()
      */
     public double getL1Distance(RealVector v) {
         checkVectorDimensions(v);
@@ -556,31 +418,6 @@ public abstract class RealVector {
     /**
      * Distance between two vectors.
      * <p>This method computes the distance consistent with
-     * L<sub>1</sub> norm, i.e. the sum of the absolute values of
-     * element differences.</p>
-     *
-     * @param v Vector to which distance is requested.
-     * @return the distance between two vectors.
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code v} is not the same size as this vector.
-     * @see #getDistance(double[])
-     * @see #getLInfDistance(double[])
-     * @see #getL1Norm()
-     */
-    public double getL1Distance(double[] v) {
-        checkVectorDimensions(v.length);
-        double d = 0;
-        Iterator<Entry> it = iterator();
-        Entry e;
-        while (it.hasNext() && (e = it.next()) != null) {
-            d += FastMath.abs(e.getValue() - v[e.getIndex()]);
-        }
-        return d;
-    }
-
-    /**
-     * Distance between two vectors.
-     * <p>This method computes the distance consistent with
      * L<sub>&infin;</sub> norm, i.e. the max of the absolute values of
      * element differences.</p>
      *
@@ -604,31 +441,6 @@ public abstract class RealVector {
     }
 
     /**
-     * Distance between two vectors.
-     * <p>This method computes the distance consistent with
-     * L<sub>&infin;</sub> norm, i.e. the max of the absolute values of
-     * elements differences.</p>
-     *
-     * @param v Vector to which distance is requested.
-     * @return Distance between two vectors.
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code v} is not the same size as this vector.
-     * @see #getDistance(double[])
-     * @see #getL1Distance(double[])
-     * @see #getLInfNorm()
-     */
-    public double getLInfDistance(double[] v) {
-        checkVectorDimensions(v.length);
-        double d = 0;
-        Iterator<Entry> it = iterator();
-        Entry e;
-        while (it.hasNext() && (e = it.next()) != null) {
-            d = FastMath.max(FastMath.abs(e.getValue() - v[e.getIndex()]), d);
-        }
-        return d;
-    }
-
-    /**
      * Get the index of the minimum entry.
      *
      * @return the index of the minimum entry or -1 if vector length is 0
@@ -788,16 +600,6 @@ public abstract class RealVector {
     }
 
     /**
-     * Compute the outer product.
-     *
-     * @param v Vector with which outer product should be computed
-     * @return the matrix outer product between instance and {@code v}.
-     */
-    public RealMatrix outerProduct(double[] v) {
-        return outerProduct(new ArrayRealVector(v, false));
-    }
-
-    /**
      * Find the orthogonal projection of this vector onto another vector.
      *
      * @param v vector onto which instance must be projected.
@@ -808,18 +610,6 @@ public abstract class RealVector {
     public abstract RealVector projection(RealVector v);
 
     /**
-     * Find the orthogonal projection of this vector onto another vector.
-     *
-     * @param v Vector onto which instance must be projected.
-     * @return the projection of the instance onto {@code v.}
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code v} is not the same size as this vector.
-     */
-    public RealVector projection(double[] v) {
-        return projection(new ArrayRealVector(v, false));
-    }
-
-    /**
      * Set all elements to a single value.
      *
      * @param value Single value to set for all elements.
@@ -833,11 +623,11 @@ public abstract class RealVector {
     }
 
     /**
-     * Convert the vector to a double array.
-     * <p>The array is independent from vector data, it's elements
-     * are copied.</p>
+     * Convert the vector to an array of {@code double}s.
+     * The array is independent from this vector data: the elements
+     * are copied.
      *
-     * @return an array containing a copy of vector elements.
+     * @return an array containing a copy of the vector elements.
      */
     public double[] toArray() {
         int dim = getDimension();
@@ -849,11 +639,11 @@ public abstract class RealVector {
     }
 
     /**
-     * Returns vector entries as a double array.
-     * <p>The array is independent from vector data, it's elements
-     * are copied.</p>
+     * Convert the vector to an array of {@code double}s.
+     * The array is independent from this vector data: the elements
+     * are copied.
      *
-     * @return a {@code double} array of entries.
+     * @return an array containing a copy of the vector elements.
      */
     public double[] getData() {
         return toArray();
@@ -973,24 +763,6 @@ public abstract class RealVector {
     }
 
     /**
-     * Returns a new vector representing {@code a*this + b*y}, the linear
-     * combination of {@code this} and a vector with components equal to the
-     * entries in {@code y}.
-     * Returns a new vector. Does not change instance data.
-     *
-     * @param a Coefficient of {@code this}.
-     * @param b Coefficient of {@code y}.
-     * @param y Vector with which {@code this} is linearly combined.
-     * @return a vector containing {@code a * this[i] + b * y[i]} for all
-     * {@code i}.
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code y} is not the same size as this vector.
-     */
-    public RealVector combine(double a, double b, double[] y) {
-        return copy().combineToSelf(a, b, y);
-    }
-
-    /**
      * Returns a new vector representing {@code a * this + b * y}, the linear
      * combination of {@code this} and {@code y}.
      * Returns a new vector. Does not change instance data.
@@ -1009,22 +781,6 @@ public abstract class RealVector {
 
     /**
      * Updates {@code this} with the linear combination of {@code this} and
-     * a vector with components equal to the entries of {@code y}.
-     *
-     * @param a Coefficient of {@code this}.
-     * @param b Coefficient of {@code y}.
-     * @param y Vector with which {@code this} is linearly combined.
-     * @return {@code this}, with components equal to
-     * {@code a * this[i] + b * y[i]} for all {@code i}.
-     * @throws org.apache.commons.math.exception.DimensionMismatchException
-     * if {@code y} is not the same size as this vector.
-     */
-    public RealVector combineToSelf(double a, double b, double[] y) {
-        return combineToSelf(a, b, new ArrayRealVector(y, false));
-    }
-
-    /**
-     * Updates {@code this} with the linear combination of {@code this} and
      * {@code y}.
      *
      * @param a Weight of {@code this}.
@@ -1195,6 +951,12 @@ public abstract class RealVector {
         return new RealVector() {
             /** {@inheritDoc} */
             @Override
+            public double[] getData() {
+                return v.getData();
+            }
+
+            /** {@inheritDoc} */
+            @Override
             public RealVector mapToSelf(UnivariateRealFunction function) {
                 throw new MathUnsupportedOperationException();
             }
@@ -1272,24 +1034,12 @@ public abstract class RealVector {
 
             /** {@inheritDoc} */
             @Override
-            public RealVector add(double[] w) {
-                return v.add(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public RealVector subtract(RealVector w) {
                 return v.subtract(w);
             }
 
             /** {@inheritDoc} */
             @Override
-            public RealVector subtract(double[] w) {
-                return v.subtract(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public RealVector mapAdd(double d) {
                 return v.mapAdd(d);
             }
@@ -1344,57 +1094,24 @@ public abstract class RealVector {
 
             /** {@inheritDoc} */
             @Override
-            public RealVector ebeMultiply(double[] w) {
-                return v.ebeMultiply(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public RealVector ebeDivide(RealVector w) {
                 return v.ebeDivide(w);
             }
 
             /** {@inheritDoc} */
             @Override
-            public RealVector ebeDivide(double[] w) {
-                return v.ebeDivide(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
-            public double[] getData() {
-                // TODO It is not specified in the javadoc that getData should
-                // return a
-                // deep copy
-                return v.getData();
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public double dotProduct(RealVector w) {
                 return v.dotProduct(w);
             }
 
             /** {@inheritDoc} */
             @Override
-            public double dotProduct(double[] w) {
-                return v.dotProduct(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public double cosine(RealVector w) {
                 return v.cosine(w);
             }
 
             /** {@inheritDoc} */
             @Override
-            public double cosine(double[] w) {
-                return v.cosine(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public double getNorm() {
                 return v.getNorm();
             }
@@ -1419,36 +1136,18 @@ public abstract class RealVector {
 
             /** {@inheritDoc} */
             @Override
-            public double getDistance(double[] w) {
-                return v.getDistance(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public double getL1Distance(RealVector w) {
                 return v.getL1Distance(w);
             }
 
             /** {@inheritDoc} */
             @Override
-            public double getL1Distance(double[] w) {
-                return v.getL1Distance(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public double getLInfDistance(RealVector w) {
                 return v.getLInfDistance(w);
             }
 
             /** {@inheritDoc} */
             @Override
-            public double getLInfDistance(double[] w) {
-                return v.getLInfDistance(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public RealVector unitVector() {
                 return v.unitVector();
             }
@@ -1467,24 +1166,12 @@ public abstract class RealVector {
 
             /** {@inheritDoc} */
             @Override
-            public RealVector projection(double[] w) {
-                return v.projection(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public RealMatrix outerProduct(RealVector w) {
                 return v.outerProduct(w);
             }
 
             /** {@inheritDoc} */
             @Override
-            public RealMatrix outerProduct(double[] w) {
-                return v.outerProduct(w);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public double getEntry(int index) {
                 return v.getEntry(index);
             }
@@ -1515,12 +1202,6 @@ public abstract class RealVector {
 
             /** {@inheritDoc} */
             @Override
-            public RealVector append(double[] a) {
-                return v.append(a);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public RealVector getSubVector(int index, int n) {
                 return v.getSubVector(index, n);
             }
@@ -1533,12 +1214,6 @@ public abstract class RealVector {
 
             /** {@inheritDoc} */
             @Override
-            public void setSubVector(int index, double[] w) {
-                throw new MathUnsupportedOperationException();
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public void set(double value) {
                 throw new MathUnsupportedOperationException();
             }
@@ -1563,24 +1238,12 @@ public abstract class RealVector {
 
             /** {@inheritDoc} */
             @Override
-            public RealVector combine(double a, double b, double[] y) {
-                return v.combine(a, b, y);
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public RealVector combine(double a, double b, RealVector y) {
                 return v.combine(a, b, y);
             }
 
             /** {@inheritDoc} */
             @Override
-            public RealVector combineToSelf(double a, double b, double[] y) {
-                throw new MathUnsupportedOperationException();
-            }
-
-            /** {@inheritDoc} */
-            @Override
             public RealVector combineToSelf(double a, double b, RealVector y) {
                 throw new MathUnsupportedOperationException();
             }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java?rev=1162629&r1=1162628&r2=1162629&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java Mon Aug 29 01:44:24 2011
@@ -89,7 +89,7 @@ public class LinearObjectiveFunction imp
      * @return value of the linear equation at the current point
      */
     public double getValue(final double[] point) {
-        return coefficients.dotProduct(point) + constantTerm;
+        return coefficients.dotProduct(new ArrayRealVector(point, false)) + constantTerm;
     }
 
     /**

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java?rev=1162629&r1=1162628&r2=1162629&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java Mon Aug 29 01:44:24 2011
@@ -50,6 +50,11 @@ public final class RegulaFalsiSolverTest
                 }
             };
 
+        final UnivariateRealSolver solverS = new SecantSolver();
+        final double rootS = solverS.solve(3624, f, 1, 10);
+        System.out.println("rootS=" + rootS + " n=" + solverS.getEvaluations());
+        Assert.assertEquals(3.4341896575, rootS, 1e-10);
+
         final UnivariateRealSolver solver = new RegulaFalsiSolver();
         final double root = solver.solve(3624, f, 1, 10);
         Assert.assertEquals(3.4341896575482003, root, 1e-15);

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java?rev=1162629&r1=1162628&r2=1162629&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/ArrayRealVectorTest.java Mon Aug 29 01:44:24 2011
@@ -486,10 +486,6 @@ public class ArrayRealVectorTest {
         Assert.assertEquals("testData len", 4, v_append_2.getDimension());
         Assert.assertEquals("testData is 2.0 ", 2.0, v_append_2.getEntry(3), 0);
 
-        RealVector v_append_3 = v1.append(vec2);
-        Assert.assertEquals("testData len", 6, v_append_3.getDimension());
-        Assert.assertEquals("testData is  ", 4.0, v_append_3.getEntry(3), 0);
-
         RealVector v_append_4 = v1.append(v2_t);
         Assert.assertEquals("testData len", 6, v_append_4.getDimension());
         Assert.assertEquals("testData is 4.0 ", 4.0, v_append_4.getEntry(3), 0);
@@ -532,17 +528,6 @@ public class ArrayRealVectorTest {
             // expected behavior
         }
 
-        ArrayRealVector v_set2 = v4.copy();
-        v_set2.set(3, v1);
-        Assert.assertEquals("testData is 1.0 ", 1.0, v_set2.getEntry(3), 0);
-        Assert.assertEquals("testData is 7.0 ", 7.0, v_set2.getEntry(6), 0);
-        try {
-            v_set2.set(7, v1);
-            Assert.fail("OutOfRangeException expected");
-        } catch (OutOfRangeException ex) {
-            // expected behavior
-        }
-
         ArrayRealVector v_set3 = v1.copy();
         v_set3.set(13.0);
         Assert.assertEquals("testData is 13.0 ", 13.0, v_set3.getEntry(2), 0);
@@ -1039,18 +1024,13 @@ public class ArrayRealVectorTest {
             // expected behavior
         }
 
-        ArrayRealVector v_projection = v1.projection(v2);
+        RealVector v_projection = v1.projection(v2);
         double[] result_projection = {1.662337662337662, 2.0779220779220777, 2.493506493506493};
         assertClose("compare vect", v_projection.getData(), result_projection, normTolerance);
 
         RealVector v_projection_2 = v1.projection(v2_t);
         double[] result_projection_2 = {1.662337662337662, 2.0779220779220777, 2.493506493506493};
         assertClose("compare vect", v_projection_2.getData(), result_projection_2, normTolerance);
-
-        RealVector v_projection_3 = v1.projection(v2.getData());
-        double[] result_projection_3 = {1.662337662337662, 2.0779220779220777, 2.493506493506493};
-        assertClose("compare vect", v_projection_3.getData(), result_projection_3, normTolerance);
-
     }
 
     @Test
@@ -1169,22 +1149,18 @@ public class ArrayRealVectorTest {
 
         double[] wData = new double[] {1, 1, 0};
         RealVector w = new ArrayRealVector(wData);
-        Assert.assertEquals(FastMath.sqrt(2) / 2, v.cosine(wData), normTolerance);
         Assert.assertEquals(FastMath.sqrt(2) / 2, v.cosine(w), normTolerance);
 
         wData = new double[] {1, 0, 0};
         w = new ArrayRealVector(wData);
-        Assert.assertEquals(1, v.cosine(wData), normTolerance);
         Assert.assertEquals(1, v.cosine(w), normTolerance);
 
         wData = new double[] {0, 1, 0};
         w = new ArrayRealVector(wData);
-        Assert.assertEquals(0, v.cosine(wData), normTolerance);
         Assert.assertEquals(0, v.cosine(w), 0);
 
         wData = new double[] {-1, 0, 0};
         w = new ArrayRealVector(wData);
-        Assert.assertEquals(-1, v.cosine(wData), normTolerance);
         Assert.assertEquals(-1, v.cosine(w), normTolerance);
     }
 
@@ -1228,7 +1204,7 @@ public class ArrayRealVectorTest {
         final double a = 1d;
         final double b = 2d;
         double[] aux = new double[] { 3d, 4d, 5d };
-        final RealVector x = new ArrayRealVector(aux, false);
+        final ArrayRealVector x = new ArrayRealVector(aux, false);
         final double[] y = new double[] { 6d, 7d };
         x.combine(a, b, y);
     }
@@ -1239,7 +1215,7 @@ public class ArrayRealVectorTest {
         final int dim = 10;
         final double a = (2 * random.nextDouble() - 1);
         final double b = (2 * random.nextDouble() - 1);
-        final RealVector x = new ArrayRealVector(dim);
+        final ArrayRealVector x = new ArrayRealVector(dim);
         final double[] y = new double[dim];
         final double[] expected = new double[dim];
         for (int i = 0; i < dim; i++) {
@@ -1353,7 +1329,7 @@ public class ArrayRealVectorTest {
         final double a = 1d;
         final double b = 2d;
         double[] aux = new double[] { 3d, 4d, 5d };
-        final RealVector x = new ArrayRealVector(aux, false);
+        final ArrayRealVector x = new ArrayRealVector(aux, false);
         final double[] y = new double[] { 6d, 7d };
         x.combineToSelf(a, b, y);
     }
@@ -1364,7 +1340,7 @@ public class ArrayRealVectorTest {
         final int dim = 10;
         final double a = (2 * random.nextDouble() - 1);
         final double b = (2 * random.nextDouble() - 1);
-        final RealVector x = new ArrayRealVector(dim);
+        final ArrayRealVector x = new ArrayRealVector(dim);
         final double[] y = new double[dim];
         final double[] expected = new double[dim];
         for (int i = 0; i < dim; i++) {

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorTest.java?rev=1162629&r1=1162628&r2=1162629&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/RealVectorTest.java Mon Aug 29 01:44:24 2011
@@ -40,7 +40,7 @@ public class RealVectorTest {
         }
 
         @Override
-        public double[] getData() { return values; }
+        public double[] toArray() { return values; }
 
         @Override
         public RealVector copy() {
@@ -176,7 +176,7 @@ public class RealVectorTest {
         double[] vec1Squared = { 1d, 4d, 9d, 16d, 25d };
         RealVector v = new TestVectorImpl(vec1.clone());
         RealVector w = v.map(new UnivariateRealFunction() { public double value(double x) { return x * x; } });
-        double[] d2 = w.getData();
+        double[] d2 = w.toArray();
         Assert.assertEquals(vec1Squared.length, d2.length);
         for(int i=0; i<vec1Squared.length; i++) {
             Assert.assertEquals(vec1Squared[i], d2[i], 0);
@@ -252,7 +252,7 @@ public class RealVectorTest {
         }
         final RealVector z = x.combine(a, b, y);
         Assert.assertTrue(z != x);
-        final double[] actual = z.getData();
+        final double[] actual = z.toArray();
         for (int i = 0; i < dim; i++) {
             final double delta;
             if (expected[i] == 0d) {
@@ -293,7 +293,7 @@ public class RealVectorTest {
             expected[i] = a * xi + b * yi;
         }
         Assert.assertSame(x, x.combineToSelf(a, b, y));
-        final double[] actual = x.getData();
+        final double[] actual = x.toArray();
         for (int i = 0; i < dim; i++) {
             final double delta;
             if (expected[i] == 0d) {

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java?rev=1162629&r1=1162628&r2=1162629&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java Mon Aug 29 01:44:24 2011
@@ -115,10 +115,6 @@ public class SparseRealVectorTest {
             throw unsupported();
         }
 
-        @Override
-        public RealVector add(double[] v) {
-            throw unsupported();
-        }
 
         @Override
         public RealVector subtract(RealVector v) {
@@ -126,11 +122,6 @@ public class SparseRealVectorTest {
         }
 
         @Override
-        public RealVector subtract(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
         public RealVector mapAdd(double d) {
             throw unsupported();
         }
@@ -178,21 +169,11 @@ public class SparseRealVectorTest {
             throw unsupported();
         }
 
-        @Override
-        public RealVector ebeMultiply(double[] v) {
-            throw unsupported();
-        }
-
         public RealVector ebeDivide(RealVector v) {
             throw unsupported();
         }
 
         @Override
-        public RealVector ebeDivide(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
         public double[] getData() {
             return data.clone();
         }
@@ -207,15 +188,6 @@ public class SparseRealVectorTest {
         }
 
         @Override
-        public double dotProduct(double[] v) {
-            double dot = 0;
-            for (int i = 0; i < data.length; i++) {
-                dot += data[i] * v[i];
-            }
-            return dot;
-        }
-
-        @Override
         public double getNorm() {
             throw unsupported();
         }
@@ -236,31 +208,16 @@ public class SparseRealVectorTest {
         }
 
         @Override
-        public double getDistance(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
         public double getL1Distance(RealVector v) {
             throw unsupported();
         }
 
         @Override
-        public double getL1Distance(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
         public double getLInfDistance(RealVector v) {
             throw unsupported();
         }
 
         @Override
-        public double getLInfDistance(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
         public RealVector unitVector() {
             throw unsupported();
         }
@@ -275,20 +232,10 @@ public class SparseRealVectorTest {
         }
 
         @Override
-        public RealVector projection(double[] v) {
-            throw unsupported();
-        }
-
-        @Override
         public RealMatrix outerProduct(RealVector v) {
             throw unsupported();
         }
 
-        @Override
-        public RealMatrix outerProduct(double[] v) {
-            throw unsupported();
-        }
-
         public double getEntry(int index) {
             return data[index];
         }
@@ -305,10 +252,6 @@ public class SparseRealVectorTest {
             throw unsupported();
         }
 
-        public RealVector append(double[] a) {
-            throw unsupported();
-        }
-
         public RealVector getSubVector(int index, int n) {
             throw unsupported();
         }
@@ -323,11 +266,6 @@ public class SparseRealVectorTest {
         }
 
         @Override
-        public void setSubVector(int index, double[] v) {
-            throw unsupported();
-        }
-
-        @Override
         public void set(double value) {
             throw unsupported();
         }
@@ -411,10 +349,6 @@ public class SparseRealVectorTest {
         Assert.assertEquals("testData len", 4, v_append_2.getDimension());
         Assert.assertEquals("testData is 2.0 ", 2.0, v_append_2.getEntry(3), 0);
 
-        RealVector v_append_3 = v1.append(vec2);
-        Assert.assertEquals("testData len", 6, v_append_3.getDimension());
-        Assert.assertEquals("testData is  ", 4.0, v_append_3.getEntry(3), 0);
-
         RealVector v_append_4 = v1.append(v2_t);
         Assert.assertEquals("testData len", 6, v_append_4.getDimension());
         Assert.assertEquals("testData is 4.0 ", 4.0, v_append_4.getEntry(3), 0);
@@ -990,7 +924,7 @@ public class SparseRealVectorTest {
 
     /** verifies that two vectors are close (sup norm) */
     protected void assertClose(String msg, double[] m, double[] n,
-            double tolerance) {
+                               double tolerance) {
         if (m.length != n.length) {
             Assert.fail("vectors have different lengths");
         }
@@ -1008,20 +942,13 @@ public class SparseRealVectorTest {
         u.setEntry(2, 2);
 
         final RealVector v1 = new OpenMapRealVector(3, 1e-6);
-        final double[] v2 = new double[3];
         v1.setEntry(0, 0);
-        v2[0] = 0;
         v1.setEntry(1, 3);
-        v2[1] = 3;
         v1.setEntry(2, 0);
-        v2[2] = 0;
 
         RealVector w;
 
         w = u.ebeMultiply(v1);
-        w = u.ebeMultiply(v2);
-
         w = u.ebeDivide(v1);
-        w = u.ebeDivide(v2);
     }
 }



Mime
View raw message