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 2009/11/25 04:41:31 UTC

svn commit: r883974 [15/20] - in /lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix: ./ bench/ doublealgo/ impl/ linalg/ objectalgo/

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/TridiagonalDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/TridiagonalDoubleMatrix2D.java?rev=883974&r1=883973&r2=883974&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/TridiagonalDoubleMatrix2D.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/TridiagonalDoubleMatrix2D.java Wed Nov 25 03:41:28 2009
@@ -21,29 +21,29 @@
 @version 0.9, 04/14/2000
 */
 class TridiagonalDoubleMatrix2D extends WrapperDoubleMatrix2D {
-	/*
-	 * The non zero elements of the matrix: {lower, diagonal, upper}.
-	 */
-	protected double[] values; 
-
-	/*
-	 * The startIndexes and number of non zeros: {lowerStart, diagonalStart, upperStart, values.length, lowerNonZeros, diagonalNonZeros, upperNonZeros}.
-	 * lowerStart = 0
-	 * diagonalStart = lowerStart + lower.length
-	 * upperStart = diagonalStart + diagonal.length
-	 */
-	protected int[] dims;
-
-	protected static final int NONZERO = 4;
-	
-	//protected double diagonal[];
-	//protected double lower[];
-	//protected double upper[];
-
-	//protected int diagonalNonZeros;
-	//protected int lowerNonZeros;
-	//protected int upperNonZeros;
-	//protected int N;
+  /*
+   * The non zero elements of the matrix: {lower, diagonal, upper}.
+   */
+  protected double[] values; 
+
+  /*
+   * The startIndexes and number of non zeros: {lowerStart, diagonalStart, upperStart, values.length, lowerNonZeros, diagonalNonZeros, upperNonZeros}.
+   * lowerStart = 0
+   * diagonalStart = lowerStart + lower.length
+   * upperStart = diagonalStart + diagonal.length
+   */
+  protected int[] dims;
+
+  protected static final int NONZERO = 4;
+  
+  //protected double diagonal[];
+  //protected double lower[];
+  //protected double upper[];
+
+  //protected int diagonalNonZeros;
+  //protected int lowerNonZeros;
+  //protected int upperNonZeros;
+  //protected int N;
 /**
  * Constructs a matrix with a copy of the given values.
  * <tt>values</tt> is required to have the form <tt>values[row][column]</tt>
@@ -55,37 +55,37 @@
  * @throws IllegalArgumentException if <tt>for any 1 &lt;= row &lt; values.length: values[row].length != values[row-1].length</tt>.
  */
 public TridiagonalDoubleMatrix2D(double[][] values) {
-	this(values.length, values.length==0 ? 0: values[0].length);
-	assign(values);
+  this(values.length, values.length==0 ? 0: values[0].length);
+  assign(values);
 }
 /**
  * Constructs a matrix with a given number of rows and columns.
  * All entries are initially <tt>0</tt>.
  * @param rows the number of rows the matrix shall have.
  * @param columns the number of columns the matrix shall have.
- * @throws	IllegalArgumentException if <tt>rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE</tt>.
+ * @throws  IllegalArgumentException if <tt>rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE</tt>.
  */
 public TridiagonalDoubleMatrix2D(int rows, int columns) {
-	super(null);
-	setUp(rows, columns);
-	
-	int d = Math.min(rows,columns);
-	int u = d-1;
-	int l = d-1;
-	if (rows>columns) l++;
-	if (rows<columns) u++;
-
-	values = new double[l+d+u]; // {lower, diagonal, upper}
-	int[] dimensions = { 0, l, l+d, l+d+u, 0, 0, 0}; // {lowerStart, diagonalStart, upperStart, values.length, lowerNonZeros, diagonalNonZeros, upperNonZeros}
-	dims = dimensions;
-	
-	//diagonal = new double[d];
-	//lower = new double[l];
-	//upper = new double[u];
-
-	//diagonalNonZeros = 0;
-	//lowerNonZeros = 0;
-	//upperNonZeros = 0;
+  super(null);
+  setUp(rows, columns);
+  
+  int d = Math.min(rows,columns);
+  int u = d-1;
+  int l = d-1;
+  if (rows>columns) l++;
+  if (rows<columns) u++;
+
+  values = new double[l+d+u]; // {lower, diagonal, upper}
+  int[] dimensions = { 0, l, l+d, l+d+u, 0, 0, 0}; // {lowerStart, diagonalStart, upperStart, values.length, lowerNonZeros, diagonalNonZeros, upperNonZeros}
+  dims = dimensions;
+  
+  //diagonal = new double[d];
+  //lower = new double[l];
+  //upper = new double[u];
+
+  //diagonalNonZeros = 0;
+  //lowerNonZeros = 0;
+  //upperNonZeros = 0;
 }
 /**
  * Sets all cells to the state specified by <tt>value</tt>.
@@ -93,48 +93,48 @@
  * @return <tt>this</tt> (for convenience only).
  */
 public DoubleMatrix2D assign(double value) {
-	// overriden for performance only
-	if (value==0) {
-		for (int i=values.length; --i >= 0; ) values[i]=0;
-		for (int i=dims.length; --i >= NONZERO; ) dims[i]=0;
-		
-		//for (int i=diagonal.length; --i >= 0; ) diagonal[i]=0;
-		//for (int i=upper.length; --i >= 0; ) upper[i]=0;
-		//for (int i=lower.length; --i >= 0; ) lower[i]=0;
-		
-		//diagonalNonZeros = 0;
-		//lowerNonZeros = 0;
-		//upperNonZeros = 0;
-	}
-	else super.assign(value);
-	return this;
+  // overriden for performance only
+  if (value==0) {
+    for (int i=values.length; --i >= 0; ) values[i]=0;
+    for (int i=dims.length; --i >= NONZERO; ) dims[i]=0;
+    
+    //for (int i=diagonal.length; --i >= 0; ) diagonal[i]=0;
+    //for (int i=upper.length; --i >= 0; ) upper[i]=0;
+    //for (int i=lower.length; --i >= 0; ) lower[i]=0;
+    
+    //diagonalNonZeros = 0;
+    //lowerNonZeros = 0;
+    //upperNonZeros = 0;
+  }
+  else super.assign(value);
+  return this;
 }
 public DoubleMatrix2D assign(final org.apache.mahout.matrix.function.DoubleFunction function) {
-	if (function instanceof org.apache.mahout.jet.math.Mult) { // x[i] = mult*x[i]
-		final double alpha = ((org.apache.mahout.jet.math.Mult) function).multiplicator;
-		if (alpha==1) return this;
-		if (alpha==0) return assign(0);
-		if (alpha!=alpha) return assign(alpha); // the funny definition of isNaN(). This should better not happen.
-
-		/*
-		double[] vals = values.elements();
-		for (int j=values.size(); --j >= 0; ) {
-			vals[j] *= alpha;
-		}
-		*/
-
-		forEachNonZero(
-			new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
-				public double apply(int i, int j, double value) {
-					return function.apply(value);
-				}
-			}
-		);
-	}
-	else {
-		super.assign(function);
-	}
-	return this;
+  if (function instanceof org.apache.mahout.jet.math.Mult) { // x[i] = mult*x[i]
+    final double alpha = ((org.apache.mahout.jet.math.Mult) function).multiplicator;
+    if (alpha==1) return this;
+    if (alpha==0) return assign(0);
+    if (alpha!=alpha) return assign(alpha); // the funny definition of isNaN(). This should better not happen.
+
+    /*
+    double[] vals = values.elements();
+    for (int j=values.size(); --j >= 0; ) {
+      vals[j] *= alpha;
+    }
+    */
+
+    forEachNonZero(
+      new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
+        public double apply(int i, int j, double value) {
+          return function.apply(value);
+        }
+      }
+    );
+  }
+  else {
+    super.assign(function);
+  }
+  return this;
 }
 /**
  * Replaces all cell values of the receiver with the values of another matrix.
@@ -143,110 +143,110 @@
  *
  * @param     source   the source matrix to copy from (may be identical to the receiver).
  * @return <tt>this</tt> (for convenience only).
- * @throws	IllegalArgumentException if <tt>columns() != source.columns() || rows() != source.rows()</tt>
+ * @throws  IllegalArgumentException if <tt>columns() != source.columns() || rows() != source.rows()</tt>
  */
 public DoubleMatrix2D assign(DoubleMatrix2D source) {
-	// overriden for performance only
-	if (source==this) return this; // nothing to do
-	checkShape(source);
-
-	if (source instanceof TridiagonalDoubleMatrix2D) {
-		// quickest
-		TridiagonalDoubleMatrix2D other = (TridiagonalDoubleMatrix2D) source;
-		
-		System.arraycopy(other.values, 0, this.values, 0, this.values.length);
-		System.arraycopy(other.dims, 0, this.dims, 0, this.dims.length);
-		return this;
-	}
-
-	if (source instanceof RCDoubleMatrix2D || source instanceof SparseDoubleMatrix2D) {
-		assign(0);
-		source.forEachNonZero(
-			new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
-				public double apply(int i, int j, double value) {
-					setQuick(i,j,value);
-					return value;
-				}
-			}
-		);	
-		return this;
-	}
-	
-	return super.assign(source);
+  // overriden for performance only
+  if (source==this) return this; // nothing to do
+  checkShape(source);
+
+  if (source instanceof TridiagonalDoubleMatrix2D) {
+    // quickest
+    TridiagonalDoubleMatrix2D other = (TridiagonalDoubleMatrix2D) source;
+    
+    System.arraycopy(other.values, 0, this.values, 0, this.values.length);
+    System.arraycopy(other.dims, 0, this.dims, 0, this.dims.length);
+    return this;
+  }
+
+  if (source instanceof RCDoubleMatrix2D || source instanceof SparseDoubleMatrix2D) {
+    assign(0);
+    source.forEachNonZero(
+      new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
+        public double apply(int i, int j, double value) {
+          setQuick(i,j,value);
+          return value;
+        }
+      }
+    );  
+    return this;
+  }
+  
+  return super.assign(source);
 }
 public DoubleMatrix2D assign(final DoubleMatrix2D y, org.apache.mahout.matrix.function.DoubleDoubleFunction function) {
-	checkShape(y);
+  checkShape(y);
 
-	if (function instanceof org.apache.mahout.jet.math.PlusMult) { // x[i] = x[i] + alpha*y[i]
-		final double alpha = ((org.apache.mahout.jet.math.PlusMult) function).multiplicator;
-		if (alpha==0) return this; // nothing to do
-		y.forEachNonZero(
-			new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
-				public double apply(int i, int j, double value) {
-					setQuick(i,j,getQuick(i,j) + alpha*value);
-					return value;
-				}
-			}
-		);
-		return this;
-	}
-
-	if (function== org.apache.mahout.jet.math.Functions.mult) { // x[i] = x[i] * y[i]
-		forEachNonZero(
-			new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
-				public double apply(int i, int j, double value) {
-					setQuick(i,j,getQuick(i,j) * y.getQuick(i,j));
-					return value;
-				}
-			}
-		);
-		return this;
-	}
-	
-	if (function== org.apache.mahout.jet.math.Functions.div) { // x[i] = x[i] / y[i]
-		forEachNonZero(
-			new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
-				public double apply(int i, int j, double value) {
-					setQuick(i,j,getQuick(i,j) / y.getQuick(i,j));
-					return value;
-				}
-			}
-		);
-		return this;
-	}
-	
-	return super.assign(y,function);
+  if (function instanceof org.apache.mahout.jet.math.PlusMult) { // x[i] = x[i] + alpha*y[i]
+    final double alpha = ((org.apache.mahout.jet.math.PlusMult) function).multiplicator;
+    if (alpha==0) return this; // nothing to do
+    y.forEachNonZero(
+      new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
+        public double apply(int i, int j, double value) {
+          setQuick(i,j,getQuick(i,j) + alpha*value);
+          return value;
+        }
+      }
+    );
+    return this;
+  }
+
+  if (function== org.apache.mahout.jet.math.Functions.mult) { // x[i] = x[i] * y[i]
+    forEachNonZero(
+      new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
+        public double apply(int i, int j, double value) {
+          setQuick(i,j,getQuick(i,j) * y.getQuick(i,j));
+          return value;
+        }
+      }
+    );
+    return this;
+  }
+  
+  if (function== org.apache.mahout.jet.math.Functions.div) { // x[i] = x[i] / y[i]
+    forEachNonZero(
+      new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
+        public double apply(int i, int j, double value) {
+          setQuick(i,j,getQuick(i,j) / y.getQuick(i,j));
+          return value;
+        }
+      }
+    );
+    return this;
+  }
+  
+  return super.assign(y,function);
 }
 public DoubleMatrix2D forEachNonZero(final org.apache.mahout.matrix.function.IntIntDoubleFunction function) {
-	for (int kind=0; kind<=2; kind++) {
-		int i=0,j=0;
-		switch (kind) {
-			case 0: { i=1; } // lower 
-			// case 1: {   } // diagonal
-			case 2: { j=1; } // upper
-		}
-		int low = dims[kind];
-		int high = dims[kind+1];
-		
-		for (int k=low; k < high; k++, i++, j++) {
-			double value = values[k];
-			if (value!=0) {
-				double r = function.apply(i,j,value);
-				if (r!=value) {
-					if (r==0) dims[kind+NONZERO]++; // one non zero more
-					values[k] = r;
-				}
-			}
-		}
-	}
-	return this;
+  for (int kind=0; kind<=2; kind++) {
+    int i=0,j=0;
+    switch (kind) {
+      case 0: { i=1; } // lower 
+      // case 1: {   } // diagonal
+      case 2: { j=1; } // upper
+    }
+    int low = dims[kind];
+    int high = dims[kind+1];
+    
+    for (int k=low; k < high; k++, i++, j++) {
+      double value = values[k];
+      if (value!=0) {
+        double r = function.apply(i,j,value);
+        if (r!=value) {
+          if (r==0) dims[kind+NONZERO]++; // one non zero more
+          values[k] = r;
+        }
+      }
+    }
+  }
+  return this;
 }
 /**
  * Returns the content of this matrix if it is a wrapper; or <tt>this</tt> otherwise.
  * Override this method in wrappers.
  */
 protected DoubleMatrix2D getContent() {
-	return this;
+  return this;
 }
 /**
  * Returns the matrix cell value at coordinate <tt>[row,column]</tt>.
@@ -260,41 +260,41 @@
  * @return    the value at the specified coordinate.
  */
 public double getQuick(int row, int column) {
-	int i = row;
-	int j = column;
+  int i = row;
+  int j = column;
 
-	int k = j-i+1;
-	int q = i;
-	if (k==0) q=j; // lower diagonal
+  int k = j-i+1;
+  int q = i;
+  if (k==0) q=j; // lower diagonal
 
-	if (k>=0 && k<=2) {
-		return values[dims[k]+q];
-	}
-	return 0;
+  if (k>=0 && k<=2) {
+    return values[dims[k]+q];
+  }
+  return 0;
 
 
-	
-	
-	
-	//int k = -1;
-	//int q = 0;
+  
+  
+  
+  //int k = -1;
+  //int q = 0;
 
-	//if (i==j) { k=0; q=i; }
-	//if (i==j+1) { k=1; q=j; }
-	//if (i==j-1) { k=2; q=i; }
+  //if (i==j) { k=0; q=i; }
+  //if (i==j+1) { k=1; q=j; }
+  //if (i==j-1) { k=2; q=i; }
 
-	//if (k<0) return 0;
-	//return values[dims[k]+q];
+  //if (k<0) return 0;
+  //return values[dims[k]+q];
 
 
 
 
-	
-	//if (i==j) return diagonal[i];
-	//if (i==j+1) return lower[j];
-	//if (i==j-1) return upper[i];
+  
+  //if (i==j) return diagonal[i];
+  //if (i==j+1) return lower[j];
+  //if (i==j-1) return upper[i];
 
-	//return 0;
+  //return 0;
 }
 /**
  * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of rows and columns.
@@ -307,7 +307,7 @@
  * @return  a new empty matrix of the same dynamic type.
  */
 public DoubleMatrix2D like(int rows, int columns) {
-	return new TridiagonalDoubleMatrix2D(rows,columns);
+  return new TridiagonalDoubleMatrix2D(rows,columns);
 }
 /**
  * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver.
@@ -318,7 +318,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 public DoubleMatrix1D like1D(int size) {
-	return new SparseDoubleMatrix1D(size);
+  return new SparseDoubleMatrix1D(size);
 }
 /**
  * Sets the matrix cell at coordinate <tt>[row,column]</tt> to the specified value.
@@ -332,179 +332,179 @@
  * @param    value the value to be filled into the specified cell.
  */
 public void setQuick(int row, int column, double value) {
-	int i = row;
-	int j = column;
+  int i = row;
+  int j = column;
 
-	boolean isZero = (value==0);
+  boolean isZero = (value==0);
 
-	int k = j-i+1;
-	int q = i;
-	if (k==0) q=j; // lower diagonal
-
-	if (k>=0 && k<=2) {
-		int index = dims[k]+q;
-		if (values[index]!=0) {
-			if (isZero) dims[k+NONZERO]--; // one nonZero less
-		}
-		else {
-			if (!isZero) dims[k+NONZERO]++; // one nonZero more
-		}
-		values[index] = value;
-		return;
-	}
-	
-	if (!isZero) throw new IllegalArgumentException("Can't store non-zero value to non-tridiagonal coordinate: row="+row+", column="+column+", value="+value);
-
-	//int k = -1;
-	//int q = 0;
-
-	//if (i==j) { k=0; q=i; } // diagonal
-	//if (i==j+1) { k=1; q=j; } // lower diagonal
-	//if (i==j-1) { k=2; q=i; } // upper diagonal
-
-	//if (k>0) {
-		//int index = dims[k]+q;
-		//if (values[index]!=0) {
-			//if (isZero) dims[k+NONZERO]--; // one nonZero less
-		//}
-		//else {
-			//if (!isZero) dims[k+NONZERO]++; // one nonZero more
-		//}
-		//values[index] = value;
-		//return;
-	//}
-	
-	//if (!isZero) throw new IllegalArgumentException("Can't store non-zero value to non-tridiagonal coordinate: row="+row+", column="+column+", value="+value);
+  int k = j-i+1;
+  int q = i;
+  if (k==0) q=j; // lower diagonal
+
+  if (k>=0 && k<=2) {
+    int index = dims[k]+q;
+    if (values[index]!=0) {
+      if (isZero) dims[k+NONZERO]--; // one nonZero less
+    }
+    else {
+      if (!isZero) dims[k+NONZERO]++; // one nonZero more
+    }
+    values[index] = value;
+    return;
+  }
+  
+  if (!isZero) throw new IllegalArgumentException("Can't store non-zero value to non-tridiagonal coordinate: row="+row+", column="+column+", value="+value);
+
+  //int k = -1;
+  //int q = 0;
+
+  //if (i==j) { k=0; q=i; } // diagonal
+  //if (i==j+1) { k=1; q=j; } // lower diagonal
+  //if (i==j-1) { k=2; q=i; } // upper diagonal
+
+  //if (k>0) {
+    //int index = dims[k]+q;
+    //if (values[index]!=0) {
+      //if (isZero) dims[k+NONZERO]--; // one nonZero less
+    //}
+    //else {
+      //if (!isZero) dims[k+NONZERO]++; // one nonZero more
+    //}
+    //values[index] = value;
+    //return;
+  //}
+  
+  //if (!isZero) throw new IllegalArgumentException("Can't store non-zero value to non-tridiagonal coordinate: row="+row+", column="+column+", value="+value);
 
 
 
 
 
-	
-	//if (i==j) {
-		//if (diagonal[i]!=0) {
-			//if (isZero) diagonalNonZeros--;
-		//}
-		//else {
-			//if (!isZero) diagonalNonZeros++;
-		//}
-		//diagonal[i] = value;
-		//return;
-	//}
-	
-	//if (i==j+1) {
-		//if (lower[j]!=0) {
-			//if (isZero) lowerNonZeros--;
-		//}
-		//else {
-			//if (!isZero) lowerNonZeros++;
-		//}
-		//lower[j] = value;
-		//return;
-	//}
-		
-	//if (i==j-1) {
-		//if (upper[i]!=0) {
-			//if (isZero) upperNonZeros--;
-		//}
-		//else {
-			//if (!isZero) upperNonZeros++;
-		//}
-		//upper[i] = value;
-		//return;
-	//}
+  
+  //if (i==j) {
+    //if (diagonal[i]!=0) {
+      //if (isZero) diagonalNonZeros--;
+    //}
+    //else {
+      //if (!isZero) diagonalNonZeros++;
+    //}
+    //diagonal[i] = value;
+    //return;
+  //}
+  
+  //if (i==j+1) {
+    //if (lower[j]!=0) {
+      //if (isZero) lowerNonZeros--;
+    //}
+    //else {
+      //if (!isZero) lowerNonZeros++;
+    //}
+    //lower[j] = value;
+    //return;
+  //}
+    
+  //if (i==j-1) {
+    //if (upper[i]!=0) {
+      //if (isZero) upperNonZeros--;
+    //}
+    //else {
+      //if (!isZero) upperNonZeros++;
+    //}
+    //upper[i] = value;
+    //return;
+  //}
 
-	//if (!isZero) throw new IllegalArgumentException("Can't store non-zero value to non-tridiagonal coordinate: row="+row+", column="+column+", value="+value);
+  //if (!isZero) throw new IllegalArgumentException("Can't store non-zero value to non-tridiagonal coordinate: row="+row+", column="+column+", value="+value);
 }
 public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, final boolean transposeA) {
-	int m = rows;
-	int n = columns;
-	if (transposeA) {
-		m = columns;
-		n = rows;
-	}
-
-	boolean ignore = (z==null);
-	if (z==null) z = new DenseDoubleMatrix1D(m);
-	
-	if (!(this.isNoView && y instanceof DenseDoubleMatrix1D && z instanceof DenseDoubleMatrix1D)) {
-		return super.zMult(y,z,alpha,beta,transposeA);
-	}
-
-	if (n != y.size() || m > z.size())	
-		throw new IllegalArgumentException("Incompatible args: "+ ((transposeA ? viewDice() : this).toStringShort()) +", "+y.toStringShort()+", "+z.toStringShort());
-
-	if (!ignore) z.assign(org.apache.mahout.jet.math.Functions.mult(beta/alpha));
-	
-	DenseDoubleMatrix1D zz = (DenseDoubleMatrix1D) z;
-	final double[] zElements = zz.elements;
-	final int zStride = zz.stride;
-	final int zi = z.index(0);
-	
-	DenseDoubleMatrix1D yy = (DenseDoubleMatrix1D) y;
-	final double[] yElements = yy.elements;
-	final int yStride = yy.stride;
-	final int yi = y.index(0);
-
-	if (yElements==null || zElements==null) throw new InternalError();
-
-	forEachNonZero(
-		new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
-			public double apply(int i, int j, double value) {
-				if (transposeA) { int tmp=i; i=j; j=tmp; }
-				zElements[zi + zStride*i] += value * yElements[yi + yStride*j];
-				//z.setQuick(row,z.getQuick(row) + value * y.getQuick(column));
-				//System.out.println("["+i+","+j+"]-->"+value);
-				return value;
-			}
-		}
-	);
-	
-	if (alpha!=1) z.assign(org.apache.mahout.jet.math.Functions.mult(alpha));
-	return z;
+  int m = rows;
+  int n = columns;
+  if (transposeA) {
+    m = columns;
+    n = rows;
+  }
+
+  boolean ignore = (z==null);
+  if (z==null) z = new DenseDoubleMatrix1D(m);
+  
+  if (!(this.isNoView && y instanceof DenseDoubleMatrix1D && z instanceof DenseDoubleMatrix1D)) {
+    return super.zMult(y,z,alpha,beta,transposeA);
+  }
+
+  if (n != y.size() || m > z.size())  
+    throw new IllegalArgumentException("Incompatible args: "+ ((transposeA ? viewDice() : this).toStringShort()) +", "+y.toStringShort()+", "+z.toStringShort());
+
+  if (!ignore) z.assign(org.apache.mahout.jet.math.Functions.mult(beta/alpha));
+  
+  DenseDoubleMatrix1D zz = (DenseDoubleMatrix1D) z;
+  final double[] zElements = zz.elements;
+  final int zStride = zz.stride;
+  final int zi = z.index(0);
+  
+  DenseDoubleMatrix1D yy = (DenseDoubleMatrix1D) y;
+  final double[] yElements = yy.elements;
+  final int yStride = yy.stride;
+  final int yi = y.index(0);
+
+  if (yElements==null || zElements==null) throw new InternalError();
+
+  forEachNonZero(
+    new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
+      public double apply(int i, int j, double value) {
+        if (transposeA) { int tmp=i; i=j; j=tmp; }
+        zElements[zi + zStride*i] += value * yElements[yi + yStride*j];
+        //z.setQuick(row,z.getQuick(row) + value * y.getQuick(column));
+        //System.out.println("["+i+","+j+"]-->"+value);
+        return value;
+      }
+    }
+  );
+  
+  if (alpha!=1) z.assign(org.apache.mahout.jet.math.Functions.mult(alpha));
+  return z;
 }
 public DoubleMatrix2D zMult(DoubleMatrix2D B, DoubleMatrix2D C, final double alpha, double beta, final boolean transposeA, boolean transposeB) {
-	if (transposeB) B = B.viewDice();
-	int m = rows;
-	int n = columns;
-	if (transposeA) {
-		m = columns;
-		n = rows;
-	}
-	int p = B.columns;
-	boolean ignore = (C==null);
-	if (C==null) C = new DenseDoubleMatrix2D(m,p);
-
-	if (B.rows != n)
-		throw new IllegalArgumentException("Matrix2D inner dimensions must agree:"+toStringShort()+", "+ (transposeB ? B.viewDice() : B).toStringShort());
-	if (C.rows != m || C.columns != p)
-		throw new IllegalArgumentException("Incompatibel result matrix: "+toStringShort()+", "+ (transposeB ? B.viewDice() : B).toStringShort()+", "+C.toStringShort());
-	if (this == C || B == C)
-		throw new IllegalArgumentException("Matrices must not be identical");
-	
-	if (!ignore) C.assign(org.apache.mahout.jet.math.Functions.mult(beta));
-
-	// cache views	
-	final DoubleMatrix1D[] Brows = new DoubleMatrix1D[n];
-	for (int i=n; --i>=0; ) Brows[i] = B.viewRow(i);
-	final DoubleMatrix1D[] Crows = new DoubleMatrix1D[m];
-	for (int i=m; --i>=0; ) Crows[i] = C.viewRow(i);
-
-	final org.apache.mahout.jet.math.PlusMult fun = org.apache.mahout.jet.math.PlusMult.plusMult(0);
-
-	forEachNonZero(
-		new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
-			public double apply(int i, int j, double value) {
-				fun.multiplicator = value*alpha;
-				if (!transposeA)
-					Crows[i].assign(Brows[j],fun);
-				else
-					Crows[j].assign(Brows[i],fun);
-				return value;
-			}
-		}
-	);
+  if (transposeB) B = B.viewDice();
+  int m = rows;
+  int n = columns;
+  if (transposeA) {
+    m = columns;
+    n = rows;
+  }
+  int p = B.columns;
+  boolean ignore = (C==null);
+  if (C==null) C = new DenseDoubleMatrix2D(m,p);
+
+  if (B.rows != n)
+    throw new IllegalArgumentException("Matrix2D inner dimensions must agree:"+toStringShort()+", "+ (transposeB ? B.viewDice() : B).toStringShort());
+  if (C.rows != m || C.columns != p)
+    throw new IllegalArgumentException("Incompatibel result matrix: "+toStringShort()+", "+ (transposeB ? B.viewDice() : B).toStringShort()+", "+C.toStringShort());
+  if (this == C || B == C)
+    throw new IllegalArgumentException("Matrices must not be identical");
+  
+  if (!ignore) C.assign(org.apache.mahout.jet.math.Functions.mult(beta));
+
+  // cache views  
+  final DoubleMatrix1D[] Brows = new DoubleMatrix1D[n];
+  for (int i=n; --i>=0; ) Brows[i] = B.viewRow(i);
+  final DoubleMatrix1D[] Crows = new DoubleMatrix1D[m];
+  for (int i=m; --i>=0; ) Crows[i] = C.viewRow(i);
+
+  final org.apache.mahout.jet.math.PlusMult fun = org.apache.mahout.jet.math.PlusMult.plusMult(0);
+
+  forEachNonZero(
+    new org.apache.mahout.matrix.function.IntIntDoubleFunction() {
+      public double apply(int i, int j, double value) {
+        fun.multiplicator = value*alpha;
+        if (!transposeA)
+          Crows[i].assign(Brows[j],fun);
+        else
+          Crows[j].assign(Brows[i],fun);
+        return value;
+      }
+    }
+  );
 
