You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bi...@apache.org on 2009/02/01 01:28:07 UTC

svn commit: r739667 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/linear/SparseRealVector.java site/xdoc/changes.xml

Author: billbarker
Date: Sun Feb  1 00:28:07 2009
New Revision: 739667

URL: http://svn.apache.org/viewvc?rev=739667&view=rev
Log:
Adding constructors that allow specifing epsilon.
Remove the isZero(int) method, since it is inconsistant with the isZero(double) method, and this class is tightly bound to it's backing store.
Some javadoc fixes.

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml

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=739667&r1=739666&r2=739667&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 Sun Feb  1 00:28:07 2009
@@ -46,7 +46,7 @@
     }
 
     /**
-     * Construct a (size)-length vector of zeros.
+     * Construct a (dimension)-length vector of zeros.
      * @param dimension size of the vector
      */
     public SparseRealVector(int dimension) {
@@ -55,6 +55,17 @@
     }
 
     /**
+     * Construct a (dimension)-length vector of zeros, specifying zero tolerance
+     * @param dimension Size of the vector
+     * @param epsilon The tolerance for having a value considered zero
+     */
+    public SparseRealVector(int dimension, double epsilon){
+        virtualSize = dimension;
+        entries = new OpenIntToDoubleHashMap(0.0);
+        this.epsilon = epsilon;
+    }
+    
+    /**
      * Resize the vector, for use with append
      * @param v The original vector
      * @param resize The amount to resize it
@@ -67,7 +78,7 @@
     /**
      * For advanced use, when you know the sparseness 
      * @param dimension The size of the vector
-     * @param expectedSize The excpected number of non-zer entries
+     * @param expectedSize The excpected number of non-zero entries
      */
     public SparseRealVector(int dimension, int expectedSize) {
         entries = new OpenIntToDoubleHashMap(expectedSize, 0.0);
@@ -75,8 +86,20 @@
     }
 
     /**
+     * For advanced use, when you know the sparseness and want to specify zero tolerance
+     * @param dimension The size of the vector
+     * @param expectedSize The expected number of non-zero entries
+     * @param epsilon The tolerance for having a value considered zero
+     */
+    public SparseRealVector(int dimension, int expectedSize, double epsilon){
+        virtualSize = dimension;
+        entries = new OpenIntToDoubleHashMap(expectedSize, 0.0);
+        this.epsilon = epsilon;
+    }
+    
+    /**
      * Create from a double array.
-     * only non-zero entries will be stored
+     * Only non-zero entries will be stored
      * @param values The set of values to create from
      */
     public SparseRealVector(double[] values) {
@@ -85,6 +108,18 @@
     }
 
     /**
+     * Create from a double array, specifying zero tolerance.
+     * Only non-zero entries will be stored
+     * @param values The set of values to create from
+     * @param epsilon The tolerance for having a value considered zero 
+     */
+    public SparseRealVector(double [] values, double epsilon){
+        virtualSize = values.length;
+        this.epsilon = epsilon;
+        fromDoubleArray(values);
+    }
+    
+    /**
      * Create from a Double array.
      * Only non-zero entries will be stored
      * @param values The set of values to create from
@@ -93,7 +128,23 @@
         virtualSize = values.length;
         double[] vals = new double[values.length];
         for(int i=0; i < values.length; i++){
-            vals[i] = values[i];
+            vals[i] = values[i].doubleValue();
+        }
+        fromDoubleArray(vals);
+    }
+    
+    /**
+     * Create from a Double array.
+     * Only non-zero entries will be stored
+     * @param values The set of values to create from
+     * @param epsilon The tolerance for having a value considered zero
+     */
+    public SparseRealVector(Double [] values, double epsilon){
+        virtualSize = values.length;
+        this.epsilon = epsilon;
+        double[] vals = new double[values.length];
+        for(int i=0; i < values.length; i++){
+            vals[i] = values[i].doubleValue();
         }
         fromDoubleArray(vals);
     }
@@ -140,15 +191,7 @@
         return entries;
     }
 
-    /**
-     * Determine if this index value is zero
-     * @param key The index to text
-     * @return <code>true</code> if this index is missing from the map, <code>false</code> otherwise
-     */
-    protected boolean isZero(int key) {
-        return !entries.containsKey(key);
-    }
-
+    
     /**
      * Determine if this value is zero
      * @param value The value to test
@@ -1047,7 +1090,7 @@
         checkIndex(index);
         if (!isZero(value)) {
             entries.put(index, value);
-        } else if (!isZero(index)) {
+        } else if (entries.containsKey(index)) {
             entries.remove(index);
         }
     }

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=739667&r1=739666&r2=739667&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Feb  1 00:28:07 2009
@@ -1,4 +1,4 @@
-<?xml version="1.0"?>
+<?xml version="1.0"?>
 <!--
    Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
@@ -294,6 +294,9 @@
       <action dev="brentworden" type="fix" issue="MATH-204" due-to="Mick">
         Added root checks for the endpoints.
       </action>
+      <action dev="billbarker" type="add">
+         Added a SparseRealVector class that implements a sparse vector for the RealVector interface.
+      </action>
     </release>
     <release version="1.2" date="2008-02-24"
     description="This release combines bug fixes and new features. Most notable