mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jman...@apache.org
Subject svn commit: r901575 - in /lucene/mahout/trunk/math/src: main/java/org/apache/mahout/math/ main/java/org/apache/mahout/math/decomposer/ test/java/org/apache/mahout/math/decomposer/
Date Thu, 21 Jan 2010 07:14:59 GMT
Author: jmannix
Date: Thu Jan 21 07:14:48 2010
New Revision: 901575

URL: http://svn.apache.org/viewvc?rev=901575&view=rev
Log:
Reverting to revision 901569, because I checked in way too much.  Need to cherry pick and
recommit

Removed:
    lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/
    lucene/mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/
Modified:
    lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java
    lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseMatrix.java
    lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseVector.java
    lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseColumnMatrix.java
    lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java?rev=901575&r1=901574&r2=901575&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java Thu
Jan 21 07:14:48 2010
@@ -21,9 +21,11 @@
 import com.google.gson.GsonBuilder;
 import com.google.gson.reflect.TypeToken;
 
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
 import java.lang.reflect.Type;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 /** A few universal implementations of convenience functions */
@@ -458,128 +460,4 @@
     return result;
   }
 
-  protected class TransposeViewVector extends AbstractVector {
-
-    protected Matrix matrix;
-    protected int transposeOffset;
-    protected int numCols;
-    private boolean rowToColumn;
-
-    public TransposeViewVector(Matrix m, int offset) {
-      this(m, offset, true);
-    }
-
-    public TransposeViewVector(Matrix m, int offset, boolean rowToColumn) {
-      matrix = m;
-      this.transposeOffset = offset;
-      this.rowToColumn = rowToColumn;
-      numCols = rowToColumn ? m.numCols() : m.numRows();
-      size = rowToColumn ? m.numRows() : m.numCols();
-    }
-
-    @Override
-    public Vector clone() {
-      Vector v = new DenseVector(size);
-      addTo(v);
-      return v;
-    }
-
-    @Override
-    protected Matrix matrixLike(int rows, int columns) {
-      return matrix.like(rows, columns);
-    }
-
-    @Override
-    public Iterator<Element> iterateAll() {
-      return new Iterator<Element>() {
-        int i = 0;
-        @Override
-        public boolean hasNext() {
-          return i < size;
-        }
-
-        @Override
-        public Element next() {
-          return getElement(i++);
-        }
-
-        @Override
-        public void remove() {
-          throw new UnsupportedOperationException("Element removal not supported");
-        }
-      };
-    }
-
-    /**
-     * Currently delegates to iterateAll.  TODO: This could be optimized to at least skip
empty rows if there are
-     * many of them.
-     * @return an iterator (currently dense).
-     */
-    @Override
-    public Iterator<Element> iterateNonZero() {
-      return iterateAll();
-    }
-
-    @Override
-    public Element getElement(final int i) {
-      return new Element() {
-        @Override
-        public double get() {
-          return getQuick(i);
-        }
-
-        @Override
-        public int index() {
-          return i;
-        }
-
-        @Override
-        public void set(double value) {
-          setQuick(i, value);
-        }
-      };
-    }
-
-    @Override
-    public double getQuick(int index) {
-      Vector v = rowToColumn ? matrix.getRow(index) : matrix.getColumn(index);
-      return v == null ? 0 : v.getQuick(transposeOffset);
-    }
-
-    @Override
-    public void setQuick(int index, double value) {
-      Vector v = rowToColumn ? matrix.getRow(index) : matrix.getColumn(index);
-      if(v == null) {
-        v = newVector(numCols);
-        matrix.assignRow(index, v);
-      }
-      v.setQuick(transposeOffset, value);
-    }
-
-    protected Vector newVector(int cardinality)
-    {
-      return new DenseVector(cardinality);
-    }
-
-    @Override
-    public Vector like() {
-      return new DenseVector(size);
-    }
-
-    @Override
-    public Vector like(int cardinality) {
-      return new DenseVector(cardinality);
-    }
-
-    /**
-     * TODO: currently I don't know of an efficient way to get this value correctly.
-     *
-     * @return the number of nonzero entries
-     */
-    @Override
-    public int getNumNondefaultElements() {
-      return size;
-    }
-  }
-
 }

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseMatrix.java?rev=901575&r1=901574&r2=901575&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseMatrix.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/DenseMatrix.java Thu Jan
21 07:14:48 2010
@@ -136,7 +136,11 @@
     if (column < 0 || column >= columnSize()) {
       throw new IndexException();
     }