-	return C;
+  return C;
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/WrapperDoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/WrapperDoubleMatrix1D.java?rev=883974&r1=883973&r2=883974&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/WrapperDoubleMatrix1D.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/WrapperDoubleMatrix1D.java Wed Nov 25 03:41:28 2009
@@ -17,20 +17,20 @@
 @version 1.0, 09/24/99
 */
 class WrapperDoubleMatrix1D extends DoubleMatrix1D {
-	/*
-	 * The elements of the matrix.
-	 */
-	protected DoubleMatrix1D content; 
+  /*
+   * The elements of the matrix.
+   */
+  protected DoubleMatrix1D content; 
 public WrapperDoubleMatrix1D(DoubleMatrix1D newContent) {
-	if (newContent != null) setUp(newContent.size());
-	this.content = newContent;
+  if (newContent != null) setUp(newContent.size());
+  this.content = newContent;
 }
 /**
  * Returns the content of this matrix if it is a wrapper; or <tt>this</tt> otherwise.
  * Override this method in wrappers.
  */
 protected DoubleMatrix1D getContent() {
-	return this.content;
+  return this.content;
 }
 /**
  * Returns the matrix cell value at coordinate <tt>index</tt>.
@@ -43,7 +43,7 @@
  * @return    the value of the specified cell.
  */
 public double getQuick(int index) {
-	return content.getQuick(index);
+  return content.getQuick(index);
 }
 /**
  * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified size.
@@ -55,7 +55,7 @@
  * @return  a new empty matrix of the same dynamic type.
  */
 public DoubleMatrix1D like(int size) {
-	return content.like(size);
+  return content.like(size);
 }
 /**
  * Construct and returns a new 2-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver.
@@ -67,7 +67,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 public DoubleMatrix2D like2D(int rows, int columns) {
-	return content.like2D(rows,columns);
+  return content.like2D(rows,columns);
 }
 /**
  * Sets the matrix cell at coordinate <tt>index</tt> to the specified value.
@@ -80,7 +80,7 @@
  * @param    value the value to be filled into the specified cell.
  */
 public void setQuick(int index, double value) {
-	content.setQuick(index, value);
+  content.setQuick(index, value);
 }
 /**
 Constructs and returns a new <i>flip view</i>.
@@ -90,15 +90,15 @@
 @return a new flip view.
 */
 public DoubleMatrix1D viewFlip() {
-	DoubleMatrix1D view = new WrapperDoubleMatrix1D(this) {
-		public double getQuick(int index) {
-			return content.get(size-1-index);
-		}
-		public void setQuick(int index, double value) {
-			content.set(size-1-index,value); 
-		}
-	};
-	return view;
+  DoubleMatrix1D view = new WrapperDoubleMatrix1D(this) {
+    public double getQuick(int index) {
+      return content.get(size-1-index);
+    }
+    public void setQuick(int index, double value) {
+      content.set(size-1-index,value); 
+    }
+  };
+  return view;
 }
 /**
 Constructs and returns a new <i>sub-range view</i> that is a <tt>width</tt> sub matrix starting at <tt>index</tt>.
@@ -117,22 +117,22 @@
 
 @param     index   The index of the first cell.
 @param     width   The width of the range.
-@throws	IndexOutOfBoundsException if <tt>index<0 || width<0 || index+width>size()</tt>.
+@throws  IndexOutOfBoundsException if <tt>index<0 || width<0 || index+width>size()</tt>.
 @return the new view.
-		
+    
 */
 public DoubleMatrix1D viewPart(final int index, int width) {
-	checkRange(index,width);
-	DoubleMatrix1D view = new WrapperDoubleMatrix1D(this) {
-		public double getQuick(int i) {
-			return content.get(index+i);
-		}
-		public void setQuick(int i, double value) {
-			content.set(index+i,value); 
-		}
-	};
-	view.size=width;
-	return view;
+  checkRange(index,width);
+  DoubleMatrix1D view = new WrapperDoubleMatrix1D(this) {
+    public double getQuick(int i) {
+      return content.get(index+i);
+    }
+    public void setQuick(int i, double value) {
+      content.set(index+i,value); 
+    }
+  };
+  view.size=width;
+  return view;
 }
 /**
 Constructs and returns a new <i>selection view</i> that is a matrix holding the indicated cells.
@@ -155,25 +155,25 @@
 @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);
-	final int[] idx = indexes;
-
-	DoubleMatrix1D view = new WrapperDoubleMatrix1D(this) {
-		public double getQuick(int i) {
-			return content.get(idx[i]);
-		}
-		public void setQuick(int i, double value) {
-			content.set(idx[i],value); 
-		}
-	};
-	view.size=indexes.length;
-	return view;
+  // 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) {
+    public double getQuick(int i) {
+      return content.get(idx[i]);
+    }
+    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.
@@ -182,29 +182,29 @@
  * @return  a new view.
  */
 protected DoubleMatrix1D viewSelectionLike(int[] offsets) {
-	throw new InternalError(); // should never get called
+  throw new InternalError(); // 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  stride  the step factor.
-@throws	IndexOutOfBoundsException if <tt>stride <= 0</tt>.
+@throws  IndexOutOfBoundsException if <tt>stride <= 0</tt>.
 @return the new view.
-		
+    
 */
 public DoubleMatrix1D viewStrides(final int _stride) {
-	if (stride<=0) throw new IndexOutOfBoundsException("illegal stride: "+stride);
-	DoubleMatrix1D view = new WrapperDoubleMatrix1D(this) {
-		public double getQuick(int index) {
-			return content.get(index*_stride);
-		}
-		public void setQuick(int index, double value) {
-			content.set(index*_stride,value); 
-		}
-	};
-	view.size = size;
-	if (size!=0) view.size = (size-1)/_stride +1;
-	return view;
+  if (stride<=0) throw new IndexOutOfBoundsException("illegal stride: "+stride);
+  DoubleMatrix1D view = new WrapperDoubleMatrix1D(this) {
+    public double getQuick(int index) {
+      return content.get(index*_stride);
+    }
+    public void setQuick(int index, double value) {
+      content.set(index*_stride,value); 
+    }
+  };
+  view.size = size;
+  if (size!=0) view.size = (size-1)/_stride +1;
+  return view;
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/WrapperDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/WrapperDoubleMatrix2D.java?rev=883974&r1=883973&r2=883974&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/WrapperDoubleMatrix2D.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/WrapperDoubleMatrix2D.java Wed Nov 25 03:41:28 2009
@@ -17,10 +17,10 @@
 @version 1.0, 04/14/2000
 */
 class WrapperDoubleMatrix2D extends DoubleMatrix2D {
-	/*
-	 * The elements of the matrix.
-	 */
-	protected DoubleMatrix2D content;
+  /*
+   * The elements of the matrix.
+   */
+  protected DoubleMatrix2D content;
 /**
  * Constructs a matrix with a copy of the given values.
  * <tt>values</tt> is required to have the form <tt>values[row][column]</tt>
@@ -32,15 +32,15 @@
  * @throws IllegalArgumentException if <tt>for any 1 &lt;= row &lt; values.length: values[row].length != values[row-1].length</tt>.
  */
 public WrapperDoubleMatrix2D(DoubleMatrix2D newContent) {
-	if (newContent != null) setUp(newContent.rows(),newContent.columns());
-	this.content = newContent;
+  if (newContent != null) setUp(newContent.rows(),newContent.columns());
+  this.content = newContent;
 }
 /**
  * Returns the content of this matrix if it is a wrapper; or <tt>this</tt> otherwise.
  * Override this method in wrappers.
  */
 protected DoubleMatrix2D getContent() {
-	return content;
+  return content;
 }
 /**
  * Returns the matrix cell value at coordinate <tt>[row,column]</tt>.
@@ -54,7 +54,7 @@
  * @return    the value at the specified coordinate.
  */
 public double getQuick(int row, int column) {
-	return content.getQuick(row,column);
+  return content.getQuick(row,column);
 }
 /**
  * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of rows and columns.
@@ -67,7 +67,7 @@
  * @return  a new empty matrix of the same dynamic type.
  */
 public DoubleMatrix2D like(int rows, int columns) {
-	return content.like(rows,columns);
+  return content.like(rows,columns);
 }
 /**
  * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver.
@@ -78,7 +78,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 public DoubleMatrix1D like1D(int size) {
-	return content.like1D(size);
+  return content.like1D(size);
 }
 /**
  * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, sharing the same cells.
@@ -91,7 +91,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 protected DoubleMatrix1D like1D(int size, int offset, int stride) {
-	throw new InternalError(); // should never get called
+  throw new InternalError(); // should never get called
 }
 /**
  * Sets the matrix cell at coordinate <tt>[row,column]</tt> to the specified value.
@@ -105,7 +105,7 @@
  * @param    value the value to be filled into the specified cell.
  */
 public void setQuick(int row, int column, double value) {
-	content.setQuick(row,column, value);
+  content.setQuick(row,column, value);
 }
 /**
 Constructs and returns a new <i>slice view</i> representing the rows of the given column.
@@ -115,12 +115,12 @@
 <b>Example:</b> 
 <table border="0">
   <tr nowrap> 
-	<td valign="top">2 x 3 matrix: <br>
-	  1, 2, 3<br>
-	  4, 5, 6 </td>
-	<td>viewColumn(0) ==></td>
-	<td valign="top">Matrix1D of size 2:<br>
-	  1, 4</td>
+  <td valign="top">2 x 3 matrix: <br>
+    1, 2, 3<br>
+    4, 5, 6 </td>
+  <td>viewColumn(0) ==></td>
+  <td valign="top">Matrix1D of size 2:<br>
+    1, 4</td>
    </tr>
 </table>
 
@@ -130,7 +130,7 @@
 @see #viewRow(int)
 */
 public DoubleMatrix1D viewColumn(int column) {
-	return viewDice().viewRow(column);
+  return viewDice().viewRow(column);
 }
 /**
 Constructs and returns a new <i>flip view</i> along the column axis.
@@ -140,17 +140,17 @@
 <b>Example:</b> 
 <table border="0">
   <tr nowrap> 
-	<td valign="top">2 x 3 matrix: <br>
-	  1, 2, 3<br>
-	  4, 5, 6 </td>
-	<td>columnFlip ==></td>
-	<td valign="top">2 x 3 matrix:<br>
-	  3, 2, 1 <br>
-	  6, 5, 4</td>
-	<td>columnFlip ==></td>
-	<td valign="top">2 x 3 matrix: <br>
-	  1, 2, 3<br>
-	  4, 5, 6 </td>
+  <td valign="top">2 x 3 matrix: <br>
+    1, 2, 3<br>
+    4, 5, 6 </td>
+  <td>columnFlip ==></td>
+  <td valign="top">2 x 3 matrix:<br>
+    3, 2, 1 <br>
+    6, 5, 4</td>
+  <td>columnFlip ==></td>
+  <td valign="top">2 x 3 matrix: <br>
+    1, 2, 3<br>
+    4, 5, 6 </td>
   </tr>
 </table>
 
@@ -158,16 +158,16 @@
 @see #viewRowFlip()
 */
 public DoubleMatrix2D viewColumnFlip() {
-	if (columns==0) return this;
-	DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
-		public double getQuick(int row, int column) {
-			return content.get(row,columns-1-column);
-		}
-		public void setQuick(int row, int column, double value) {
-			content.set(row,columns-1-column,value); 
-		}
-	};
-	return view;
+  if (columns==0) return this;
+  DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
+    public double getQuick(int row, int column) {
+      return content.get(row,columns-1-column);
+    }
+    public void setQuick(int row, int column, double value) {
+      content.set(row,columns-1-column,value); 
+    }
+  };
+  return view;
 }
 /**
 Constructs and returns a new <i>dice (transposition) view</i>; Swaps axes; example: 3 x 4 matrix --> 4 x 3 matrix.
@@ -180,35 +180,35 @@
 <b>Example:</b> 
 <table border="0">
   <tr nowrap> 
-	<td valign="top">2 x 3 matrix: <br>
-	  1, 2, 3<br>
-	  4, 5, 6 </td>
-	<td>transpose ==></td>
-	<td valign="top">3 x 2 matrix:<br>
-	  1, 4 <br>
-	  2, 5 <br>
-	  3, 6</td>
-	<td>transpose ==></td>
-	<td valign="top">2 x 3 matrix: <br>
-	  1, 2, 3<br>
-	  4, 5, 6 </td>
+  <td valign="top">2 x 3 matrix: <br>
+    1, 2, 3<br>
+    4, 5, 6 </td>
+  <td>transpose ==></td>
+  <td valign="top">3 x 2 matrix:<br>
+    1, 4 <br>
+    2, 5 <br>
+    3, 6</td>
+  <td>transpose ==></td>
+  <td valign="top">2 x 3 matrix: <br>
+    1, 2, 3<br>
+    4, 5, 6 </td>
   </tr>
 </table>
 
 @return a new dice view.
 */
 public DoubleMatrix2D viewDice() {
-	DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
-		public double getQuick(int row, int column) {
-			return content.get(column,row);
-		}
-		public void setQuick(int row, int column, double value) {
-			content.set(column,row,value); 
-		}
-	};
-	view.rows = columns;
-	view.columns = rows;
-	return view;
+  DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
+    public double getQuick(int row, int column) {
+      return content.get(column,row);
+    }
+    public void setQuick(int row, int column, double value) {
+      content.set(column,row,value); 
+    }
+  };
+  view.rows = columns;
+  view.columns = rows;
+  return view;
 }
 /**
 Constructs and returns a new <i>sub-range view</i> that is a <tt>height x width</tt> sub matrix starting at <tt>[row,column]</tt>.
@@ -229,24 +229,24 @@
 @param     column   The index of the column-coordinate.
 @param     height   The height of the box.
 @param     width   The width of the box.
-@throws	IndexOutOfBoundsException if <tt>column<0 || width<0 || column+width>columns() || row<0 || height<0 || row+height>rows()</tt>
+@throws  IndexOutOfBoundsException if <tt>column<0 || width<0 || column+width>columns() || row<0 || height<0 || row+height>rows()</tt>
 @return the new view.
-		
+    
 */
 public DoubleMatrix2D viewPart(final int row, final int column, int height, int width) {
-	checkBox(row,column,height,width);
-	DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
-		public double getQuick(int i, int j) {
-			return content.get(row+i,column+j);
-		}
-		public void setQuick(int i, int j, double value) {
-			content.set(row+i,column+j,value); 
-		}
-	};
-	view.rows = height;
-	view.columns = width;
+  checkBox(row,column,height,width);
+  DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
+    public double getQuick(int i, int j) {
+      return content.get(row+i,column+j);
+    }
+    public void setQuick(int i, int j, double value) {
+      content.set(row+i,column+j,value); 
+    }
+  };
+  view.rows = height;
+  view.columns = width;
 
