You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by jm...@apache.org on 2010/02/03 09:06:02 UTC

svn commit: r905927 - in /lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math: DenseVector.java RandomAccessSparseVector.java SequentialAccessSparseVector.java

Author: jmannix
Date: Wed Feb  3 08:05:57 2010
New Revision: 905927

URL: http://svn.apache.org/viewvc?rev=905927&view=rev
Log:
Copy constructors with the option of shallow copy.  Nice for wrapping a vector in a writable subclass, for example.

Modified:
    lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java
    lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java
    lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java?rev=905927&r1=905926&r2=905927&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java Wed Feb  3 08:05:57 2010
@@ -46,6 +46,10 @@
     this.values = shallowCopy ? values : values.clone();
   }
 
+  public DenseVector(DenseVector values, boolean shallowCopy) {
+    this(values.values, shallowCopy);
+  }
+
   public DenseVector(String name, double[] values) {
     super(name);
     this.values = values.clone();

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java?rev=905927&r1=905926&r2=905927&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java Wed Feb  3 08:05:57 2010
@@ -63,6 +63,11 @@
     }
   }
 
+  public RandomAccessSparseVector(RandomAccessSparseVector other, boolean shallowCopy) {
+    super(other.getName(), other.size());
+    values = shallowCopy ? other.values : (OpenIntDoubleHashMap)other.values.clone() ;
+  }
+
   @Override
   protected Matrix matrixLike(int rows, int columns) {
     int[] cardinality = {rows, columns};

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java?rev=905927&r1=905926&r2=905927&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SequentialAccessSparseVector.java Wed Feb  3 08:05:57 2010
@@ -59,6 +59,11 @@
     }
   }
 
+  public SequentialAccessSparseVector(SequentialAccessSparseVector other, boolean shallowCopy) {
+    super(other.getName(), other.size());
+    values = shallowCopy ? other.values : other.values.clone();
+  }
+
   public SequentialAccessSparseVector(SequentialAccessSparseVector other) {
     this(other.getName(), other.size(), other.getNumNondefaultElements());
     values = other.values.clone();