You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2011/01/08 14:49:11 UTC

svn commit: r1056703 [3/4] - in /mahout/trunk: core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ core/src/main/java/org/apache/mahout/classifier/ core/src/main/java/org/apache/mahout/classifier/bayes/common/ core/src/main/java/org/apache/mahou...

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix1D.java Sat Jan  8 13:49:07 2011
@@ -8,18 +8,17 @@ It is provided "as is" without expressed
 */
 package org.apache.mahout.math.matrix;
 
-import org.apache.mahout.math.function.BinaryFunction;
+import org.apache.mahout.math.function.DoubleDoubleFunction;
 import org.apache.mahout.math.function.Functions;
 import org.apache.mahout.math.function.PlusMult;
-import org.apache.mahout.math.function.UnaryFunction;
-import org.apache.mahout.math.function.DoubleProcedure;
+import org.apache.mahout.math.function.DoubleFunction;
 import org.apache.mahout.math.list.DoubleArrayList;
 import org.apache.mahout.math.list.IntArrayList;
 import org.apache.mahout.math.matrix.impl.AbstractMatrix1D;
 
 /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
 @Deprecated
-public abstract class DoubleMatrix1D extends AbstractMatrix1D {
+public abstract class DoubleMatrix1D extends AbstractMatrix1D implements Cloneable {
 
   /** Makes this class non instantiable, but still let's others inherit from it. */
   protected DoubleMatrix1D() {
@@ -45,8 +44,8 @@ public abstract class DoubleMatrix1D ext
    * @return the aggregated measure.
    * @see org.apache.mahout.math.function.Functions
    */
-  public double aggregate(BinaryFunction aggr,
-                          UnaryFunction f) {
+  public double aggregate(DoubleDoubleFunction aggr,
+                          DoubleFunction f) {
     if (size == 0) {
       return Double.NaN;
     }
@@ -83,8 +82,8 @@ public abstract class DoubleMatrix1D ext
    * @throws IllegalArgumentException if <tt>size() != other.size()</tt>.
    * @see org.apache.mahout.math.function.Functions
    */
-  public double aggregate(DoubleMatrix1D other, BinaryFunction aggr,
-                          BinaryFunction f) {
+  public double aggregate(DoubleMatrix1D other, DoubleDoubleFunction aggr,
+                          DoubleDoubleFunction f) {
     checkSize(other);
     if (size == 0) {
       return Double.NaN;
@@ -102,10 +101,9 @@ public abstract class DoubleMatrix1D ext
    * matrix, and vice-versa.
    *
    * @param values the values to be filled into the cells.
-   * @return <tt>this</tt> (for convenience only).
    * @throws IllegalArgumentException if <tt>values.length != size()</tt>.
    */
-  public DoubleMatrix1D assign(double[] values) {
+  public void assign(double[] values) {
     if (values.length != size) {
       throw new IllegalArgumentException(
           "Must have same number of cells: length=" + values.length + "size()=" + size());
@@ -113,20 +111,17 @@ public abstract class DoubleMatrix1D ext
     for (int i = size; --i >= 0;) {
       setQuick(i, values[i]);
     }
-    return this;
   }
 
   /**
    * Sets all cells to the state specified by <tt>value</tt>.
    *
    * @param value the value to be filled into the cells.
-   * @return <tt>this</tt> (for convenience only).
    */
-  public DoubleMatrix1D assign(double value) {
+  public void assign(double value) {
     for (int i = size; --i >= 0;) {
       setQuick(i, value);
     }
-    return this;
   }
 
   /**
@@ -142,14 +137,12 @@ public abstract class DoubleMatrix1D ext
    * For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
    *
    * @param function a function object taking as argument the current cell's value.
-   * @return <tt>this</tt> (for convenience only).
    * @see org.apache.mahout.math.function.Functions
    */
-  public DoubleMatrix1D assign(UnaryFunction function) {
+  public void assign(DoubleFunction function) {
     for (int i = size; --i >= 0;) {
       setQuick(i, function.apply(getQuick(i)));
     }
-    return this;
   }
 
   /**
@@ -195,7 +188,7 @@ public abstract class DoubleMatrix1D ext
    * @throws IllegalArgumentException if <tt>size() != y.size()</tt>.
    * @see org.apache.mahout.math.function.Functions
    */
-  public DoubleMatrix1D assign(DoubleMatrix1D y, BinaryFunction function) {
+  public DoubleMatrix1D assign(DoubleMatrix1D y, DoubleDoubleFunction function) {
     checkSize(y);
     for (int i = size; --i >= 0;) {
       setQuick(i, function.apply(getQuick(i), y.getQuick(i)));
@@ -216,7 +209,7 @@ public abstract class DoubleMatrix1D ext
    *
    * // for non-standard functions there is no shortcut:
    * m1.assign(m2,
-   * &nbsp;&nbsp;&nbsp;new BinaryFunction() {
+   * &nbsp;&nbsp;&nbsp;new DoubleDoubleFunction() {
    * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public double apply(double x, double y) { return Math.pow(x,y); }
    * &nbsp;&nbsp;&nbsp;}
    * );
@@ -226,12 +219,11 @@ public abstract class DoubleMatrix1D ext
    * @param y        the secondary matrix to operate on.
    * @param function a function object taking as first argument the current cell's value of <tt>this</tt>, and as second
    *                 argument the current cell's value of <tt>y</tt>,
-   * @return <tt>this</tt> (for convenience only).
    * @throws IllegalArgumentException if <tt>size() != y.size()</tt>.
    * @see org.apache.mahout.math.function.Functions
    */
-  public DoubleMatrix1D assign(DoubleMatrix1D y, BinaryFunction function,
-                               IntArrayList nonZeroIndexes) {
+  public void assign(DoubleMatrix1D y, DoubleDoubleFunction function,
+                     IntArrayList nonZeroIndexes) {
     checkSize(y);
     int[] nonZeroElements = nonZeroIndexes.elements();
 
@@ -249,7 +241,7 @@ public abstract class DoubleMatrix1D ext
     } else if (function instanceof PlusMult) {
       double multiplicator = ((PlusMult) function).getMultiplicator();
       if (multiplicator == 0) { // x[i] = x[i] + 0*y[i]
-        return this;
+        // do nothing
       } else if (multiplicator == 1) { // x[i] = x[i] + y[i]
         for (int index = nonZeroIndexes.size(); --index >= 0;) {
           int i = nonZeroElements[index];
@@ -267,9 +259,8 @@ public abstract class DoubleMatrix1D ext
         }
       }
     } else { // the general case x[i] = f(x[i],y[i])
-      return assign(y, function);
+      assign(y, function);
     }
-    return this;
   }
 
   /** Returns the number of cells having non-zero values; ignores tolerance. */
@@ -598,18 +589,11 @@ public abstract class DoubleMatrix1D ext
    * @return a new view of the receiver.
    */
   protected DoubleMatrix1D view() {
-    return (DoubleMatrix1D) clone();
-  }
-
-  /**
-   * Constructs and returns a new <i>flip view</i>. What used to be index <tt>0</tt> is now index <tt>size()-1</tt>,
-   * ..., what used to be index <tt>size()-1</tt> is now index <tt>0</tt>. The returned view is backed by this matrix,
-   * so changes in the returned view are reflected in this matrix, and vice-versa.
-   *
-   * @return a new flip view.
-   */
-  public DoubleMatrix1D viewFlip() {
-    return (DoubleMatrix1D) (view().vFlip());
+    try {
+      return (DoubleMatrix1D) clone();
+    } catch (CloneNotSupportedException cnse) {
+      throw new IllegalStateException();
+    }
   }
 
   /**
@@ -633,73 +617,6 @@ public abstract class DoubleMatrix1D ext
   }
 
   /**
-   * Constructs and returns a new <i>selection view</i> that is a matrix holding the indicated cells. There holds
-   * <tt>view.size() == indexes.length</tt> and <tt>view.get(i) == this.get(indexes[i])</tt>. Indexes can occur multiple
-   * times and can be in arbitrary order. <p> <b>Example:</b> <br>
-   * <pre>
-   * this     = (0,0,8,0,7)
-   * indexes  = (0,2,4,2)
-   * -->
-   * view     = (0,8,7,8)
-   * </pre>
-   * Note that modifying <tt>indexes</tt> after this call has returned has no effect on the view. The returned view is
-   * backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa.
-   *
-   * @param indexes The indexes of the cells that shall be visible in the new view. To indicate that <i>all</i> cells
-   *                shall be visible, simply set this parameter to <tt>null</tt>.
-   * @return the new view.
-   * @throws IndexOutOfBoundsException if <tt>!(0 <= indexes[i] < size())</tt> for any <tt>i=0..indexes.length()-1</tt>.
-   */
-  public DoubleMatrix1D viewSelection(int[] indexes) {
-    // check for "all"
-    if (indexes == null) {
-      indexes = new int[size];
-      for (int i = size; --i >= 0;) {
-        indexes[i] = i;
-      }
-    }
-
-    checkIndexes(indexes);
-    int[] offsets = new int[indexes.length];
-    for (int i = indexes.length; --i >= 0;) {
-      offsets[i] = index(indexes[i]);
-    }
-    return viewSelectionLike(offsets);
-  }
-
-  /**
-   * Constructs and returns a new <i>selection view</i> that is a matrix holding the cells matching the given condition.
-   * Applies the condition to each cell and takes only those cells where <tt>condition.apply(get(i))</tt> yields
-   * <tt>true</tt>. <p> <b>Example:</b> <br>
-   * <pre>
-   * // extract and view all cells with even value
-   * matrix = 0 1 2 3
-   * matrix.viewSelection(
-   * &nbsp;&nbsp;&nbsp;new DoubleProcedure() {
-   * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(double a) { return a % 2 == 0; }
-   * &nbsp;&nbsp;&nbsp;}
-   * );
-   * -->
-   * matrix ==  0 2
-   * </pre>
-   * For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>. The returned view is
-   * backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa.
-   *
-   * @param condition The condition to be matched.
-   * @return the new view.
-   */
-  public DoubleMatrix1D viewSelection(DoubleProcedure condition) {
-    IntArrayList matches = new IntArrayList();
-    for (int i = 0; i < size; i++) {
-      if (condition.apply(getQuick(i))) {
-        matches.add(i);
-      }
-    }
-    matches.trimToSize();
-    return viewSelection(matches.elements());
-  }
-
-  /**
    * Construct and returns a new selection view.
    *
    * @param offsets the offsets of the visible elements.
@@ -708,19 +625,6 @@ public abstract class DoubleMatrix1D ext
   protected abstract DoubleMatrix1D viewSelectionLike(int[] offsets);
 
   /**
-   * Constructs and returns a new <i>stride view</i> which is a sub matrix consisting of every i-th cell. More
-   * specifically, the view has size <tt>this.size()/stride</tt> holding cells <tt>this.get(i*stride)</tt> for all <tt>i
-   * = 0..size()/stride - 1</tt>.
-   *
-   * @param stride the step factor.
-   * @return the new view.
-   * @throws IndexOutOfBoundsException if <tt>stride <= 0</tt>.
-   */
-  public DoubleMatrix1D viewStrides(int stride) {
-    return (DoubleMatrix1D) (view().vStrides(stride));
-  }
-
-  /**
    * Returns the dot product of two vectors x and y, which is <tt>Sum(x[i]*y[i])</tt>. Where <tt>x == this</tt>.
    * Operates on cells at indexes <tt>0 .. Math.min(size(),y.size())</tt>.
    *

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/DoubleMatrix2D.java Sat Jan  8 13:49:07 2011
@@ -9,18 +9,16 @@ It is provided "as is" without expressed
 package org.apache.mahout.math.matrix;
 
 import org.apache.mahout.math.function.Functions;
-import org.apache.mahout.math.function.UnaryFunction;
-import org.apache.mahout.math.function.BinaryFunction;
+import org.apache.mahout.math.function.DoubleFunction;
+import org.apache.mahout.math.function.DoubleDoubleFunction;
 import org.apache.mahout.math.function.IntIntDoubleFunction;
-import org.apache.mahout.math.list.DoubleArrayList;
-import org.apache.mahout.math.list.IntArrayList;
 import org.apache.mahout.math.matrix.impl.AbstractMatrix2D;
 import org.apache.mahout.math.matrix.impl.DenseDoubleMatrix1D;
 import org.apache.mahout.math.matrix.impl.DenseDoubleMatrix2D;
 
 /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
 @Deprecated
-public abstract class DoubleMatrix2D extends AbstractMatrix2D {
+public abstract class DoubleMatrix2D extends AbstractMatrix2D implements Cloneable {
 
   /** Makes this class non instantiable, but still let's others inherit from it. */
   protected DoubleMatrix2D() {
@@ -48,8 +46,8 @@ public abstract class DoubleMatrix2D ext
    * @return the aggregated measure.
    * @see org.apache.mahout.math.function.Functions
    */
-  public double aggregate(BinaryFunction aggr,
-                          UnaryFunction f) {
+  public double aggregate(DoubleDoubleFunction aggr,
+                          DoubleFunction f) {
     if (size() == 0) {
       return Double.NaN;
     }
@@ -95,8 +93,8 @@ public abstract class DoubleMatrix2D ext
    * @throws IllegalArgumentException if <tt>columns() != other.columns() || rows() != other.rows()</tt>
    * @see org.apache.mahout.math.function.Functions
    */
-  public double aggregate(DoubleMatrix2D other, BinaryFunction aggr,
-                          BinaryFunction f) {
+  public double aggregate(DoubleMatrix2D other, DoubleDoubleFunction aggr,
+                          DoubleDoubleFunction f) {
     checkShape(other);
     if (size() == 0) {
       return Double.NaN;
@@ -118,11 +116,10 @@ public abstract class DoubleMatrix2D ext
    * are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa.
    *
    * @param values the values to be filled into the cells.
-   * @return <tt>this</tt> (for convenience only).
    * @throws IllegalArgumentException if <tt>values.length != rows() || for any 0 &lt;= row &lt; rows():
    *                                  values[row].length != columns()</tt>.
    */
-  public DoubleMatrix2D assign(double[][] values) {
+  public void assign(double[][] values) {
     if (values.length != rows) {
       throw new IllegalArgumentException("Must have same number of rows: rows=" + values.length + "rows()=" + rows());
     }
@@ -136,7 +133,6 @@ public abstract class DoubleMatrix2D ext
         setQuick(row, column, currentRow[column]);
       }
     }
-    return this;
   }
 
   /**
@@ -175,16 +171,14 @@ public abstract class DoubleMatrix2D ext
    * For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
    *
    * @param function a function object taking as argument the current cell's value.
-   * @return <tt>this</tt> (for convenience only).
    * @see org.apache.mahout.math.function.Functions
    */
-  public DoubleMatrix2D assign(UnaryFunction function) {
+  public void assign(DoubleFunction function) {
     for (int row = rows; --row >= 0;) {
       for (int column = columns; --column >= 0;) {
         setQuick(row, column, function.apply(getQuick(row, column)));
       }
     }
-    return this;
   }
 
   /**
@@ -244,7 +238,7 @@ public abstract class DoubleMatrix2D ext
    * @throws IllegalArgumentException if <tt>columns() != other.columns() || rows() != other.rows()</tt>
    * @see org.apache.mahout.math.function.Functions
    */
-  public DoubleMatrix2D assign(DoubleMatrix2D y, BinaryFunction function) {
+  public DoubleMatrix2D assign(DoubleMatrix2D y, DoubleDoubleFunction function) {
     checkShape(y);
     for (int row = rows; --row >= 0;) {
       for (int column = columns; --column >= 0;) {
@@ -318,9 +312,8 @@ public abstract class DoubleMatrix2D ext
    * Parameters to function are as follows: <tt>first==row</tt>, <tt>second==column</tt>, <tt>third==nonZeroValue</tt>.
    *
    * @param function a function object taking as argument the current non-zero cell's row, column and value.
-   * @return <tt>this</tt> (for convenience only).
    */
-  public DoubleMatrix2D forEachNonZero(IntIntDoubleFunction function) {
+  public void forEachNonZero(IntIntDoubleFunction function) {
     for (int row = rows; --row >= 0;) {
       for (int column = columns; --column >= 0;) {
         double value = getQuick(row, column);
@@ -332,7 +325,6 @@ public abstract class DoubleMatrix2D ext
         }
       }
     }
-    return this;
   }
 
   /**
@@ -359,46 +351,6 @@ public abstract class DoubleMatrix2D ext
   }
 
   /**
-   * Fills the coordinates and values of cells having non-zero values into the specified lists. Fills into the lists,
-   * starting at index 0. After this call returns the specified lists all have a new size, the number of non-zero
-   * values. <p> In general, fill order is <i>unspecified</i>. This implementation fills like <tt>for (row = 0..rows-1)
-   * for (column = 0..columns-1) do ... </tt>. However, subclasses are free to us any other order, even an order that
-   * may change over time as cell values are changed. (Of course, result lists indexes are guaranteed to correspond to
-   * the same cell). <p> <b>Example:</b> <br>
-   * <pre>
-   * 2 x 3 matrix:
-   * 0, 0, 8
-   * 0, 7, 0
-   * -->
-   * rowList    = (0,1)
-   * columnList = (2,1)
-   * valueList  = (8,7)
-   * </pre>
-   * In other words, <tt>get(0,2)==8, get(1,1)==7</tt>.
-   *
-   * @param rowList    the list to be filled with row indexes, can have any size.
-   * @param columnList the list to be filled with column indexes, can have any size.
-   * @param valueList  the list to be filled with values, can have any size.
-   */
-  public void getNonZeros(IntArrayList rowList, IntArrayList columnList, DoubleArrayList valueList) {
-    rowList.clear();
-    columnList.clear();
-    valueList.clear();
-    int r = rows;
-    int c = columns;
-    for (int row = 0; row < r; row++) {
-      for (int column = 0; column < c; column++) {
-        double value = getQuick(row, column);
-        if (value != 0) {
-          rowList.add(row);
-          columnList.add(column);
-          valueList.add(value);
-        }
-      }
-    }
-  }
-
-  /**
    * Returns the matrix cell value at coordinate <tt>[row,column]</tt>.
    *
    * <p>Provided with invalid parameters this method may return invalid objects without throwing any exception. <b>You
@@ -532,7 +484,11 @@ public abstract class DoubleMatrix2D ext
    * @return a new view of the receiver.
    */
   protected DoubleMatrix2D view() {
-    return (DoubleMatrix2D) clone();
+    try {
+      return (DoubleMatrix2D) clone();
+    } catch (CloneNotSupportedException cnse) {
+      throw new IllegalStateException();
+    }
   }
 
   /**
@@ -735,6 +691,7 @@ public abstract class DoubleMatrix2D ext
    * @param condition The condition to be matched.
    * @return the new view.
    */
+  /*
   public DoubleMatrix2D viewSelection(DoubleMatrix1DProcedure condition) {
     IntArrayList matches = new IntArrayList();
     for (int i = 0; i < rows; i++) {
@@ -746,6 +703,7 @@ public abstract class DoubleMatrix2D ext
     matches.trimToSize();
     return viewSelection(matches.elements(), null); // take all columns
   }
+   */
 
   /**
    * Construct and returns a new selection view.
@@ -756,108 +714,6 @@ public abstract class DoubleMatrix2D ext
    */
   protected abstract DoubleMatrix2D viewSelectionLike(int[] rowOffsets, int[] columnOffsets);
 
-  /**
-   * Constructs and returns a new <i>stride view</i> which is a sub matrix consisting of every i-th cell. More
-   * specifically, the view has <tt>this.rows()/rowStride</tt> rows and <tt>this.columns()/columnStride</tt> columns
-   * holding cells <tt>this.get(i*rowStride,j*columnStride)</tt> for all <tt>i = 0..rows()/rowStride - 1, j =
-   * 0..columns()/columnStride - 1</tt>. The returned view is backed by this matrix, so changes in the returned view are
-   * reflected in this matrix, and vice-versa.
-   *
-   * @param rowStride    the row step factor.
-   * @param columnStride the column step factor.
-   * @return a new view.
-   * @throws IndexOutOfBoundsException if <tt>rowStride<=0 || columnStride<=0</tt>.
-   */
-  public DoubleMatrix2D viewStrides(int rowStride, int columnStride) {
-    return (DoubleMatrix2D) (view().vStrides(rowStride, columnStride));
-  }
-
-  /**
-   * 8 neighbor stencil transformation. For efficient finite difference operations. Applies a function to a moving <tt>3
-   * x 3</tt> window. Does nothing if <tt>rows() < 3 || columns() < 3</tt>.
-   * <pre>
-   * B[i,j] = function.apply(
-   * &nbsp;&nbsp;&nbsp;A[i-1,j-1], A[i-1,j], A[i-1,j+1],
-   * &nbsp;&nbsp;&nbsp;A[i,  j-1], A[i,  j], A[i,  j+1],
-   * &nbsp;&nbsp;&nbsp;A[i+1,j-1], A[i+1,j], A[i+1,j+1]
-   * &nbsp;&nbsp;&nbsp;)
-   *
-   * x x x - &nbsp;&nbsp;&nbsp; - x x x &nbsp;&nbsp;&nbsp; - - - -
-   * x o x - &nbsp;&nbsp;&nbsp; - x o x &nbsp;&nbsp;&nbsp; - - - -
-   * x x x - &nbsp;&nbsp;&nbsp; - x x x ... - x x x
-   * - - - - &nbsp;&nbsp;&nbsp; - - - - &nbsp;&nbsp;&nbsp; - x o x
-   * - - - - &nbsp;&nbsp;&nbsp; - - - - &nbsp;&nbsp;&nbsp; - x x x
-   * </pre>
-   * Make sure that cells of <tt>this</tt> and <tt>B</tt> do not overlap. In case of overlapping views, behaviour is
-   * unspecified. </pre> <p> <b>Example:</b> <pre> final double alpha = 0.25; final double beta = 0.75;
-   *
-   * // 8 neighbors org.apache.mahout.math.function.Double9Function f = new Double9Function() {
-   * &nbsp;&nbsp;&nbsp;public final double apply( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double a00, double a01, double
-   * a02, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double a10, double a11, double a12,
-   * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double
-   * a20, double a21, double a22) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return beta*a11 +
-   * alpha*(a00+a01+a02 + a10+a12 + a20+a21+a22); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} }; A.zAssign8Neighbors(B,f);
-   *
-   * // 4 neighbors org.apache.mahout.math.function.Double9Function g = new Double9Function() {
-   * &nbsp;&nbsp;&nbsp;public final double apply( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double a00, double a01, double
-   * a02, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double a10, double a11, double a12,
-   * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double
-   * a20, double a21, double a22) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return beta*a11 + alpha*(a01+a10+a12+a21);
-   * &nbsp;&nbsp;&nbsp;} C.zAssign8Neighbors(B,g); // fast, even though it doesn't look like it }; </pre>
-   *
-   * @param B        the matrix to hold the results.
-   * @param function the function to be applied to the 9 cells.
-   * @throws NullPointerException     if <tt>function==null</tt>.
-   * @throws IllegalArgumentException if <tt>rows() != B.rows() || columns() != B.columns()</tt>.
-   */
-  public void zAssign8Neighbors(DoubleMatrix2D B, org.apache.mahout.math.function.Double9Function function) {
-    if (function == null) {
-      throw new IllegalArgumentException("function must not be null.");
-    }
-    checkShape(B);
-    if (rows < 3 || columns < 3) {
-      return;
-    } // nothing to do
-    int r = rows - 1;
-    int c = columns - 1;
-    for (int i = 1; i < r; i++) {
-      double a00 = getQuick(i - 1, 0);
-      double a01 = getQuick(i - 1, 1);
-      double a10 = getQuick(i, 0);
-      double a11 = getQuick(i, 1);
-      double a20 = getQuick(i + 1, 0);
-      double a21 = getQuick(i + 1, 1);
-
-      for (int j = 1; j < c; j++) {
-        // in each step six cells can be remembered in registers - they don't need to be reread from slow memory
-        // in each step 3 instead of 9 cells need to be read from memory.
-        double a02 = getQuick(i - 1, j + 1);
-        double a12 = getQuick(i, j + 1);
-        double a22 = getQuick(i + 1, j + 1);
-
-        B.setQuick(i, j, function.apply(
-            a00, a01, a02,
-            a10, a11, a12,
-            a20, a21, a22));
-
-        a00 = a01;
-        a10 = a11;
-        a20 = a21;
-
-        a01 = a02;
-        a11 = a12;
-        a21 = a22;
-      }
-    }
-  }
-
-  /**
-   * Linear algebraic matrix-vector multiplication; <tt>z = A * y</tt>;
-   * Equivalent to <tt>return A.zMult(y,z,1,0);</tt>
-   */
-  public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z) {
-    return zMult(y, z, 1, z == null ? 1 : 0, false);
-  }
 
   /**
    * Linear algebraic matrix-vector multiplication; <tt>z = alpha * A * y + beta*z</tt>. <tt>z[i] = alpha*Sum(A[i,j] *
@@ -893,14 +749,6 @@ public abstract class DoubleMatrix2D ext
   }
 
   /**
-   * Linear algebraic matrix-matrix multiplication; <tt>C = A x B</tt>; Equivalent to
-   * <tt>A.zMult(B,C,1,0,false,false)</tt>.
-   */
-  public DoubleMatrix2D zMult(DoubleMatrix2D B, DoubleMatrix2D C) {
-    return zMult(B, C, 1, C == null ? 1 : 0, false, false);
-  }
-
-  /**
    * Linear algebraic matrix-matrix multiplication; <tt>C = alpha * A x B + beta*C</tt>. <tt>C[i,j] = alpha*Sum(A[i,k] *
    * B[k,j]) + beta*C[i,j], k=0..n-1</tt>. <br> Matrix shapes: <tt>A(m x n), B(n x p), C(m x p)</tt>. <br> Note: Matrix
    * shape conformance is checked <i>after</i> potential transpositions.

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix.java Sat Jan  8 13:49:07 2011
@@ -8,8 +8,6 @@ It is provided "as is" without expressed
 */
 package org.apache.mahout.math.matrix.impl;
 
-import org.apache.mahout.math.PersistentObject;
-
 /**
  Abstract base class for arbitrary-dimensional matrices holding objects or primitive data types such as <code>int</code>, <code>float</code>, etc.
  First see the <a href="package-summary.html">package summary</a> and javadoc <a href="package-tree.html">tree view</a> to get the broad picture.
@@ -22,12 +20,10 @@ import org.apache.mahout.math.Persistent
 
 /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
 @Deprecated
-public abstract class AbstractMatrix extends PersistentObject {
+public abstract class AbstractMatrix {
 
   protected boolean isNoView = true;
 
-  //public static boolean debug = true;
-
   /** Makes this class non instantiable, but still let's others inherit from it. */
   protected AbstractMatrix() {
   }
@@ -42,18 +38,7 @@ public abstract class AbstractMatrix ext
   public void ensureCapacity(int minNonZeros) {
   }
 
-  /** Returns whether the receiver is a view or not. */
-  protected boolean isView() {
-    return !this.isNoView;
-  }
-
   /** Returns the number of cells. */
   public abstract int size();
 
-  /**
-   * Releases any superfluous internal memory. An application can use this operation to minimize the storage of the
-   * receiver. <p> This default implementation does nothing. Override this method if necessary.
-   */
-  public void trimToSize() {
-  }
 }

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix1D.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix1D.java Sat Jan  8 13:49:07 2011
@@ -26,11 +26,8 @@ public abstract class AbstractMatrix1D e
 
   /** the number of cells this matrix (view) has */
   protected int size;
-
-
   /** the index of the first element */
   protected int zero;
-
   /** the number of indexes between any two elements, i.e. <tt>index(i+1) - index(i)</tt>. */
   protected int stride;
 
@@ -73,20 +70,6 @@ public abstract class AbstractMatrix1D e
   }
 
   /**
-   * Checks whether indexes are legal and throws an exception, if necessary.
-   *
-   * @throws IndexOutOfBoundsException if <tt>! (0 <= indexes[i] < size())</tt> for any i=0..indexes.length()-1.
-   */
-  protected void checkIndexes(int[] indexes) {
-    for (int i = indexes.length; --i >= 0;) {
-      int index = indexes[i];
-      if (index < 0 || index >= size) {
-        checkIndex(index);
-      }
-    }
-  }
-
-  /**
    * Checks whether the receiver contains the given range and throws an exception, if necessary.
    *
    * @throws IndexOutOfBoundsException if <tt>index<0 || index+width>size()</tt>.
@@ -102,17 +85,6 @@ public abstract class AbstractMatrix1D e
    *
    * @throws IllegalArgumentException if <tt>size() != b.size()</tt>.
    */
-  protected void checkSize(double[] b) {
-    if (size != b.length) {
-      throw new IllegalArgumentException("Incompatible sizes: " + size + " and " + b.length);
-    }
-  }
-
-  /**
-   * Sanity check for operations requiring two matrices with the same size.
-   *
-   * @throws IllegalArgumentException if <tt>size() != b.size()</tt>.
-   */
   public void checkSize(AbstractMatrix1D b) {
     if (size != b.size) {
       throw new IllegalArgumentException("Incompatible sizes: " + size + " and " + b.size);
@@ -178,19 +150,6 @@ public abstract class AbstractMatrix1D e
   }
 
   /**
-   * Self modifying version of viewFlip(). What used to be index <tt>0</tt> is now index <tt>size()-1</tt>, ..., what
-   * used to be index <tt>size()-1</tt> is now index <tt>0</tt>.
-   */
-  protected AbstractMatrix1D vFlip() {
-    if (size > 0) {
-      this.zero += (this.size - 1) * this.stride;
-      this.stride = -this.stride;
-      this.isNoView = false;
-    }
-    return this;
-  }
-
-  /**
    * Self modifying version of viewPart().
    *
    * @throws IndexOutOfBoundsException if <tt>index<0 || index+width>size()</tt>.
@@ -203,20 +162,4 @@ public abstract class AbstractMatrix1D e
     return this;
   }
 
-  /**
-   * Self modifying version of viewStrides().
-   *
-   * @throws IndexOutOfBoundsException if <tt>stride <= 0</tt>.
-   */
-  protected AbstractMatrix1D vStrides(int stride) {
-    if (stride <= 0) {
-      throw new IndexOutOfBoundsException("illegal stride: " + stride);
-    }
-    this.stride *= stride;
-    if (this.size != 0) {
-      this.size = (this.size - 1) / stride + 1;
-    }
-    this.isNoView = false;
-    return this;
-  }
 }

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix2D.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/AbstractMatrix2D.java Sat Jan  8 13:49:07 2011
@@ -162,18 +162,6 @@ public abstract class AbstractMatrix2D e
     }
   }
 
-  /**
-   * Sanity check for operations requiring matrices with the same number of columns and rows.
-   *
-   * @throws IllegalArgumentException if <tt>columns() != B.columns() || rows() != B.rows() || columns() != C.columns()
-   *                                  || rows() != C.rows()</tt>.
-   */
-  public void checkShape(AbstractMatrix2D B, AbstractMatrix2D C) {
-    if (columns != B.columns || rows != B.rows || columns != C.columns || rows != C.rows) {
-      throw new IllegalArgumentException("Incompatible dimensions");
-    }
-  }
-
   /** Returns the number of columns. */
   public int columns() {
     return columns;
@@ -297,24 +285,4 @@ public abstract class AbstractMatrix2D e
     return this;
   }
 
-  /**
-   * Self modifying version of viewStrides().
-   *
-   * @throws IndexOutOfBoundsException if <tt>rowStride<=0 || columnStride<=0</tt>.
-   */
-  protected AbstractMatrix2D vStrides(int rowStride, int columnStride) {
-    if (rowStride <= 0 || columnStride <= 0) {
-      throw new IndexOutOfBoundsException("illegal strides: " + rowStride + ", " + columnStride);
-    }
-    this.rowStride *= rowStride;
-    this.columnStride *= columnStride;
-    if (this.rows != 0) {
-      this.rows = (this.rows - 1) / rowStride + 1;
-    }
-    if (this.columns != 0) {
-      this.columns = (this.columns - 1) / columnStride + 1;
-    }
-    this.isNoView = false;
-    return this;
-  }
 }

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix1D.java Sat Jan  8 13:49:07 2011
@@ -8,11 +8,11 @@ It is provided "as is" without expressed
 */
 package org.apache.mahout.math.matrix.impl;
 
-import org.apache.mahout.math.function.BinaryFunction;
+import org.apache.mahout.math.function.DoubleDoubleFunction;
 import org.apache.mahout.math.function.Functions;
 import org.apache.mahout.math.function.Mult;
 import org.apache.mahout.math.function.PlusMult;
-import org.apache.mahout.math.function.UnaryFunction;
+import org.apache.mahout.math.function.DoubleFunction;
 import org.apache.mahout.math.matrix.DoubleMatrix1D;
 import org.apache.mahout.math.matrix.DoubleMatrix2D;
 
@@ -66,11 +66,10 @@ public class DenseDoubleMatrix1D extends
    * matrix, and vice-versa.
    *
    * @param values the values to be filled into the cells.
-   * @return <tt>this</tt> (for convenience only).
    * @throws IllegalArgumentException if <tt>values.length != size()</tt>.
    */
   @Override
-  public DoubleMatrix1D assign(double[] values) {
+  public void assign(double[] values) {
     if (isNoView) {
       if (values.length != size) {
         throw new IllegalArgumentException(
@@ -80,17 +79,15 @@ public class DenseDoubleMatrix1D extends
     } else {
       super.assign(values);
     }
-    return this;
   }
 
   /**
    * Sets all cells to the state specified by <tt>value</tt>.
    *
    * @param value the value to be filled into the cells.
-   * @return <tt>this</tt> (for convenience only).
    */
   @Override
-  public DoubleMatrix1D assign(double value) {
+  public void assign(double value) {
     int index = index(0);
     int s = this.stride;
     double[] elems = this.elements;
@@ -98,7 +95,6 @@ public class DenseDoubleMatrix1D extends
       elems[index] = value;
       index += s;
     }
-    return this;
   }
 
   /**
@@ -114,11 +110,10 @@ public class DenseDoubleMatrix1D extends
    * For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
    *
    * @param function a function object taking as argument the current cell's value.
-   * @return <tt>this</tt> (for convenience only).
    * @see org.apache.mahout.math.function.Functions
    */
   @Override
-  public DoubleMatrix1D assign(UnaryFunction function) {
+  public void assign(DoubleFunction function) {
     int s = stride;
     int i = index(0);
     double[] elems = this.elements;
@@ -130,7 +125,7 @@ public class DenseDoubleMatrix1D extends
     if (function instanceof Mult) { // x[i] = mult*x[i]
       double multiplicator = ((Mult) function).getMultiplicator();
       if (multiplicator == 1) {
-        return this;
+        return;
       }
       for (int k = size; --k >= 0;) {
         elems[i] *= multiplicator;
@@ -142,7 +137,6 @@ public class DenseDoubleMatrix1D extends
         i += s;
       }
     }
-    return this;
   }
 
   /**
@@ -208,7 +202,7 @@ public class DenseDoubleMatrix1D extends
    *
    * // for non-standard functions there is no shortcut:
    * m1.assign(m2,
-   * &nbsp;&nbsp;&nbsp;new BinaryFunction() {
+   * &nbsp;&nbsp;&nbsp;new DoubleDoubleFunction() {
    * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public double apply(double x, double y) { return Math.pow(x,y); }
    * &nbsp;&nbsp;&nbsp;}
    * );
@@ -223,7 +217,7 @@ public class DenseDoubleMatrix1D extends
    * @see org.apache.mahout.math.function.Functions
    */
   @Override
-  public DoubleMatrix1D assign(DoubleMatrix1D y, BinaryFunction function) {
+  public DoubleMatrix1D assign(DoubleMatrix1D y, DoubleDoubleFunction function) {
     // overriden for performance only
     if (!(y instanceof DenseDoubleMatrix1D)) {
       return super.assign(y, function);

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/DenseDoubleMatrix2D.java Sat Jan  8 13:49:07 2011
@@ -8,10 +8,10 @@ It is provided "as is" without expressed
 */
 package org.apache.mahout.math.matrix.impl;
 
-import org.apache.mahout.math.function.BinaryFunction;
+import org.apache.mahout.math.function.DoubleDoubleFunction;
 import org.apache.mahout.math.function.Functions;
 import org.apache.mahout.math.function.Mult;
-import org.apache.mahout.math.function.UnaryFunction;
+import org.apache.mahout.math.function.DoubleFunction;
 import org.apache.mahout.math.function.PlusMult;
 import org.apache.mahout.math.matrix.DoubleMatrix1D;
 import org.apache.mahout.math.matrix.DoubleMatrix2D;
@@ -53,24 +53,13 @@ public final class DenseDoubleMatrix2D e
     this.elements = new double[rows * columns];
   }
 
-  /**
-   * Constructs a view with the given parameters.
-   *
-   * @param rows         the number of rows the matrix shall have.
-   * @param columns      the number of columns the matrix shall have.
-   * @param elements     the cells.
-   * @param rowZero      the position of the first element.
-   * @param columnZero   the position of the first element.
-   * @param rowStride    the number of elements between two rows, i.e. <tt>index(i+1,j)-index(i,j)</tt>.
-   * @param columnStride the number of elements between two columns, i.e. <tt>index(i,j+1)-index(i,j)</tt>.
-   * @throws IllegalArgumentException if <tt>rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE</tt> or
-   *                                  flip's are illegal.
-   */
-  DenseDoubleMatrix2D(int rows, int columns, double[] elements, int rowZero, int columnZero, int rowStride,
-                                int columnStride) {
-    setUp(rows, columns, rowZero, columnZero, rowStride, columnStride);
-    this.elements = elements;
-    this.isNoView = false;
+  /** Constructs an identity matrix (having ones on the diagonal and zeros elsewhere). */
+  public static DoubleMatrix2D identity(int rowsAndColumns) {
+    DoubleMatrix2D matrix = new DenseDoubleMatrix2D(rowsAndColumns, rowsAndColumns);
+    for (int i = rowsAndColumns; --i >= 0;) {
+      matrix.setQuick(i, i, 1);
+    }
+    return matrix;
   }
 
   /**
@@ -79,12 +68,11 @@ public final class DenseDoubleMatrix2D e
    * are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa.
    *
    * @param values the values to be filled into the cells.
-   * @return <tt>this</tt> (for convenience only).
    * @throws IllegalArgumentException if <tt>values.length != rows() || for any 0 &lt;= row &lt; rows():
    *                                  values[row].length != columns()</tt>.
    */
   @Override
-  public DoubleMatrix2D assign(double[][] values) {
+  public void assign(double[][] values) {
     if (this.isNoView) {
       if (values.length != rows) {
         throw new IllegalArgumentException("Must have same number of rows: rows=" + values.length + "rows()=" + rows());
@@ -102,7 +90,6 @@ public final class DenseDoubleMatrix2D e
     } else {
       super.assign(values);
     }
-    return this;
   }
 
   /**
@@ -144,11 +131,10 @@ public final class DenseDoubleMatrix2D e
    * For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
    *
    * @param function a function object taking as argument the current cell's value.
-   * @return <tt>this</tt> (for convenience only).
    * @see org.apache.mahout.math.function.Functions
    */
   @Override
-  public DoubleMatrix2D assign(UnaryFunction function) {
+  public void assign(DoubleFunction function) {
     double[] elems = this.elements;
     if (elems == null) {
       throw new IllegalStateException();
@@ -161,10 +147,11 @@ public final class DenseDoubleMatrix2D e
     if (function instanceof Mult) { // x[i] = mult*x[i]
       double multiplicator = ((Mult) function).getMultiplicator();
       if (multiplicator == 1) {
-        return this;
+        return;
       }
       if (multiplicator == 0) {
-        return assign(0);
+        assign(0);
+        return;
       }
       for (int row = rows; --row >= 0;) { // the general case
         for (int i = index, column = columns; --column >= 0;) {
@@ -182,7 +169,6 @@ public final class DenseDoubleMatrix2D e
         index += rs;
       }
     }
-    return this;
   }
 
   /**
@@ -273,7 +259,7 @@ public final class DenseDoubleMatrix2D e
    * @see org.apache.mahout.math.function.Functions
    */
   @Override
-  public DoubleMatrix2D assign(DoubleMatrix2D y, BinaryFunction function) {
+  public DoubleMatrix2D assign(DoubleMatrix2D y, DoubleDoubleFunction function) {
     // overriden for performance only
     if (!(y instanceof DenseDoubleMatrix2D)) {
       return super.assign(y, function);
@@ -492,123 +478,6 @@ public final class DenseDoubleMatrix2D e
     return new SelectedDenseDoubleMatrix2D(this.elements, rowOffsets, columnOffsets, 0);
   }
 
-  /**
-   * 8 neighbor stencil transformation. For efficient finite difference operations. Applies a function to a moving <tt>3
-   * x 3</tt> window. Does nothing if <tt>rows() < 3 || columns() < 3</tt>.
-   * <pre>
-   * B[i,j] = function.apply(
-   * &nbsp;&nbsp;&nbsp;A[i-1,j-1], A[i-1,j], A[i-1,j+1],
-   * &nbsp;&nbsp;&nbsp;A[i,  j-1], A[i,  j], A[i,  j+1],
-   * &nbsp;&nbsp;&nbsp;A[i+1,j-1], A[i+1,j], A[i+1,j+1]
-   * &nbsp;&nbsp;&nbsp;)
-   *
-   * x x x - &nbsp;&nbsp;&nbsp; - x x x &nbsp;&nbsp;&nbsp; - - - -
-   * x o x - &nbsp;&nbsp;&nbsp; - x o x &nbsp;&nbsp;&nbsp; - - - -
-   * x x x - &nbsp;&nbsp;&nbsp; - x x x ... - x x x
-   * - - - - &nbsp;&nbsp;&nbsp; - - - - &nbsp;&nbsp;&nbsp; - x o x
-   * - - - - &nbsp;&nbsp;&nbsp; - - - - &nbsp;&nbsp;&nbsp; - x x x
-   * </pre>
-   * Make sure that cells of <tt>this</tt> and <tt>B</tt> do not overlap. In case of overlapping views, behaviour is
-   * unspecified. </pre> <p> <b>Example:</b> <pre> final double alpha = 0.25; final double beta = 0.75;
-   *
-   * // 8 neighbors org.apache.mahout.math.function.Double9Function f = new Double9Function() {
-   * &nbsp;&nbsp;&nbsp;public final double apply( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double a00, double a01, double
-   * a02, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double a10, double a11, double a12,
-   * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double
-   * a20, double a21, double a22) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return beta*a11 +
-   * alpha*(a00+a01+a02 + a10+a12 + a20+a21+a22); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} }; A.zAssign8Neighbors(B,f);
-   *
-   * // 4 neighbors org.apache.mahout.math.function.Double9Function g = new Double9Function() {
-   * &nbsp;&nbsp;&nbsp;public final double apply( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double a00, double a01, double
-   * a02, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double a10, double a11, double a12,
-   * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double
-   * a20, double a21, double a22) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return beta*a11 + alpha*(a01+a10+a12+a21);
-   * &nbsp;&nbsp;&nbsp;} C.zAssign8Neighbors(B,g); // fast, even though it doesn't look like it }; </pre>
-   *
-   * @param B        the matrix to hold the results.
-   * @param function the function to be applied to the 9 cells.
-   * @throws NullPointerException     if <tt>function==null</tt>.
-   * @throws IllegalArgumentException if <tt>rows() != B.rows() || columns() != B.columns()</tt>.
-   */
-  @Override
-  public void zAssign8Neighbors(DoubleMatrix2D B, org.apache.mahout.math.function.Double9Function function) {
-    // 1. using only 4-5 out of the 9 cells in "function" is *not* the limiting factor for performance.
-
-    // 2. if the "function" would be hardwired into the innermost loop, a speedup of 1.5-2.0 would be seen
-    // but then the multi-purpose interface is gone...
-
-    if (!(B instanceof DenseDoubleMatrix2D)) {
-      super.zAssign8Neighbors(B, function);
-      return;
-    }
-    if (function == null) {
-      throw new IllegalArgumentException("function must not be null.");
-    }
-    checkShape(B);
-    int r = rows - 1;
-    int c = columns - 1;
-    if (rows < 3 || columns < 3) {
-      return;
-    } // nothing to do
-
-    DenseDoubleMatrix2D BB = (DenseDoubleMatrix2D) B;
-    int A_rs = rowStride;
-    int B_rs = BB.rowStride;
-    int A_cs = columnStride;
-    int B_cs = BB.columnStride;
-    double[] elems = this.elements;
-    double[] B_elems = BB.elements;
-    if (elems == null || B_elems == null) {
-      throw new IllegalStateException();
-    }
-
-    int A_index = index(1, 1);
-    int B_index = BB.index(1, 1);
-    for (int i = 1; i < r; i++) {
-
-      int B11 = B_index;
-
-      int A02 = A_index - A_rs - A_cs;
-      int A12 = A02 + A_rs;
-      int A22 = A12 + A_rs;
-
-      // in each step six cells can be remembered in registers - they don't need to be reread from slow memory
-      double a00 = elems[A02];
-      A02 += A_cs;
-      double a01 = elems[A02];
-      double a10 = elems[A12];
-      A12 += A_cs;
-      double a11 = elems[A12];
-      double a20 = elems[A22];
-      A22 += A_cs;
-      double a21 = elems[A22];
-
-      for (int j = 1; j < c; j++) {
-        //in each step 3 instead of 9 cells need to be read from memory.
-        double a02 = elems[A02 += A_cs];
-        double a12 = elems[A12 += A_cs];
-        double a22 = elems[A22 += A_cs];
-
-        B_elems[B11] = function.apply(
-            a00, a01, a02,
-            a10, a11, a12,
-            a20, a21, a22);
-        B11 += B_cs;
-
-        // move remembered cells
-        a00 = a01;
-        a01 = a02;
-        a10 = a11;
-        a11 = a12;
-        a20 = a21;
-        a21 = a22;
-      }
-      A_index += A_rs;
-      B_index += B_rs;
-    }
-
-  }
-
   @Override
   public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, boolean transposeA) {
     if (transposeA) {

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix1D.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix1D.java Sat Jan  8 13:49:07 2011
@@ -80,17 +80,15 @@ public final class SparseDoubleMatrix1D 
    * Sets all cells to the state specified by <tt>value</tt>.
    *
    * @param value the value to be filled into the cells.
-   * @return <tt>this</tt> (for convenience only).
    */
   @Override
-  public DoubleMatrix1D assign(double value) {
+  public void assign(double value) {
     // overriden for performance only
     if (this.isNoView && value == 0) {
       this.elements.clear();
     } else {
       super.assign(value);
     }
-    return this;
   }
 
   /** Returns the number of cells having non-zero values. */
@@ -211,22 +209,6 @@ public final class SparseDoubleMatrix1D 
   }
 
   /**
-   * Releases any superfluous memory created by explicitly putting zero values into cells formerly having non-zero
-   * values; An application can use this operation to minimize the storage of the receiver. <p> <b>Background:</b> <p>
-   * Cells that <ul> <li>are never set to non-zero values do not use any memory. <li>switch from zero to non-zero state
-   * do use memory. <li>switch back from non-zero to zero state also do use memory. However, their memory can be
-   * reclaimed by calling <tt>trimToSize()</tt>. </ul> A sequence like <tt>set(i,5); set(i,0);</tt> sets a cell to
-   * non-zero state and later back to zero state. Such as sequence generates obsolete memory that is automatically
-   * reclaimed from time to time or can manually be reclaimed by calling <tt>trimToSize()</tt>. Putting zeros into cells
-   * already containing zeros does not generate obsolete memory since no memory was allocated to them in the first
-   * place.
-   */
-  @Override
-  public void trimToSize() {
-    this.elements.trimToSize();
-  }
-
-  /**
    * Construct and returns a new selection view.
    *
    * @param offsets the offsets of the visible elements.

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/SparseDoubleMatrix2D.java Sat Jan  8 13:49:07 2011
@@ -8,10 +8,10 @@ It is provided "as is" without expressed
 */
 package org.apache.mahout.math.matrix.impl;
 
-import org.apache.mahout.math.function.BinaryFunction;
+import org.apache.mahout.math.function.DoubleDoubleFunction;
 import org.apache.mahout.math.function.Functions;
 import org.apache.mahout.math.function.PlusMult;
-import org.apache.mahout.math.function.UnaryFunction;
+import org.apache.mahout.math.function.DoubleFunction;
 import org.apache.mahout.math.function.IntDoubleProcedure;
 import org.apache.mahout.math.function.IntIntDoubleFunction;
 import org.apache.mahout.math.function.Mult;
@@ -75,26 +75,6 @@ public final class SparseDoubleMatrix2D 
   }
 
   /**
-   * Constructs a view with the given parameters.
-   *
-   * @param rows         the number of rows the matrix shall have.
-   * @param columns      the number of columns the matrix shall have.
-   * @param elements     the cells.
-   * @param rowZero      the position of the first element.
-   * @param columnZero   the position of the first element.
-   * @param rowStride    the number of elements between two rows, i.e. <tt>index(i+1,j)-index(i,j)</tt>.
-   * @param columnStride the number of elements between two columns, i.e. <tt>index(i,j+1)-index(i,j)</tt>.
-   * @throws IllegalArgumentException if <tt>rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE</tt> or
-   *                                  flip's are illegal.
-   */
-  SparseDoubleMatrix2D(int rows, int columns, AbstractIntDoubleMap elements, int rowZero, int columnZero,
-                                 int rowStride, int columnStride) {
-    setUp(rows, columns, rowZero, columnZero, rowStride, columnStride);
-    this.elements = elements;
-    this.isNoView = false;
-  }
-
-  /**
    * Sets all cells to the state specified by <tt>value</tt>.
    *
    * @param value the value to be filled into the cells.
@@ -128,17 +108,15 @@ public final class SparseDoubleMatrix2D 
    * For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
    *
    * @param function a function object taking as argument the current cell's value.
-   * @return <tt>this</tt> (for convenience only).
    * @see org.apache.mahout.math.function.Functions
    */
   @Override
-  public DoubleMatrix2D assign(UnaryFunction function) {
+  public void assign(DoubleFunction function) {
     if (this.isNoView && function instanceof Mult) { // x[i] = mult*x[i]
       this.elements.assign(function);
     } else {
       super.assign(function);
     }
-    return this;
   }
 
   /**
@@ -172,7 +150,7 @@ public final class SparseDoubleMatrix2D 
 
   @Override
   public DoubleMatrix2D assign(final DoubleMatrix2D y,
-                               BinaryFunction function) {
+                               DoubleDoubleFunction function) {
     if (!this.isNoView) {
       return super.assign(y, function);
     }
@@ -251,7 +229,7 @@ public final class SparseDoubleMatrix2D 
   }
 
   @Override
-  public DoubleMatrix2D forEachNonZero(final org.apache.mahout.math.function.IntIntDoubleFunction function) {
+  public void forEachNonZero(final org.apache.mahout.math.function.IntIntDoubleFunction function) {
     if (this.isNoView) {
       this.elements.forEachPair(
           new IntDoubleProcedure() {
@@ -269,7 +247,6 @@ public final class SparseDoubleMatrix2D 
     } else {
       super.forEachNonZero(function);
     }
-    return this;
   }
 
   /**
@@ -396,22 +373,6 @@ public final class SparseDoubleMatrix2D 
   }
 
   /**
-   * Releases any superfluous memory created by explicitly putting zero values into cells formerly having non-zero
-   * values; An application can use this operation to minimize the storage of the receiver. <p> <b>Background:</b> <p>
-   * Cells that <ul> <li>are never set to non-zero values do not use any memory. <li>switch from zero to non-zero state
-   * do use memory. <li>switch back from non-zero to zero state also do use memory. However, their memory can be
-   * reclaimed by calling <tt>trimToSize()</tt>. </ul> A sequence like <tt>set(r,c,5); set(r,c,0);</tt> sets a cell to
-   * non-zero state and later back to zero state. Such as sequence generates obsolete memory that is automatically
-   * reclaimed from time to time or can manually be reclaimed by calling <tt>trimToSize()</tt>. Putting zeros into cells
-   * already containing zeros does not generate obsolete memory since no memory was allocated to them in the first
-   * place.
-   */
-  @Override
-  public void trimToSize() {
-    this.elements.trimToSize();
-  }
-
-  /**
    * Construct and returns a new selection view.
    *
    * @param rowOffsets    the offsets of the visible elements.
@@ -538,10 +499,10 @@ public final class SparseDoubleMatrix2D 
             int i = key / columns;
             int j = key % columns;
             fun.setMultiplicator(value * alpha);
-            if (!transposeA) {
-              Crows[i].assign(Brows[j], fun);
-            } else {
+            if (transposeA) {
               Crows[j].assign(Brows[i], fun);
+            } else {
+              Crows[i].assign(Brows[j], fun);
             }
             return true;
           }

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/WrapperDoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/WrapperDoubleMatrix1D.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/WrapperDoubleMatrix1D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/WrapperDoubleMatrix1D.java Sat Jan  8 13:49:07 2011
@@ -101,28 +101,6 @@ class WrapperDoubleMatrix1D extends Doub
   }
 
   /**
-   * Constructs and returns a new <i>flip view</i>. What used to be index <tt>0</tt> is now index <tt>size()-1</tt>,
-   * ..., what used to be index <tt>size()-1</tt> is now index <tt>0</tt>. The returned view is backed by this matrix,
-   * so changes in the returned view are reflected in this matrix, and vice-versa.
-   *
-   * @return a new flip view.
-   */
-  @Override
-  public DoubleMatrix1D viewFlip() {
-    return new WrapperDoubleMatrix1D(WrapperDoubleMatrix1D.this) {
-      @Override
-      public double getQuick(int index) {
-        return content.get(size - 1 - index);
-      }
-
-      @Override
-      public void setQuick(int index, double value) {
-        content.set(size - 1 - index, value);
-      }
-    };
-  }
-
-  /**
    * Constructs and returns a new <i>sub-range view</i> that is a <tt>width</tt> sub matrix starting at <tt>index</tt>.
    *
    * Operations on the returned view can only be applied to the restricted range. Any attempt to access coordinates not
@@ -157,52 +135,6 @@ class WrapperDoubleMatrix1D extends Doub
   }
 
   /**
-   * Constructs and returns a new <i>selection view</i> that is a matrix holding the indicated cells. There holds
-   * <tt>view.size() == indexes.length</tt> and <tt>view.get(i) == this.get(indexes[i])</tt>. Indexes can occur multiple
-   * times and can be in arbitrary order. <p> <b>Example:</b> <br>
-   * <pre>
-   * this     = (0,0,8,0,7)
-   * indexes  = (0,2,4,2)
-   * -->
-   * view     = (0,8,7,8)
-   * </pre>
-   * Note that modifying <tt>indexes</tt> after this call has returned has no effect on the view. The returned view is
-   * backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa.
-   *
-   * @param indexes The indexes of the cells that shall be visible in the new view. To indicate that <i>all</i> cells
-   *                shall be visible, simply set this parameter to <tt>null</tt>.
-   * @return the new view.
-   * @throws IndexOutOfBoundsException if <tt>!(0 <= indexes[i] < size())</tt> for any <tt>i=0..indexes.length()-1</tt>.
-   */
-  @Override
-  public DoubleMatrix1D viewSelection(int[] indexes) {
-    // check for "all"
-    if (indexes == null) {
-      indexes = new int[size];
-      for (int i = size; --i >= 0;) {
-        indexes[i] = i;
-      }
-    }
-
-    checkIndexes(indexes);
-    final int[] idx = indexes;
-
-    DoubleMatrix1D view = new WrapperDoubleMatrix1D(this) {
-      @Override
-      public double getQuick(int i) {
-        return content.get(idx[i]);
-      }
-
-      @Override
-      public void setQuick(int i, double value) {
-        content.set(idx[i], value);
-      }
-    };
-    view.size = indexes.length;
-    return view;
-  }
-
-  /**
    * Construct and returns a new selection view.
    *
    * @param offsets the offsets of the visible elements.
@@ -213,35 +145,4 @@ class WrapperDoubleMatrix1D extends Doub
     throw new UnsupportedOperationException(); // should never get called
   }
 
-  /**
-   * Constructs and returns a new <i>stride view</i> which is a sub matrix consisting of every i-th cell. More
-   * specifically, the view has size <tt>this.size()/stride</tt> holding cells <tt>this.get(i*stride)</tt> for all <tt>i
-   * = 0..size()/stride - 1</tt>.
-   *
-   * @param theStride the step factor.
-   * @return the new view.
-   * @throws IndexOutOfBoundsException if <tt>stride <= 0</tt>.
-   */
-  @Override
-  public DoubleMatrix1D viewStrides(final int theStride) {
-    if (stride <= 0) {
-      throw new IndexOutOfBoundsException("illegal stride: " + stride);
-    }
-    DoubleMatrix1D view = new WrapperDoubleMatrix1D(this) {
-      @Override
-      public double getQuick(int index) {
-        return content.get(index * theStride);
-      }
-
-      @Override
-      public void setQuick(int index, double value) {
-        content.set(index * theStride, value);
-      }
-    };
-    view.size = size;
-    if (size != 0) {
-      view.size = (size - 1) / theStride + 1;
-    }
-    return view;
-  }
 }

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/WrapperDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/WrapperDoubleMatrix2D.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/WrapperDoubleMatrix2D.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/impl/WrapperDoubleMatrix2D.java Sat Jan  8 13:49:07 2011
@@ -371,42 +371,4 @@ class WrapperDoubleMatrix2D extends Doub
     throw new UnsupportedOperationException(); // should never be called
   }
 
-  /**
-   * Constructs and returns a new <i>stride view</i> which is a sub matrix consisting of every i-th cell. More
-   * specifically, the view has <tt>this.rows()/rowStride</tt> rows and <tt>this.columns()/columnStride</tt> columns
-   * holding cells <tt>this.get(i*rowStride,j*columnStride)</tt> for all <tt>i = 0..rows()/rowStride - 1, j =
-   * 0..columns()/columnStride - 1</tt>. The returned view is backed by this matrix, so changes in the returned view are
-   * reflected in this matrix, and vice-versa.
-   *
-   * @param theRowStride    the row step factor.
-   * @param theColumnStride the column step factor.
-   * @return a new view.
-   * @throws IndexOutOfBoundsException if <tt>rowStride<=0 || columnStride<=0</tt>.
-   */
-  @Override
-  public DoubleMatrix2D viewStrides(final int theRowStride, final int theColumnStride) {
-    if (theRowStride <= 0 || theColumnStride <= 0) {
-      throw new IndexOutOfBoundsException("illegal stride");
-    }
-    DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
-      @Override
-      public double getQuick(int row, int column) {
-        return content.get(theRowStride * row, theColumnStride * column);
-      }
-
-      @Override
-      public void setQuick(int row, int column, double value) {
-        content.set(theRowStride * row, theColumnStride * column, value);
-      }
-    };
-    view.rows = rows;
-    view.columns = columns;
-    if (rows != 0) {
-      view.rows = (rows - 1) / theRowStride + 1;
-    }
-    if (columns != 0) {
-      view.columns = (columns - 1) / theColumnStride + 1;
-    }
-    return view;
-  }
 }

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Algebra.java Sat Jan  8 13:49:07 2011
@@ -9,14 +9,13 @@ It is provided "as is" without expressed
 package org.apache.mahout.math.matrix.linalg;
 
 import org.apache.mahout.math.GenericPermuting;
-import org.apache.mahout.math.PersistentObject;
 import org.apache.mahout.math.Swapper;
 import org.apache.mahout.math.matrix.DoubleMatrix1D;
 import org.apache.mahout.math.matrix.DoubleMatrix2D;
 
 /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
 @Deprecated
-public final class Algebra extends PersistentObject {
+public final class Algebra {
 
   /**
    * A default Algebra object; has {@link Property#DEFAULT} attached for tolerance. Allows ommiting to construct an
@@ -65,17 +64,6 @@ public final class Algebra extends Persi
   }
 
   /**
-   * Returns a copy of the receiver. The attached property object is also copied. Hence, the property object of the copy
-   * is mutable.
-   *
-   * @return a copy of the receiver.
-   */
-  @Override
-  public Object clone() {
-    return new Algebra(property.tolerance());
-  }
-
-  /**
    * Returns the determinant of matrix <tt>A</tt>.
    *
    * @return the determinant.
@@ -124,10 +112,9 @@ public final class Algebra extends Persi
    *                < A.size()</tt>;
    * @param work    the working storage, must satisfy <tt>work.length >= A.size()</tt>; set <tt>work==null</tt> if you
    *                don't care about performance.
-   * @return the modified <tt>A</tt> (for convenience only).
    * @throws IndexOutOfBoundsException if <tt>indexes.length != A.size()</tt>.
    */
-  public static DoubleMatrix1D permute(DoubleMatrix1D A, int[] indexes, double[] work) {
+  public static void permute(DoubleMatrix1D A, int[] indexes, double[] work) {
     // check validity
     int size = A.size();
     if (indexes.length != size) {
@@ -150,36 +137,6 @@ public final class Algebra extends Persi
     for (int i = size; --i >= 0;) {
       A.setQuick(i, work[indexes[i]]);
     }
-    return A;
-  }
-
-  /**
-   * Constructs and returns a new row and column permuted <i>selection view</i> of matrix <tt>A</tt>; equivalent to
-   * {@link DoubleMatrix2D#viewSelection(int[],int[])}. The returned matrix is backed by this matrix, so changes in the
-   * returned matrix are reflected in this matrix, and vice-versa. Use idioms like <tt>result = permute(...).copy()</tt>
-   * to generate an independent sub matrix.
-   *
-   * @return the new permuted selection view.
-   */
-  public static DoubleMatrix2D permute(DoubleMatrix2D A, int[] rowIndexes, int[] columnIndexes) {
-    return A.viewSelection(rowIndexes, columnIndexes);
-  }
-
-  /**
-   * Modifies the given matrix <tt>A</tt> such that it's columns are permuted as specified; Useful for pivoting. Column
-   * <tt>A[i]</tt> will go into column <tt>A[indexes[i]]</tt>. Equivalent to <tt>permuteRows(transpose(A), indexes,
-   * work)</tt>.
-   *
-   * @param A       the matrix to permute.
-   * @param indexes the permutation indexes, must satisfy <tt>indexes.length==A.columns() && indexes[i] >= 0 &&
-   *                indexes[i] < A.columns()</tt>;
-   * @param work    the working storage, must satisfy <tt>work.length >= A.columns()</tt>; set <tt>work==null</tt> if
-   *                you don't care about performance.
-   * @return the modified <tt>A</tt> (for convenience only).
-   * @throws IndexOutOfBoundsException if <tt>indexes.length != A.columns()</tt>.
-   */
-  public static DoubleMatrix2D permuteColumns(DoubleMatrix2D A, int[] indexes, int[] work) {
-    return permuteRows(A.viewDice(), indexes, work);
   }
 
   /**
@@ -202,10 +159,9 @@ public final class Algebra extends Persi
    *                < A.rows()</tt>;
    * @param work    the working storage, must satisfy <tt>work.length >= A.rows()</tt>; set <tt>work==null</tt> if you
    *                don't care about performance.
-   * @return the modified <tt>A</tt> (for convenience only).
    * @throws IndexOutOfBoundsException if <tt>indexes.length != A.rows()</tt>.
    */
-  public static DoubleMatrix2D permuteRows(final DoubleMatrix2D A, int[] indexes, int[] work) {
+  public static void permuteRows(final DoubleMatrix2D A, int[] indexes, int[] work) {
     // check validity
     int size = A.rows();
     if (indexes.length != size) {
@@ -226,7 +182,7 @@ public final class Algebra extends Persi
       for (int j = A.columns(); --j >= 0;) {
         permute(A.viewColumn(j), indexes, doubleWork);
       }
-      return A;
+      return;
     }
 
     Swapper swapper = new Swapper() {
@@ -236,7 +192,6 @@ public final class Algebra extends Persi
     };
 
     GenericPermuting.permute(indexes, swapper, work, null);
-    return A;
   }
 
   /**
@@ -249,11 +204,6 @@ public final class Algebra extends Persi
     return property;
   }
 
-  /** Constructs and returns the QR-decomposition of the given matrix. */
-  private static QRDecomposition qr(DoubleMatrix2D matrix) {
-    return new QRDecomposition(matrix);
-  }
-
   /**
    * Attaches the given property object to this Algebra, defining tolerance.
    *
@@ -275,15 +225,6 @@ public final class Algebra extends Persi
   }
 
   /**
-   * Solves A*X = B.
-   *
-   * @return X; a new independent matrix; solution if A is square, least squares solution otherwise.
-   */
-  public static DoubleMatrix2D solve(DoubleMatrix2D A, DoubleMatrix2D B) {
-    return A.rows() == A.columns() ? (lu(A).solve(B)) : (qr(A).solve(B));
-  }
-
-  /**
    * Modifies the matrix to be a lower trapezoidal matrix.
    *
    * @return <tt>A</tt> (for convenience only).

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/EigenvalueDecomposition.java Sat Jan  8 13:49:07 2011
@@ -8,10 +8,10 @@ It is provided "as is" without expressed
 */
 package org.apache.mahout.math.matrix.linalg;
 
-import org.apache.mahout.math.matrix.DoubleFactory1D;
-import org.apache.mahout.math.matrix.DoubleFactory2D;
 import org.apache.mahout.math.matrix.DoubleMatrix1D;
 import org.apache.mahout.math.matrix.DoubleMatrix2D;
+import org.apache.mahout.math.matrix.impl.DenseDoubleMatrix1D;
+import org.apache.mahout.math.matrix.impl.DenseDoubleMatrix2D;
 
 import java.io.Serializable;
 
@@ -19,7 +19,7 @@ import static org.apache.mahout.math.mat
 
 /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
 @Deprecated
-public class EigenvalueDecomposition implements Serializable {
+public final class EigenvalueDecomposition implements Serializable {
 
   /** Row and column dimension (square matrix). */
   private final int n;
@@ -124,7 +124,7 @@ public class EigenvalueDecomposition imp
         D[i][i - 1] = e[i];
       }
     }
-    return DoubleFactory2D.DENSE.make(D);
+    return new DenseDoubleMatrix2D(D);
   }
 
   /**
@@ -133,7 +133,7 @@ public class EigenvalueDecomposition imp
    * @return imag(diag(D))
    */
   public DoubleMatrix1D getImagEigenvalues() {
-    return DoubleFactory1D.dense.make(e);
+    return new DenseDoubleMatrix1D(e);
   }
 
   /**
@@ -142,7 +142,7 @@ public class EigenvalueDecomposition imp
    * @return real(diag(D))
    */
   public DoubleMatrix1D getRealEigenvalues() {
-    return DoubleFactory1D.dense.make(d);
+    return new DenseDoubleMatrix1D(d);
   }
 
   /**
@@ -151,7 +151,7 @@ public class EigenvalueDecomposition imp
    * @return <tt>V</tt>
    */
   public DoubleMatrix2D getV() {
-    return DoubleFactory2D.DENSE.make(V);
+    return new DenseDoubleMatrix2D(V);
   }
 
   /** Nonsymmetric reduction from Hessenberg to real Schur form. */

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecomposition.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecomposition.java Sat Jan  8 13:49:07 2011
@@ -8,6 +8,8 @@ It is provided "as is" without expressed
 */
 package org.apache.mahout.math.matrix.linalg;
 
+import java.io.Serializable;
+
 import org.apache.mahout.math.matrix.DoubleMatrix2D;
 
 /**
@@ -17,13 +19,8 @@ import org.apache.mahout.math.matrix.Dou
  * m</tt> and <tt>U</tt> is <tt>m x n</tt>. <P> The LU decomposition with pivoting always exists, even if the matrix is
  * singular, so the constructor will never fail.  The primary use of the LU decomposition is in the solution of square
  * systems of simultaneous linear equations.  This will fail if <tt>isNonsingular()</tt> returns false.
- *
- * @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported.
  */
-
-/** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
-@Deprecated
-public class LUDecomposition implements java.io.Serializable {
+public final class LUDecomposition implements Serializable {
 
   private final LUDecompositionQuick quick;
 
@@ -48,53 +45,6 @@ public class LUDecomposition implements 
   }
 
   /**
-   * Returns pivot permutation vector as a one-dimensional double array
-   *
-   * @return (double) piv
-   */
-  /*
-  private double[] getDoublePivot() {
-    return quick.getDoublePivot();
-  }
-   */
-
-  /**
-   * Returns the lower triangular factor, <tt>L</tt>.
-   *
-   * @return <tt>L</tt>
-   */
-  public DoubleMatrix2D getL() {
-    return quick.getL();
-  }
-
-  /**
-   * Returns a copy of the pivot permutation vector.
-   *
-   * @return piv
-   */
-  public int[] getPivot() {
-    return quick.getPivot().clone();
-  }
-
-  /**
-   * Returns the upper triangular factor, <tt>U</tt>.
-   *
-   * @return <tt>U</tt>
-   */
-  public DoubleMatrix2D getU() {
-    return quick.getU();
-  }
-
-  /**
-   * Returns whether the matrix is nonsingular (has an inverse).
-   *
-   * @return true if <tt>U</tt>, and hence <tt>A</tt>, is nonsingular; false otherwise.
-   */
-  public boolean isNonsingular() {
-    return quick.isNonsingular();
-  }
-
-  /**
    * Solves <tt>A*X = B</tt>.
    *
    * @param b A matrix with as many rows as <tt>A</tt> and any number of columns.

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecompositionQuick.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecompositionQuick.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecompositionQuick.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/LUDecompositionQuick.java Sat Jan  8 13:49:07 2011
@@ -13,12 +13,14 @@ import org.apache.mahout.math.function.P
 import org.apache.mahout.math.list.IntArrayList;
 import org.apache.mahout.math.matrix.DoubleMatrix1D;
 import org.apache.mahout.math.matrix.DoubleMatrix2D;
+import org.apache.mahout.math.matrix.impl.DenseDoubleMatrix1D;
+import org.apache.mahout.math.matrix.impl.DenseDoubleMatrix2D;
 
 import java.io.Serializable;
 
 /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
 @Deprecated
-public class LUDecompositionQuick implements Serializable {
+public final class LUDecompositionQuick implements Serializable {
 
   /** Array for internal storage of decomposition. */
   private DoubleMatrix2D lu;
@@ -36,14 +38,6 @@ public class LUDecompositionQuick implem
   private transient double[] workDouble;
   private transient int[] work1;
 
-  /**
-   * Constructs and returns a new LU Decomposition object with default tolerance <tt>1.0E-9</tt> for singularity
-   * detection.
-   */
-  public LUDecompositionQuick() {
-    this(Property.DEFAULT.tolerance());
-  }
-
   /** Constructs and returns a new LU Decomposition object which uses the given tolerance for singularity detection; */
   public LUDecompositionQuick(double tolerance) {
     this.algebra = new Algebra(tolerance);
@@ -465,7 +459,7 @@ public class LUDecompositionQuick implem
 
     IntArrayList nonZeroIndexes =
         new IntArrayList(); // sparsity
-    DoubleMatrix1D bRowk = org.apache.mahout.math.matrix.DoubleFactory1D.dense.make(nx); // blocked row k
+    DoubleMatrix1D bRowk = new DenseDoubleMatrix1D(nx); // blocked row k
 
     // Solve L*Y = B(piv,:)
     int cutOff = 10;
@@ -648,7 +642,7 @@ public class LUDecompositionQuick implem
     }
 
     buf.append("\n\ninverse(A) = ");
-    DoubleMatrix2D identity = org.apache.mahout.math.matrix.DoubleFactory2D.DENSE.identity(lu.rows());
+    DoubleMatrix2D identity = DenseDoubleMatrix2D.identity(lu.rows());
     try {
       this.solve(identity);
       buf.append(String.valueOf(identity));

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/Property.java Sat Jan  8 13:49:07 2011
@@ -8,13 +8,11 @@ It is provided "as is" without expressed
 */
 package org.apache.mahout.math.matrix.linalg;
 
-import org.apache.mahout.math.PersistentObject;
 import org.apache.mahout.math.function.Functions;
-import org.apache.mahout.math.list.ObjectArrayList;
-import org.apache.mahout.math.matrix.DoubleFactory2D;
 import org.apache.mahout.math.matrix.DoubleMatrix1D;
 import org.apache.mahout.math.matrix.DoubleMatrix2D;
 import org.apache.mahout.math.matrix.impl.AbstractMatrix2D;
+import org.apache.mahout.math.matrix.impl.DenseDoubleMatrix2D;
 
 import java.util.Formatter;
 import java.util.Locale;
@@ -23,7 +21,7 @@ import java.util.TreeMap;
 
 /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
 @Deprecated
-public class Property extends PersistentObject {
+public final class Property {
 
   /** The default Property object; currently has <tt>tolerance()==1.0E-9</tt>. */
   public static final Property DEFAULT = new Property(1.0E-9);
@@ -31,33 +29,13 @@ public class Property extends Persistent
   /** A Property object with <tt>tolerance()==0.0</tt>. */
   public static final Property ZERO = new Property(0.0);
 
-  /** A Property object with <tt>tolerance()==1.0E-12</tt>. */
-  public static final Property TWELVE = new Property(1.0E-12);
-
-  private double tolerance;
-
-  /** Not instantiable by no-arg constructor. */
-  private Property() {
-    this(1.0E-9); // just to be on the safe side
-  }
+  private final double tolerance;
 
   /** Constructs an instance with a tolerance of <tt>Math.abs(newTolerance)</tt>. */
   public Property(double newTolerance) {
     tolerance = Math.abs(newTolerance);
   }
 
-  /** Returns a String with <tt>length</tt> blanks. */
-  protected static String blanks(int length) {
-    if (length < 0) {
-      length = 0;
-    }
-    StringBuilder buf = new StringBuilder(length);
-    for (int k = 0; k < length; k++) {
-      buf.append(' ');
-    }
-    return buf.toString();
-  }
-
   /**
    * Checks whether the given matrix <tt>A</tt> is <i>rectangular</i>.
    *
@@ -228,30 +206,6 @@ public class Property extends Persistent
   }
 
   /**
-   * Modifies the given matrix square matrix <tt>A</tt> such that it is diagonally dominant by row and column, hence
-   * non-singular, hence invertible. For testing purposes only.
-   *
-   * @param a the square matrix to modify.
-   * @throws IllegalArgumentException if <tt>!isSquare(A)</tt>.
-   */
-  public static void generateNonSingular(DoubleMatrix2D a) {
-    checkSquare(a);
-    int min = Math.min(a.rows(), a.columns());
-    for (int i = min; --i >= 0;) {
-      a.setQuick(i, i, 0);
-    }
-    for (int i = min; --i >= 0;) {
-      double rowSum = a.viewRow(i).aggregate(Functions.PLUS, Functions.ABS);
-      double colSum = a.viewColumn(i).aggregate(Functions.PLUS, Functions.ABS);
-      a.setQuick(i, i, Math.max(rowSum, colSum) + i + 1);
-    }
-  }
-
-  protected static String get(ObjectArrayList<String> list, int index) {
-    return list.get(index);
-  }
-
-  /**
    * A matrix <tt>A</tt> is <i>diagonal</i> if <tt>A[i,j] == 0</tt> whenever <tt>i != j</tt>. Matrix may but need not be
    * square.
    */
@@ -393,7 +347,7 @@ public class Property extends Persistent
   public boolean isOrthogonal(DoubleMatrix2D a) {
     checkSquare(a);
     return equals(a.zMult(a, null, 1, 0, false, true),
-        DoubleFactory2D.DENSE.identity(a.rows()));
+                  DenseDoubleMatrix2D.identity(a.rows()));
   }
 
   /** A matrix <tt>A</tt> is <i>positive</i> if <tt>A[i,j] &gt; 0</tt> holds for all cells.
@@ -692,19 +646,6 @@ public class Property extends Persistent
     return 1;
   }
 
-  /**
-   * Sets the tolerance to <tt>Math.abs(newTolerance)</tt>.
-   *
-   * @throws UnsupportedOperationException if <tt>this==DEFAULT || this==ZERO || this==TWELVE</tt>.
-   */
-  public void setTolerance(double newTolerance) {
-    if (this == DEFAULT || this == ZERO || this == TWELVE) {
-      throw new IllegalArgumentException("Attempted to modify immutable object.");
-      //throw new UnsupportedOperationException("Attempted to modify object."); // since JDK1.2
-    }
-    tolerance = Math.abs(newTolerance);
-  }
-
   /** Returns the current tolerance. */
   public double tolerance() {
     return tolerance;

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/matrix/linalg/QRDecomposition.java Sat Jan  8 13:49:07 2011
@@ -8,10 +8,12 @@ It is provided "as is" without expressed
 */
 package org.apache.mahout.math.matrix.linalg;
 
+import java.io.Serializable;
+
 import org.apache.mahout.math.function.Functions;
-import org.apache.mahout.math.matrix.DoubleFactory2D;
 import org.apache.mahout.math.matrix.DoubleMatrix1D;
 import org.apache.mahout.math.matrix.DoubleMatrix2D;
+import org.apache.mahout.math.matrix.impl.DenseDoubleMatrix2D;
 
 /**
  For an <tt>m x n</tt> matrix <tt>A</tt> with <tt>m >= n</tt>, the QR decomposition is an <tt>m x n</tt>
@@ -27,7 +29,7 @@ import org.apache.mahout.math.matrix.Dou
 
 /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
 @Deprecated
-public class QRDecomposition implements java.io.Serializable {
+public class QRDecomposition implements Serializable {
 
   /** Array for internal storage of decomposition. */
   private final DoubleMatrix2D QR;
@@ -57,7 +59,7 @@ public class QRDecomposition implements 
     n = A.columns();
     Rdiag = A.like1D(n);
     //Rdiag = new double[n];
-    //org.apache.mahout.math.function.BinaryFunction hypot = Algebra.hypotFunction();
+    //org.apache.mahout.math.function.DoubleDoubleFunction hypot = Algebra.hypotFunction();
 
     // precompute and cache some views to avoid regenerating them time and again
     DoubleMatrix1D[] QRcolumns = new DoubleMatrix1D[n];
@@ -279,7 +281,7 @@ public class QRDecomposition implements 
 
     buf.append("\n\npseudo inverse(A) = ");
     try {
-      buf.append(String.valueOf(this.solve(DoubleFactory2D.DENSE.identity(QR.rows()))));
+      buf.append(String.valueOf(this.solve(DenseDoubleMatrix2D.identity(QR.rows()))));
     } catch (IllegalArgumentException exc) {
       buf.append(unknown).append(exc.getMessage());
     }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/VectorTest.java Sat Jan  8 13:49:07 2011
@@ -846,7 +846,7 @@ public final class VectorTest extends Ma
   public void testHashCodeEquivalence() {
     // Hash codes must be equal if the vectors are considered equal
     Vector sparseLeft = new RandomAccessSparseVector(3);
-    DenseVector denseRight = new DenseVector(3);
+    Vector denseRight = new DenseVector(3);
     sparseLeft.setQuick(0, 1);
     sparseLeft.setQuick(1, 2);
     sparseLeft.setQuick(2, 3);
@@ -863,7 +863,7 @@ public final class VectorTest extends Ma
     assertEquals(sparseLeft, denseRight);
     assertEquals(sparseLeft.hashCode(), denseRight.hashCode());
 
-    DenseVector denseLeft = new DenseVector(3);
+    Vector denseLeft = new DenseVector(3);
     denseLeft.setQuick(0, 1);
     denseLeft.setQuick(1, 2);
     denseLeft.setQuick(2, 3);

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/SolverTest.java Sat Jan  8 13:49:07 2011
@@ -17,7 +17,6 @@
 
 package org.apache.mahout.math.decomposer;
 
-import org.apache.mahout.common.RandomUtils;
 import org.apache.mahout.math.MahoutTestCase;
 import org.apache.mahout.math.Matrix;
 import org.apache.mahout.math.SequentialAccessSparseVector;

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/ExponentialTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/ExponentialTest.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/ExponentialTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/ExponentialTest.java Sat Jan  8 13:49:07 2011
@@ -17,8 +17,6 @@
 
 package org.apache.mahout.math.jet.random;
 
-import org.apache.commons.math.ConvergenceException;
-import org.apache.commons.math.FunctionEvaluationException;
 import org.apache.mahout.common.RandomUtils;
 import org.apache.mahout.math.MahoutTestCase;
 import org.junit.Test;
@@ -26,6 +24,7 @@ import org.junit.Test;
 import java.util.Arrays;
 
 public final class ExponentialTest extends MahoutTestCase {
+
   @Test
   public void consistency() throws Exception {
     Exponential dist = new Exponential(1, RandomUtils.getRandom());

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NegativeBinomialTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NegativeBinomialTest.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NegativeBinomialTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NegativeBinomialTest.java Sat Jan  8 13:49:07 2011
@@ -57,33 +57,4 @@ public final class NegativeBinomialTest 
     }
   }
 
-  // TODO "fix" this test? Seems very sensitive to sequence of random numbers and
-  // having trouble making it work reliably on all environments
-  /*
-  @Test
-  public void sample() {
-    for (double p : new double[]{0.1, 0.2, 0.5, 0.9}) {
-      for (int r = 1; r < 5; r++) {
-        NegativeBinomial nb = new NegativeBinomial(r, p, RandomUtils.getRandom());
-        int[] counts = new int[N];
-        for (int i = 0; i < N; i++) {
-          int k = nb.nextInt();
-          if (k < counts.length) {
-            counts[k]++;
-          }
-        }
-
-        // probably should do a chi^2 or LLR test here especially since we know the PDF
-        for (int k = 0; k < counts.length; k++) {
-          assertEquals(String.format(Locale.ENGLISH, "r=%d,p=%.3f,k=%d,count=%d,pdf=%.3f",
-                                     r, p, k, counts[k], nb.pdf(k)),
-                       N * nb.pdf(k),
-                       counts[k],
-                       Math.max(3, 4 * Math.sqrt(N * nb.pdf(k) * (1 - nb.pdf(k)))));
-        }
-      }
-    }
-  }
-   */
-
 }

Modified: mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NormalTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NormalTest.java?rev=1056703&r1=1056702&r2=1056703&view=diff
==============================================================================
--- mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NormalTest.java (original)
+++ mahout/trunk/math/src/test/java/org/apache/mahout/math/jet/random/NormalTest.java Sat Jan  8 13:49:07 2011
@@ -17,8 +17,6 @@
 
 package org.apache.mahout.math.jet.random;
 
-import org.apache.commons.math.ConvergenceException;
-import org.apache.commons.math.FunctionEvaluationException;
 import org.apache.mahout.common.RandomUtils;
 import org.apache.mahout.math.MahoutTestCase;
 import org.junit.Test;