-    return new TransposeViewVector(this, column);
+    double[] col = new double[rowSize()];
+    for (int row = 0; row < rowSize(); row++) {
+      col[row] = values[row][column];
+    }
+    return new DenseVector(col);
   }
 
   @Override
@@ -144,7 +148,7 @@
     if (row < 0 || row >= rowSize()) {
       throw new IndexException();
     }
-    return new DenseVector(values[row], true);
+    return new DenseVector(values[row]);
   }
   
 }

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=901575&r1=901574&r2=901575&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 Thu Jan
21 07:14:48 2010
@@ -37,11 +37,7 @@
 
   /** Construct a new instance using provided values */
   public DenseVector(double[] values) {
-    this(values, false);
-  }
-
-  public DenseVector(double[] values, boolean shallowCopy) {
-    this.values = shallowCopy ? values : values.clone();
+    this.values = values.clone();
   }
 
   public DenseVector(String name, double[] values) {

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseColumnMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseColumnMatrix.java?rev=901575&r1=901574&r2=901575&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseColumnMatrix.java
(original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseColumnMatrix.java
Thu Jan 21 07:14:48 2010
@@ -160,7 +160,11 @@
     if (row < 0 || row >= cardinality[ROW]) {
       throw new IndexException();
     }
-    return new TransposeViewVector(this, row, false);
+    double[] d = new double[cardinality[COL]];
+    for (int col = 0; col < cardinality[COL]; col++) {
+      d[col] = getQuick(row, col);
+    }
+    return new DenseVector(d);
   }
 
 }

Modified: lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java?rev=901575&r1=901574&r2=901575&view=diff
==============================================================================
--- lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java (original)
+++ lucene/mahout/trunk/math/src/main/java/org/apache/mahout/math/SparseRowMatrix.java Thu
Jan 21 07:14:48 2010
@@ -143,35 +143,18 @@
     return this;
   }
 
-  /**
-   *
-   * @param column an int column index
-   * @return Currently: a full, dense copy of the column.  <b>You don't have the ability
to mutate the original
-   * matrix with this "view", as it is a fresh copy of the data</b> TODO: Fix this
(MAHOUT-211) 
-   */
   @Override
   public Vector getColumn(int column) {
     if (column < 0 || column >= cardinality[COL]) {
       throw new IndexException();
     }
-    return new TransposeViewVector(this, column) {
-      @Override
-      protected Vector newVector(int cardinality) {
-        return new RandomAccessSparseVector(cardinality, 10);
-      }
-    };
-    //double[] d = new double[cardinality[ROW]];
-    //for (int row = 0; row < cardinality[ROW]; row++) {
-    //  d[row] = getQuick(row, column);
-    //}
-    //return new DenseVector(d, true);  // no need to copy it after making it from scratch...
+    double[] d = new double[cardinality[ROW]];
+    for (int row = 0; row < cardinality[ROW]; row++) {
+      d[row] = getQuick(row, column);
+    }
+    return new DenseVector(d);
   }
 
-  /**
-   *
-   * @param row an int row index
-   * @return a deep view of the Vector at specified row (ie you may mutate the original matrix
using this row)
-   */
   @Override
   public Vector getRow(int row) {
     if (row < 0 || row >= cardinality[ROW]) {



Mime
View raw message