-	return view;
+  return view;
 }
 /**
 Constructs and returns a new <i>slice view</i> representing the columns of the given row.
@@ -256,12 +256,12 @@
 <b>Example:</b> 
 <table border="0">
   <tr nowrap> 
-	<td valign="top">2 x 3 matrix: <br>
-	  1, 2, 3<br>
-	  4, 5, 6 </td>
-	<td>viewRow(0) ==></td>
-	<td valign="top">Matrix1D of size 3:<br>
-	  1, 2, 3</td>
+  <td valign="top">2 x 3 matrix: <br>
+    1, 2, 3<br>
+    4, 5, 6 </td>
+  <td>viewRow(0) ==></td>
+  <td valign="top">Matrix1D of size 3:<br>
+    1, 2, 3</td>
    </tr>
 </table>
 
@@ -271,8 +271,8 @@
 @see #viewColumn(int)
 */
 public DoubleMatrix1D viewRow(int row) {
-	checkRow(row);
-	return new DelegateDoubleMatrix1D(this,row);
+  checkRow(row);
+  return new DelegateDoubleMatrix1D(this,row);
 }
 /**
 Constructs and returns a new <i>flip view</i> along the row axis.
@@ -282,17 +282,17 @@
 <b>Example:</b> 
 <table border="0">
   <tr nowrap> 
-	<td valign="top">2 x 3 matrix: <br>
-	  1, 2, 3<br>
-	  4, 5, 6 </td>
-	<td>rowFlip ==></td>
-	<td valign="top">2 x 3 matrix:<br>
-	  4, 5, 6 <br>
-	  1, 2, 3</td>
-	<td>rowFlip ==></td>
-	<td valign="top">2 x 3 matrix: <br>
-	  1, 2, 3<br>
-	  4, 5, 6 </td>
+  <td valign="top">2 x 3 matrix: <br>
+    1, 2, 3<br>
+    4, 5, 6 </td>
+  <td>rowFlip ==></td>
+  <td valign="top">2 x 3 matrix:<br>
+    4, 5, 6 <br>
+    1, 2, 3</td>
+  <td>rowFlip ==></td>
+  <td valign="top">2 x 3 matrix: <br>
+    1, 2, 3<br>
+    4, 5, 6 </td>
   </tr>
 </table>
 
@@ -300,16 +300,16 @@
 @see #viewColumnFlip()
 */
 public DoubleMatrix2D viewRowFlip() {
-	if (rows==0) return this;
-	DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
-		public double getQuick(int row, int column) {
-			return content.get(rows-1-row,column);
-		}
-		public void setQuick(int row, int column, double value) {
-			content.set(rows-1-row,column,value); 
-		}
-	};
-	return view;
+  if (rows==0) return this;
+  DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
+    public double getQuick(int row, int column) {
+      return content.get(rows-1-row,column);
+    }
+    public void setQuick(int row, int column, double value) {
+      content.set(rows-1-row,column,value); 
+    }
+  };
+  return view;
 }
 /**
 Constructs and returns a new <i>selection view</i> that is a matrix holding the indicated cells.
@@ -339,33 +339,33 @@
 @throws IndexOutOfBoundsException if <tt>!(0 <= columnIndexes[i] < columns())</tt> for any <tt>i=0..columnIndexes.length()-1</tt>.
 */
 public DoubleMatrix2D viewSelection(int[] rowIndexes, int[] columnIndexes) {
-	// check for "all"
-	if (rowIndexes==null) {
-		rowIndexes = new int[rows];
-		for (int i=rows; --i >= 0; ) rowIndexes[i] = i;
-	}
-	if (columnIndexes==null) {
-		columnIndexes = new int[columns];
-		for (int i=columns; --i >= 0; ) columnIndexes[i] = i;
-	}
-	
-	checkRowIndexes(rowIndexes);
-	checkColumnIndexes(columnIndexes);
-	final int[] rix = rowIndexes;
-	final int[] cix = columnIndexes;
-	
-	DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
-		public double getQuick(int i, int j) {
-			return content.get(rix[i],cix[j]);
-		}
-		public void setQuick(int i, int j, double value) {
-			content.set(rix[i],cix[j],value); 
-		}
-	};
-	view.rows = rowIndexes.length;
-	view.columns = columnIndexes.length;
+  // check for "all"
+  if (rowIndexes==null) {
+    rowIndexes = new int[rows];
+    for (int i=rows; --i >= 0; ) rowIndexes[i] = i;
+  }
+  if (columnIndexes==null) {
+    columnIndexes = new int[columns];
+    for (int i=columns; --i >= 0; ) columnIndexes[i] = i;
+  }
+  
+  checkRowIndexes(rowIndexes);
+  checkColumnIndexes(columnIndexes);
+  final int[] rix = rowIndexes;
+  final int[] cix = columnIndexes;
+  
+  DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
+    public double getQuick(int i, int j) {
+      return content.get(rix[i],cix[j]);
+    }
+    public void setQuick(int i, int j, double value) {
+      content.set(rix[i],cix[j],value); 
+    }
+  };
+  view.rows = rowIndexes.length;
+  view.columns = columnIndexes.length;
 
