commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r740744 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/linear/ test/org/apache/commons/math/linear/
Date Wed, 04 Feb 2009 13:59:51 GMT
Author: luc
Date: Wed Feb  4 13:59:50 2009
New Revision: 740744

URL: http://svn.apache.org/viewvc?rev=740744&view=rev
Log:
improved consistency between RealVector and RealMatrix API
JIRA: MATH-245

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVector.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealVectorImplTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVector.java?rev=740744&r1=740743&r2=740744&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVector.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVector.java Wed
Feb  4 13:59:50 2009
@@ -696,11 +696,23 @@
      * @param index  index location of entry to be fetched
      * @return vector entry at index
      * @throws MatrixIndexException if the index is not valid
+     * @see #setEntry(int, double)
      */
     double getEntry(int index)
         throws MatrixIndexException;
 
     /**
+     * Set a single element.
+     * @param index element index.
+     * @param value new value for the element.
+     * @exception MatrixIndexException if the index is
+     * inconsistent with vector size
+     * @see #getEntry(int)
+     */
+    void setEntry(int index, double value)
+        throws MatrixIndexException;
+
+    /**
      * Returns the size of the vector.
      * @return size
      */
@@ -735,17 +747,7 @@
      * @exception MatrixIndexException if the index is
      * inconsistent with vector size
      */
-    RealVector get(int index, int n)
-        throws MatrixIndexException;
-
-    /**
-     * Set a single element.
-     * @param index element index.
-     * @param value new value for the element.
-     * @exception MatrixIndexException if the index is
-     * inconsistent with vector size
-     */
-    void set(int index, double value)
+    RealVector getSubVector(int index, int n)
         throws MatrixIndexException;
 
     /**
@@ -754,8 +756,9 @@
      * @param v vector containing the values to set.
      * @exception MatrixIndexException if the index is
      * inconsistent with vector size
+     * @see #setSubVector(int, double[])
      */
-    void set(int index, RealVector v)
+    void setSubVector(int index, RealVector v)
         throws MatrixIndexException;
 
     /**
@@ -764,8 +767,9 @@
      * @param v vector containing the values to set.
      * @exception MatrixIndexException if the index is
      * inconsistent with vector size
+     * @see #setSubVector(int, RealVector)
      */
-    void set(int index, double[] v)
+    void setSubVector(int index, double[] v)
         throws MatrixIndexException;
 
     /**

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorImpl.java?rev=740744&r1=740743&r2=740744&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorImpl.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealVectorImpl.java
Wed Feb  4 13:59:50 2009
@@ -1190,7 +1190,7 @@
     }
 
     /** {@inheritDoc} */
