commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1185398 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/linear/ site/xdoc/ test/java/org/apache/commons/math/linear/
Date Mon, 17 Oct 2011 22:10:42 GMT
Author: erans
Date: Mon Oct 17 22:10:42 2011
New Revision: 1185398

URL: http://svn.apache.org/viewvc?rev=1185398&view=rev
Log:
MATH-685
Method "addToEntry" in "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/RealVector.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    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/UnmodifiableRealVectorAbstractTest.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=1185398&r1=1185397&r2=1185398&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 Oct 17 22:10:42 2011
@@ -673,6 +673,11 @@ public class ArrayRealVector extends Rea
     }
 
     /** {@inheritDoc} */
+    public void addToEntry(int index, double increment) {
+        data[index] += increment;
+    }
+
+    /** {@inheritDoc} */
     @Override
     public void setSubVector(int index, RealVector v) {
         if (v instanceof ArrayRealVector) {

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=1185398&r1=1185397&r2=1185398&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 Oct 17 22:10:42 2011
@@ -86,6 +86,19 @@ public abstract class RealVector {
     public abstract void setEntry(int index, double value);
 
     /**
+     * Change an entry at the specified index.
+     *
+     * @param index Index location of entry to be set.
+     * @param increment Value to add to the vector entry.
+     * @throws org.apache.commons.math.exception.OutOfRangeException if
+     * the index is not valid.
+     * @since 3.0
+     */
+    public void addToEntry(int index, double increment) {
+        setEntry(index, getEntry(index) + increment);
+    }
+
+    /**
      * Construct a new vector by appending a vector to this vector.
      *
      * @param v vector to append to this one.
@@ -1163,6 +1176,12 @@ public abstract class RealVector {
 
             /** {@inheritDoc} */
             @Override
+            public void addToEntry(int index, double value) {
+                throw new MathUnsupportedOperationException();
+            }
+
+            /** {@inheritDoc} */
+            @Override
             public int getDimension() {
                 return v.getDimension();
             }

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1185398&r1=1185397&r2=1185398&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon Oct 17 22:10:42 2011
@@ -52,6 +52,9 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="erans" type="add" issue="MATH-685">
+        Method "addToEntry" in "RealVector".
+      </action>
       <action dev="psteitz" type="update" issue="MATH-612" due-to="Christopher Nix">
         Replaced temporary matrices and entry mutators with double[][] arrays to speed computation
         in loops within QRDecomposition, Bi- and TriDiagonalTransformer implementations.

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=1185398&r1=1185397&r2=1185398&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 Oct 17 22:10:42 2011
@@ -1365,6 +1365,19 @@ public class ArrayRealVectorTest {
         }
     }
 
+    @Test
+    public void testAddToEntry() {
+        final double[] v = new double[] { 1, 2, 3 };
+        final ArrayRealVector x = new ArrayRealVector(v);
+        final double inc = 7;
+        for (int i = 0; i < x.getDimension(); i++) {
+            x.addToEntry(i, inc);
+        }
+        for (int i = 0; i < x.getDimension(); i++) {
+            Assert.assertEquals(v[i] + inc, x.getEntry(i), 0);
+        }
+    }
+
     /** verifies that two vectors are close (sup norm) */
     protected void assertClose(String msg, double[] m, double[] n,
             double tolerance) {

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=1185398&r1=1185397&r2=1185398&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 Oct 17 22:10:42 2011
@@ -305,4 +305,17 @@ public class RealVectorTest {
                                 actual[i], delta);
         }
     }
+
+    @Test
+    public void testAddToEntry() {
+        final double[] v = new double[] { 1, 2, 3 };
+        final RealVector x = new TestVectorImpl(v.clone());
+        final double inc = 7;
+        for (int i = 0; i < x.getDimension(); i++) {
+            x.addToEntry(i, inc);
+        }
+        for (int i = 0; i < x.getDimension(); i++) {
+            Assert.assertEquals(v[i] + inc, x.getEntry(i), 0);
+        }
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/UnmodifiableRealVectorAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/UnmodifiableRealVectorAbstractTest.java?rev=1185398&r1=1185397&r2=1185398&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/UnmodifiableRealVectorAbstractTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/UnmodifiableRealVectorAbstractTest.java
Mon Oct 17 22:10:42 2011
@@ -58,6 +58,7 @@ public abstract class UnmodifiableRealVe
     static {
         EXCLUDE.add("getEntry");
         EXCLUDE.add("setEntry");
+        EXCLUDE.add("addToEntry");
         EXCLUDE.add("getSubVector");
         EXCLUDE.add("setSubVector");
         EXCLUDE.add("iterator");
@@ -368,6 +369,15 @@ public abstract class UnmodifiableRealVe
         }
     }
 
+    @Test(expected = MathUnsupportedOperationException.class)
+    public void testAddToEntry() {
+        RealVector u = createVector();
+        RealVector v = RealVector.unmodifiableRealVector(u);
+        for (int i = 0; i < DIM; i++) {
+            v.addToEntry(i, 0d);
+        }
+    }
+
     @Test
     public void testGetSubVector() {
         RealVector u = createVector();



Mime
View raw message