-	return view;
+  return view;
 }
 /**
  * Construct and returns a new selection view.
@@ -375,7 +375,7 @@
  * @return  a new view.
  */
 protected DoubleMatrix2D viewSelectionLike(int[] rowOffsets, int[] columnOffsets) {
-	throw new InternalError(); // should never be called
+  throw new InternalError(); // should never be called
 }
 /**
 Constructs and returns a new <i>stride view</i> which is a sub matrix consisting of every i-th cell.
@@ -385,22 +385,22 @@
 @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>.
+@throws  IndexOutOfBoundsException if <tt>rowStride<=0 || columnStride<=0</tt>.
 */
 public DoubleMatrix2D viewStrides(final int _rowStride, final int _columnStride) {
-	if (_rowStride<=0 || _columnStride<=0) throw new IndexOutOfBoundsException("illegal stride");
-	DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
-		public double getQuick(int row, int column) {
-			return content.get(_rowStride*row, _columnStride*column);
-		}
-		public void setQuick(int row, int column, double value) {
-			content.set(_rowStride*row, _columnStride*column, value); 
-		}
-	};
-	view.rows = rows;
-	view.columns = columns;
-	if (rows!=0) view.rows = (rows-1)/_rowStride +1;
-	if (columns!=0) view.columns = (columns-1)/_columnStride +1;
-	return view;
+  if (_rowStride<=0 || _columnStride<=0) throw new IndexOutOfBoundsException("illegal stride");
+  DoubleMatrix2D view = new WrapperDoubleMatrix2D(this) {
+    public double getQuick(int row, int column) {
+      return content.get(_rowStride*row, _columnStride*column);
+    }
+    public void setQuick(int row, int column, double value) {
+      content.set(_rowStride*row, _columnStride*column, value); 
+    }
+  };
+  view.rows = rows;
+  view.columns = columns;
+  if (rows!=0) view.rows = (rows-1)/_rowStride +1;
+  if (columns!=0) view.columns = (columns-1)/_columnStride +1;
+  return view;
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/package.html
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/package.html?rev=883974&r1=883973&r2=883974&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/package.html (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/package.html Wed Nov 25 03:41:28 2009
@@ -1,6 +1,6 @@
 <HTML>
 <BODY>
 Matrix <i>implementations</i>; You normally need not look at this package, because all concrete classes implement the
-abstract interfaces of {@link cern.colt.matrix}, <i>without subsetting or supersetting</i>.
+abstract interfaces of {@link org.apache.mahout.matrix.matrix}, <i>without subsetting or supersetting</i>.
 </BODY>
 </HTML>
\ No newline at end of file