mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r791560 - /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/
Date Mon, 06 Jul 2009 18:36:46 GMT
Author: srowen
Date: Mon Jul  6 18:36:45 2009
New Revision: 791560

URL: http://svn.apache.org/viewvc?rev=791560&view=rev
Log:
MAHOUT-65 clone fixes

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractMatrix.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseMatrix.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/MatrixView.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/OrderedIntDoubleMapping.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseColumnMatrix.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseRowMatrix.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractMatrix.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractMatrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractMatrix.java Mon
Jul  6 18:36:45 2009
@@ -239,7 +239,21 @@
   }
 
   @Override
-  public abstract Matrix clone();
+  public Matrix clone() {
+    AbstractMatrix clone;
+    try {
+      clone = (AbstractMatrix) super.clone();
+    } catch (CloneNotSupportedException cnse) {
+      throw new IllegalStateException(cnse); // can't happen
+    }
+    if (rowLabelBindings != null) {
+      clone.rowLabelBindings = (Map<String,Integer>) ((HashMap<String,Integer>)
rowLabelBindings).clone();
+    }
+    if (columnLabelBindings != null) {
+      clone.columnLabelBindings = (Map<String,Integer>) ((HashMap<String,Integer>)
columnLabelBindings).clone();
+    }
+    return clone;
+  }
 
   @Override
   public Matrix divide(double x) {

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java Mon
Jul  6 18:36:45 2009
@@ -64,9 +64,20 @@
   public abstract Vector.Element getElement(int index); 
 
 
-
   @Override
-  public abstract Vector clone();
+  public Vector clone() {
+    AbstractVector clone;
+    try {
+      clone = (AbstractVector) super.clone();
+    } catch (CloneNotSupportedException cnse) {
+      throw new IllegalStateException(cnse); // Can't happen
+    }
+    if (bindings != null) {
+      clone.bindings = (Map<String,Integer>) ((HashMap<String,Integer>) bindings).clone();
+    }
+    // name is OK
+    return clone;
+  }
 
   @Override
   public Vector divide(double x) {
@@ -343,12 +354,7 @@
   @Override
   public void setName(String name) {
     this.name = name;
-
-  }/*
-    * (non-Javadoc)
-    * 
-    * @see org.apache.mahout.matrix.Vector#asFormatString()
-    */
+  }
 
   @Override
   public String asFormatString() {
@@ -429,11 +435,6 @@
     return true;
   }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.mahout.matrix.Vector#get(java.lang.String)
-   */
   @Override
   public double get(String label) throws IndexException, UnboundLabelException {
     if (bindings == null)
@@ -444,21 +445,11 @@
     return get(index);
   }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.mahout.matrix.Vector#getLabelBindings()
-   */
   @Override
   public Map<String, Integer> getLabelBindings() {
     return bindings;
   }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.mahout.matrix.Vector#set(java.lang.String, double)
-   */
   @Override
   public void set(String label, double value) throws IndexException,
           UnboundLabelException {
@@ -470,21 +461,11 @@
     set(index, value);
   }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.mahout.matrix.Vector#setLabelBindings(java.util.Map)
-   */
   @Override
   public void setLabelBindings(Map<String, Integer> bindings) {
     this.bindings = bindings;
   }
 
-  /*
-   * (non-Javadoc)
-   * 
-   * @see org.apache.mahout.matrix.Vector#set(java.lang.String, int, double)
-   */
   @Override
   public void set(String label, int index, double value) throws IndexException {
     if (bindings == null)

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseMatrix.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseMatrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseMatrix.java Mon Jul
 6 18:36:45 2009
@@ -48,10 +48,10 @@
    */
   public DenseMatrix(double[][] values) {
     // clone the rows
-    this.values = values.clone();
+    this.values = new double[values.length][];
     // be careful, need to clone the columns too
     for (int i = 0; i < values.length; i++)
-      this.values[i] = this.values[i].clone();
+      this.values[i] = values[i].clone();
   }
 
   /**
@@ -74,7 +74,12 @@
 
   @Override
   public Matrix clone() {
-    return new DenseMatrix(values);
+    DenseMatrix clone = (DenseMatrix) super.clone();
+    clone.values = new double[values.length][];
+    for (int i = 0; i < values.length; i++) {
+      clone.values[i] = values[i].clone();
+    }
+    return clone;
   }
 
   @Override

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/DenseVector.java Mon Jul
 6 18:36:45 2009
@@ -28,6 +28,8 @@
  */
 public class DenseVector extends AbstractVector {
 
+  private double[] values;
+
   /** For serialization purposes only */
   public DenseVector() {
   }
@@ -36,8 +38,6 @@
     super(name);
   }
 
-  private double[] values;
-
   /**
    * Construct a new instance using provided values
    * 
@@ -78,9 +78,9 @@
 
   @Override
   public DenseVector clone() {
-    DenseVector denseVector = new DenseVector(values);
-    denseVector.setLabelBindings(getLabelBindings());
-    return denseVector;
+    DenseVector clone = (DenseVector) super.clone();
+    clone.values = values.clone();
+    return clone;
   }
 
   @Override

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/MatrixView.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/MatrixView.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/MatrixView.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/MatrixView.java Mon Jul
 6 18:36:45 2009
@@ -58,7 +58,11 @@
 
   @Override
   public Matrix clone() {
-    return new MatrixView(matrix.clone(), offset, cardinality);
+    MatrixView clone = (MatrixView) super.clone();
+    clone.matrix = matrix.clone();
+    clone.offset = offset.clone();
+    clone.cardinality = cardinality.clone();
+    return clone;
   }
 
   @Override

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/OrderedIntDoubleMapping.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/OrderedIntDoubleMapping.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/OrderedIntDoubleMapping.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/OrderedIntDoubleMapping.java
Mon Jul  6 18:36:45 2009
@@ -154,7 +154,7 @@
   }
 
   @Override
-  public Object clone() {
+  public OrderedIntDoubleMapping clone() {
     OrderedIntDoubleMapping clone = new OrderedIntDoubleMapping(numMappings);
     System.arraycopy(indices, 0, clone.indices, 0, numMappings);
     System.arraycopy(values, 0, clone.values, 0, numMappings);

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseColumnMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseColumnMatrix.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseColumnMatrix.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseColumnMatrix.java
Mon Jul  6 18:36:45 2009
@@ -67,10 +67,13 @@
 
   @Override
   public Matrix clone() {
-    SparseColumnMatrix copy = new SparseColumnMatrix(cardinality);
-    for (int col = 0; col < cardinality[COL]; col++)
-      copy.columns[col] = columns[col].clone();
-    return copy;
+    SparseColumnMatrix clone = (SparseColumnMatrix) super.clone();
+    clone.cardinality = cardinality.clone();
+    clone.columns = new Vector[columns.length];
+    for (int i = 0; i < columns.length; i++) {
+      clone.columns[i] = columns[i].clone();
+    }
+    return clone;
   }
 
   @Override

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseMatrix.java Mon
Jul  6 18:36:45 2009
@@ -28,14 +28,14 @@
  */
 public class SparseMatrix extends AbstractMatrix {
 
-  public SparseMatrix() {
-    super();
-  }
-
   private int[] cardinality;
 
   private Map<Integer, Vector> rows;
 
+  public SparseMatrix() {
+    super();
+  }
+
   /**
    * Construct a matrix of the given cardinality with the given row map
    * 
@@ -66,10 +66,10 @@
 
   @Override
   public Matrix clone() {
-    SparseMatrix copy = new SparseMatrix(cardinality);
-    for (Map.Entry<Integer, Vector> entry : rows.entrySet())
-      copy.rows.put(entry.getKey(), entry.getValue().clone());
-    return copy;
+    SparseMatrix clone = (SparseMatrix) super.clone();
+    clone.cardinality = cardinality.clone();
+    clone.rows = (Map<Integer,Vector>) ((HashMap<Integer,Vector>) rows).clone();
+    return clone;
   }
 
   @Override

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseRowMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseRowMatrix.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseRowMatrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseRowMatrix.java Mon
Jul  6 18:36:45 2009
@@ -67,10 +67,13 @@
 
   @Override
   public Matrix clone() {
-    SparseRowMatrix copy = new SparseRowMatrix(cardinality);
-    for (int row = 0; row < cardinality[ROW]; row++)
-      copy.rows[row] = rows[row].clone();
-    return copy;
+    SparseRowMatrix clone = (SparseRowMatrix) super.clone();
+    clone.cardinality = cardinality.clone();
+    clone.rows = new Vector[rows.length];
+    for (int i = 0; i < rows.length; i++) {
+      clone.rows[i] = rows[i].clone();
+    }
+    return clone;
   }
 
   @Override

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/SparseVector.java Mon
Jul  6 18:36:45 2009
@@ -28,16 +28,16 @@
  */
 public class SparseVector extends AbstractVector {
 
+  private OrderedIntDoubleMapping values;
+
+  private int cardinality;
+
   /**
    * For serialization purposes only.
    */
   public SparseVector() {
   }
 
-  private OrderedIntDoubleMapping values;
-
-  private int cardinality;
-
   public SparseVector(int cardinality, int size) {
     this(null, cardinality, size);
   }
@@ -71,9 +71,9 @@
 
   @Override
   public SparseVector clone() {
-    SparseVector result = like();
-    result.values = (OrderedIntDoubleMapping) values.clone();
-    return result;
+    SparseVector clone = (SparseVector) super.clone();
+    clone.values = values.clone();
+    return clone;
   }
 
   @Override

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java?rev=791560&r1=791559&r2=791560&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/VectorView.java Mon Jul
 6 18:36:45 2009
@@ -28,10 +28,6 @@
  */
 public class VectorView extends AbstractVector {
 
-  /** For serialization purposes only */
-  public VectorView() {
-  }
-
   private Vector vector;
 
   // the offset into the Vector
@@ -40,6 +36,10 @@
   // the cardinality of the view
   private int cardinality;
 
+  /** For serialization purposes only */
+  public VectorView() {
+  }
+
   public VectorView(Vector vector, int offset, int cardinality) {
     this.vector = vector;
     this.offset = offset;
@@ -58,7 +58,9 @@
 
   @Override
   public Vector clone() {
-    return new VectorView(vector.clone(), offset, cardinality);
+    VectorView clone = (VectorView) super.clone();
+    clone.vector = vector.clone();
+    return clone;
   }
 
   @Override



Mime
View raw message