-    public RealVector get(int index, int n) {
+    public RealVector getSubVector(int index, int n) {
         RealVectorImpl out = new RealVectorImpl(n);
         try {
             System.arraycopy(data, index, out.data, 0, n);
@@ -1202,7 +1202,7 @@
     }
 
     /** {@inheritDoc} */
-    public void set(int index, double value) {
+    public void setEntry(int index, double value) {
         try {
             data[index] = value;
         } catch (IndexOutOfBoundsException e) {
@@ -1211,7 +1211,7 @@
     }
 
     /** {@inheritDoc} */
-    public void set(int index, RealVector v) {
+    public void setSubVector(int index, RealVector v) {
         try {
             try {
                 set(index, (RealVectorImpl) v);
@@ -1227,7 +1227,7 @@
     }
 
     /** {@inheritDoc} */
-    public void set(int index, double[] v) {
+    public void setSubVector(int index, double[] v) {
         try {
             System.arraycopy(v, 0, data, index, v.length);
         } catch (IndexOutOfBoundsException e) {
@@ -1246,7 +1246,7 @@
      */
     public void set(int index, RealVectorImpl v)
         throws MatrixIndexException {
-        set(index, v.data);
+        setSubVector(index, v.data);
     }
 
     /** {@inheritDoc} */

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java?rev=740744&r1=740743&r2=740744&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SingularValueDecompositionImpl.java
Wed Feb  4 13:59:50 2009
@@ -372,7 +372,7 @@
                 if (si == 0) {
                     throw new SingularMatrixException();
                 }
-                w.set(i, w.getEntry(i) / si);
+                w.setEntry(i, w.getEntry(i) / si);
             }
             return v.operate(w);
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java?rev=740744&r1=740743&r2=740744&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java
Wed Feb  4 13:59:50 2009
@@ -238,7 +238,7 @@
             iter.advance();
             int key = iter.key();
             if (v.getEntries().containsKey(key)) {
-                res.set(key, iter.value() + v.getEntry(key));
+                res.setEntry(key, iter.value() + v.getEntry(key));
             }
         }
         iter = v.getEntries().iterator();
@@ -246,7 +246,7 @@
             iter.advance();
             int key = iter.key();
             if (!entries.containsKey(key)) {
-                res.set(key, iter.value());
+                res.setEntry(key, iter.value());
             }
         }
         return res;
@@ -257,7 +257,7 @@
         checkVectorDimensions(v.length);
         SparseRealVector res = new SparseRealVector(getDimension());
         for (int i = 0; i < v.length; i++) {
-            res.set(i, v[i] + getEntry(i));
+            res.setEntry(i, v[i] + getEntry(i));
         }
         return res;
     }
@@ -272,7 +272,7 @@
         Iterator iter = v.entries.iterator();
         while (iter.hasNext()) {
             iter.advance();
-            res.set(iter.key() + virtualSize, iter.value());
+            res.setEntry(iter.key() + virtualSize, iter.value());
         }
         return res;
     }
@@ -288,7 +288,7 @@
     /** {@inheritDoc} */
     public RealVector append(double d) {
         RealVector res = new SparseRealVector(this, 1);
-        res.set(virtualSize, d);
+        res.setEntry(virtualSize, d);
         return res;
     }
 
@@ -296,7 +296,7 @@
     public RealVector append(double[] a) {
         RealVector res = new SparseRealVector(this, a.length);
         for (int i = 0; i < a.length; i++) {
-            res.set(i + virtualSize, a[i]);
+            res.setEntry(i + virtualSize, a[i]);
         }
         return res;
     }
@@ -340,7 +340,7 @@
         Iterator iter = res.entries.iterator();
         while (iter.hasNext()) {
             iter.advance();
-            res.set(iter.key(), iter.value() / v.getEntry(iter.key()));
+            res.setEntry(iter.key(), iter.value() / v.getEntry(iter.key()));
         }
         return res;
     }
@@ -352,7 +352,7 @@
         Iterator iter = res.entries.iterator();
         while (iter.hasNext()) {
             iter.advance();
-            res.set(iter.key(), iter.value() / v[iter.key()]);
+            res.setEntry(iter.key(), iter.value() / v[iter.key()]);
         }
         return null;
     }
@@ -364,7 +364,7 @@
         Iterator iter = res.entries.iterator();
         while (iter.hasNext()) {
             iter.advance();
-            res.set(iter.key(), iter.value() * v.getEntry(iter.key()));
+            res.setEntry(iter.key(), iter.value() * v.getEntry(iter.key()));
         }
         return res;
     }
@@ -376,13 +376,13 @@
         Iterator iter = res.entries.iterator();
         while (iter.hasNext()) {
             iter.advance();
-            res.set(iter.key(), iter.value() * v[iter.key()]);
+            res.setEntry(iter.key(), iter.value() * v[iter.key()]);
         }
         return res;
     }
 
     /** {@inheritDoc} */
-    public RealVector get(int index, int n) throws MatrixIndexException {
+    public RealVector getSubVector(int index, int n) throws MatrixIndexException {
         checkIndex(index);
         checkIndex(index+n-1);
         SparseRealVector res = new SparseRealVector(n);
@@ -392,7 +392,7 @@
             iter.advance();
             int key = iter.key();
             if (key >= index && key < end) {
-                res.set(key - index, iter.value());
+                res.setEntry(key - index, iter.value());
             }
         }
         return res;
@@ -632,7 +632,7 @@
     /** {@inheritDoc} */
     public RealVector mapAcosToSelf() {
         for(int i=0; i < virtualSize; i++){
-            set(i, Math.acos(getEntry(i)));
+            setEntry(i, Math.acos(getEntry(i)));
         }
         return this;
     }
@@ -645,7 +645,7 @@
     /** {@inheritDoc} */
     public RealVector mapAddToSelf(double d) {
         for (int i = 0; i < virtualSize; i++) {
-            set(i, getEntry(i) + d);
+            setEntry(i, getEntry(i) + d);
         }
         return this;
     }
@@ -806,7 +806,7 @@
     /** {@inheritDoc} */
     public RealVector mapInvToSelf() {
         for(int i=0; i < virtualSize; i++){
-            set(i, 1.0/getEntry(i));
+            setEntry(i, 1.0/getEntry(i));
         }
         return this;
     }
@@ -824,7 +824,7 @@
     /** {@inheritDoc} */
     public RealVector mapLog10ToSelf() {
         for(int i=0; i < virtualSize; i++){
-            set(i, Math.log10(getEntry(i)));
+            setEntry(i, Math.log10(getEntry(i)));
         }
         return this;
     }
@@ -847,7 +847,7 @@
     /** {@inheritDoc} */
     public RealVector mapLogToSelf() {
         for(int i=0; i < virtualSize; i++){
-            set(i, Math.log(getEntry(i)));
+            setEntry(i, Math.log(getEntry(i)));
         }
        return this;
     }
@@ -1080,7 +1080,7 @@
     }
 
     /** {@inheritDoc} */
-    public void set(int index, double value) throws MatrixIndexException {
+    public void setEntry(int index, double value) throws MatrixIndexException {
         checkIndex(index);
         if (!isZero(value)) {
             entries.put(index, value);
@@ -1090,25 +1090,25 @@
     }
 
     /** {@inheritDoc} */
-    public void set(int index, RealVector v) throws MatrixIndexException {
+    public void setSubVector(int index, RealVector v) throws MatrixIndexException {
         checkIndex(index);
         checkIndex(index + v.getDimension() - 1);
-        set(index, v.getData());
+        setSubVector(index, v.getData());
     }
 
     /** {@inheritDoc} */
-    public void set(int index, double[] v) throws MatrixIndexException {
+    public void setSubVector(int index, double[] v) throws MatrixIndexException {
         checkIndex(index);
         checkIndex(index + v.length - 1);
         for (int i = 0; i < v.length; i++) {
-            set(i + index, v[i]);
+            setEntry(i + index, v[i]);
         }
     }
 
     /** {@inheritDoc} */
     public void set(double value) {
         for(int i=0; i < virtualSize; i++){
-            set(i, value);
+            setEntry(i, value);
         }
     }
 
@@ -1145,9 +1145,9 @@
         SparseRealVector res = new SparseRealVector(this);
         for (int i = 0; i < v.length; i++) {
             if (entries.containsKey(i)) {
-                res.set(i, entries.get(i) - v[i]);
+                res.setEntry(i, entries.get(i) - v[i]);
             } else {
-                res.set(i, -v[i]);
+                res.setEntry(i, -v[i]);
             }
         }
         return res;

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealVectorImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealVectorImplTest.java?rev=740744&r1=740743&r2=740744&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealVectorImplTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealVectorImplTest.java
Wed Feb  4 13:59:50 2009
@@ -424,19 +424,19 @@
             throw unsupported();
         }
 
-        public RealVector get(int index, int n) throws MatrixIndexException {
+        public RealVector getSubVector(int index, int n) throws MatrixIndexException {
             throw unsupported();
         }
 
-        public void set(int index, double value) throws MatrixIndexException {
+        public void setEntry(int index, double value) throws MatrixIndexException {
             throw unsupported();
         }
 
-        public void set(int index, RealVector v) throws MatrixIndexException {
+        public void setSubVector(int index, RealVector v) throws MatrixIndexException {
             throw unsupported();
         }
 
-        public void set(int index, double[] v) throws MatrixIndexException {
+        public void setSubVector(int index, double[] v) throws MatrixIndexException {
             throw unsupported();
         }
 
@@ -576,11 +576,11 @@
 //      assertEquals("testData not same object ", v1.data, vout4.data);
 
 
-        RealVector vout5 = v4.get(3, 3);
+        RealVector vout5 = v4.getSubVector(3, 3);
         assertEquals("testData len", 3, vout5.getDimension());
         assertEquals("testData is 4.0 ", 5.0, vout5.getEntry(1));
         try {
-            v4.get(3, 7);
+            v4.getSubVector(3, 7);
             fail("MatrixIndexException expected");
         } catch (MatrixIndexException ex) {
             // expected behavior
@@ -589,10 +589,10 @@
         }
 
         RealVectorImpl v_set1 = (RealVectorImpl) v1.copy();
-        v_set1.set(1, 11.0);
+        v_set1.setEntry(1, 11.0);
         assertEquals("testData is 11.0 ", 11.0, v_set1.getEntry(1));
         try {
-            v_set1.set(3, 11.0);
+            v_set1.setEntry(3, 11.0);
             fail("MatrixIndexException expected");
         } catch (MatrixIndexException ex) {
             // expected behavior
@@ -627,11 +627,11 @@
         }
 
         RealVectorImpl v_set4 = (RealVectorImpl) v4.copy();
-        v_set4.set(3, v2_t);
+        v_set4.setSubVector(3, v2_t);
         assertEquals("testData is 1.0 ", 4.0, v_set4.getEntry(3));
         assertEquals("testData is 7.0 ", 7.0, v_set4.getEntry(6));
         try {
-            v_set4.set(7, v2_t);
+            v_set4.setSubVector(7, v2_t);
             fail("MatrixIndexException expected");
         } catch (MatrixIndexException ex) {
             // expected behavior
@@ -643,7 +643,7 @@
         RealVectorImpl vout10 = (RealVectorImpl) v1.copy();       
         RealVectorImpl vout10_2 = (RealVectorImpl) v1.copy();
         assertEquals(vout10, vout10_2);
-        vout10_2.set(0, 1.1);
+        vout10_2.setEntry(0, 1.1);
         assertNotSame(vout10, vout10_2);
 
     }
@@ -1147,16 +1147,16 @@
         RealVectorImpl v = new RealVectorImpl(new double[] { 0, 1, 2 });
 
         assertFalse(v.isNaN());
-        v.set(1, Double.NaN);
+        v.setEntry(1, Double.NaN);
         assertTrue(v.isNaN());
 
         assertFalse(v.isInfinite());
-        v.set(0, Double.POSITIVE_INFINITY);
+        v.setEntry(0, Double.POSITIVE_INFINITY);
         assertFalse(v.isInfinite());
-        v.set(1, 1);
+        v.setEntry(1, 1);
         assertTrue(v.isInfinite());
 
-        v.set(0, 0);
+        v.setEntry(0, 0);
         assertEquals(v, new RealVectorImpl(new double[] { 0, 1, 2 }));
         assertNotSame(v, new RealVectorImpl(new double[] { 0, 1, 2 + Math.ulp(2)}));
         assertNotSame(v, new RealVectorImpl(new double[] { 0, 1, 2, 3 }));

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java?rev=740744&r1=740743&r2=740744&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java
Wed Feb  4 13:59:50 2009
@@ -424,19 +424,19 @@
             throw unsupported();
         }
 
-        public RealVector get(int index, int n) throws MatrixIndexException {
+        public RealVector getSubVector(int index, int n) throws MatrixIndexException {
             throw unsupported();
         }
 
-        public void set(int index, double value) throws MatrixIndexException {
+        public void setEntry(int index, double value) throws MatrixIndexException {
             throw unsupported();
         }
 
-        public void set(int index, RealVector v) throws MatrixIndexException {
+        public void setSubVector(int index, RealVector v) throws MatrixIndexException {
             throw unsupported();
         }
 
-        public void set(int index, double[] v) throws MatrixIndexException {
+        public void setSubVector(int index, double[] v) throws MatrixIndexException {
             throw unsupported();
         }
 
@@ -580,11 +580,11 @@
 //      assertEquals("testData not same object ", v1.data, vout4.data);
 
 
-        RealVector vout5 = v4.get(3, 3);
+        RealVector vout5 = v4.getSubVector(3, 3);
         assertEquals("testData len", 3, vout5.getDimension());
         assertEquals("testData is 4.0 ", 5.0, vout5.getEntry(1));
         try {
-            v4.get(3, 7);
+            v4.getSubVector(3, 7);
             fail("MatrixIndexException expected");
         } catch (MatrixIndexException ex) {
             // expected behavior
@@ -593,10 +593,10 @@
         }
 
         SparseRealVector v_set1 = (SparseRealVector) v1.copy();
-        v_set1.set(1, 11.0);
+        v_set1.setEntry(1, 11.0);
         assertEquals("testData is 11.0 ", 11.0, v_set1.getEntry(1));
         try {
-            v_set1.set(3, 11.0);
+            v_set1.setEntry(3, 11.0);
             fail("MatrixIndexException expected");
         } catch (MatrixIndexException ex) {
             // expected behavior
@@ -605,11 +605,11 @@
         }
 
         SparseRealVector v_set2 = (SparseRealVector) v4.copy();
-        v_set2.set(3, v1);
+        v_set2.setSubVector(3, v1);
         assertEquals("testData is 1.0 ", 1.0, v_set2.getEntry(3));
         assertEquals("testData is 7.0 ", 7.0, v_set2.getEntry(6));
         try {
-            v_set2.set(7, v1);
+            v_set2.setSubVector(7, v1);
             fail("MatrixIndexException expected");
         } catch (MatrixIndexException ex) {
             // expected behavior
@@ -631,11 +631,11 @@
         }
 
         SparseRealVector v_set4 = (SparseRealVector) v4.copy();
-        v_set4.set(3, v2_t);
+        v_set4.setSubVector(3, v2_t);
         assertEquals("testData is 1.0 ", 4.0, v_set4.getEntry(3));
         assertEquals("testData is 7.0 ", 7.0, v_set4.getEntry(6));
         try {
-            v_set4.set(7, v2_t);
+            v_set4.setSubVector(7, v2_t);
             fail("MatrixIndexException expected");
         } catch (MatrixIndexException ex) {
             // expected behavior
@@ -1154,17 +1154,17 @@
         SparseRealVector v = new SparseRealVector(new double[] { 0, 1, 2 });
 
         assertFalse(v.isNaN());
-        v.set(1, Double.NaN);
+        v.setEntry(1, Double.NaN);
         assertTrue(v.isNaN());
 
         assertFalse(v.isInfinite());
-        v.set(0, Double.POSITIVE_INFINITY);
+        v.setEntry(0, Double.POSITIVE_INFINITY);
         // TODO: fixme
         //assertFalse(v.isInfinite());
-        v.set(1, 1);
+        v.setEntry(1, 1);
         assertTrue(v.isInfinite());
 
-        v.set(0, 0);
+        v.setEntry(0, 0);
         // TODO: backing store doesn't yet implement equals
         //assertEquals(v, new SparseRealVector(new double[] { 0, 1, 2 }));
         //assertNotSame(v, new SparseRealVector(new double[] { 0, 1, 2 + Math.ulp(2)}));



Mime
View raw message