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 [13/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/SelectedSparseDoubleMatrix3D.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseDoubleMatrix3D.java?rev=883974&r1=883973&r2=883974&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseDoubleMatrix3D.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseDoubleMatrix3D.java Wed Nov 25 03:41:28 2009
@@ -44,23 +44,23 @@
 @version 1.0, 09/24/99
 */
 class SelectedSparseDoubleMatrix3D extends DoubleMatrix3D {
-	/**
-	  * The elements of this matrix.
-	  */
-	protected AbstractIntDoubleMap elements;
-	
-	/**
-	  * The offsets of the visible cells of this matrix.
-	  */
-	protected int[] sliceOffsets;
-	protected int[] rowOffsets;
-	protected int[] columnOffsets;
-	
-	/**
-	  * The offset.
-	  */
-	protected int offset;	
-	
+  /**
+    * The elements of this matrix.
+    */
+  protected AbstractIntDoubleMap elements;
+  
+  /**
+    * The offsets of the visible cells of this matrix.
+    */
+  protected int[] sliceOffsets;
+  protected int[] rowOffsets;
+  protected int[] columnOffsets;
+  
+  /**
+    * The offset.
+    */
+  protected int offset;  
+  
 /**
  * Constructs a matrix view with the given parameters.
  * @param elements the cells.
@@ -69,21 +69,21 @@
  * @param  columnOffsets   The column offsets of the cells that shall be visible.
  */
 protected SelectedSparseDoubleMatrix3D(AbstractIntDoubleMap elements, int[] sliceOffsets, int[] rowOffsets, int[] columnOffsets, int offset) {
-	// be sure parameters are valid, we do not check...
-	int slices = sliceOffsets.length;
-	int rows = rowOffsets.length;
-	int columns = columnOffsets.length;
-	setUp(slices,rows, columns);
-	
-	this.elements = elements;
-	
-	this.sliceOffsets = sliceOffsets;
-	this.rowOffsets = rowOffsets;
-	this.columnOffsets = columnOffsets;
-
-	this.offset = offset;
-	
-	this.isNoView = false;
+  // be sure parameters are valid, we do not check...
+  int slices = sliceOffsets.length;
+  int rows = rowOffsets.length;
+  int columns = columnOffsets.length;
+  setUp(slices,rows, columns);
+  
+  this.elements = elements;
+  
+  this.sliceOffsets = sliceOffsets;
+  this.rowOffsets = rowOffsets;
+  this.columnOffsets = columnOffsets;
+
+  this.offset = offset;
+  
+  this.isNoView = false;
 }
 /**
  * Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -93,7 +93,7 @@
  * @return the position.
  */
 protected int _columnOffset(int absRank) {
-	return columnOffsets[absRank];
+  return columnOffsets[absRank];
 }
 /**
  * Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -103,7 +103,7 @@
  * @return the position.
  */
 protected int _rowOffset(int absRank) {
-	return rowOffsets[absRank];
+  return rowOffsets[absRank];
 }
 /**
  * Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -113,7 +113,7 @@
  * @return the position.
  */
 protected int _sliceOffset(int absRank) {
-	return sliceOffsets[absRank];
+  return sliceOffsets[absRank];
 }
 /**
  * Returns the matrix cell value at coordinate <tt>[slice,row,column]</tt>.
@@ -128,10 +128,10 @@
  * @return    the value at the specified coordinate.
  */
 public double getQuick(int slice, int row, int column) {
-	//if (debug) if (slice<0 || slice>=slices || row<0 || row>=rows || column<0 || column>=columns) throw new IndexOutOfBoundsException("slice:"+slice+", row:"+row+", column:"+column);
-	//return elements.get(index(slice,row,column));
-	//manually inlined:
-	return elements.get(offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride]);
+  //if (debug) if (slice<0 || slice>=slices || row<0 || row>=rows || column<0 || column>=columns) throw new IndexOutOfBoundsException("slice:"+slice+", row:"+row+", column:"+column);
+  //return elements.get(index(slice,row,column));
+  //manually inlined:
+  return elements.get(offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride]);
 }
 /**
  * Returns <tt>true</tt> if both matrices share common cells.
@@ -143,15 +143,15 @@
  * </ul>
  */
 protected boolean haveSharedCellsRaw(DoubleMatrix3D other) {
-	if (other instanceof SelectedSparseDoubleMatrix3D) {
-		SelectedSparseDoubleMatrix3D otherMatrix = (SelectedSparseDoubleMatrix3D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	else if (other instanceof SparseDoubleMatrix3D) {
-		SparseDoubleMatrix3D otherMatrix = (SparseDoubleMatrix3D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	return false;
+  if (other instanceof SelectedSparseDoubleMatrix3D) {
+    SelectedSparseDoubleMatrix3D otherMatrix = (SelectedSparseDoubleMatrix3D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  else if (other instanceof SparseDoubleMatrix3D) {
+    SparseDoubleMatrix3D otherMatrix = (SparseDoubleMatrix3D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  return false;
 }
 /**
  * Returns the position of the given coordinate within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -161,9 +161,9 @@
  * @param     column   the index of the third-coordinate.
  */
 protected int index(int slice, int row, int column) {
-	//return this.offset + super.index(slice,row,column);
-	//manually inlined:
-	return this.offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
+  //return this.offset + super.index(slice,row,column);
+  //manually inlined:
+  return this.offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
 }
 /**
  * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of slices, rows and columns.
@@ -177,7 +177,7 @@
  * @return  a new empty matrix of the same dynamic type.
  */
 public DoubleMatrix3D like(int slices, int rows, int columns) {
-	return new SparseDoubleMatrix3D(slices,rows,columns); 
+  return new SparseDoubleMatrix3D(slices,rows,columns); 
 }
 /**
  * Construct and returns a new 2-d matrix <i>of the corresponding dynamic type</i>, sharing the same cells.
@@ -193,7 +193,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 protected DoubleMatrix2D like2D(int rows, int columns, int rowZero, int columnZero, int rowStride, int columnStride) {
-	throw new InternalError(); // this method is never called since viewRow() and viewColumn are overridden properly.
+  throw new InternalError(); // this method is never called since viewRow() and viewColumn are overridden properly.
 }
 /**
  * Sets the matrix cell at coordinate <tt>[slice,row,column]</tt> to the specified value.
@@ -208,47 +208,47 @@
  * @param    value the value to be filled into the specified cell.
  */
 public void setQuick(int slice, int row, int column, double value) {
-	//if (debug) if (slice<0 || slice>=slices || row<0 || row>=rows || column<0 || column>=columns) throw new IndexOutOfBoundsException("slice:"+slice+", row:"+row+", column:"+column);
-	//int index =	index(slice,row,column);
-	//manually inlined:
-	int index = offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
-	if (value == 0)
-		this.elements.removeKey(index);
-	else 
-		this.elements.put(index, value);
+  //if (debug) if (slice<0 || slice>=slices || row<0 || row>=rows || column<0 || column>=columns) throw new IndexOutOfBoundsException("slice:"+slice+", row:"+row+", column:"+column);
+  //int index =  index(slice,row,column);
+  //manually inlined:
+  int index = offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
+  if (value == 0)
+    this.elements.removeKey(index);
+  else 
+    this.elements.put(index, value);
 }
 /**
  * Sets up a matrix with a given number of slices and rows.
  * @param slices the number of slices the matrix shall have.
  * @param rows the number of rows the matrix shall have.
  * @param columns the number of columns the matrix shall have.
- * @throws	IllegalArgumentException if <tt>(double)rows*slices > Integer.MAX_VALUE</tt>.
+ * @throws  IllegalArgumentException if <tt>(double)rows*slices > Integer.MAX_VALUE</tt>.
  */
 protected void setUp(int slices, int rows, int columns) {
-	super.setUp(slices,rows,columns);
-	this.sliceStride = 1;
-	this.rowStride = 1;
-	this.columnStride = 1;
-	this.offset = 0;
+  super.setUp(slices,rows,columns);
+  this.sliceStride = 1;
+  this.rowStride = 1;
+  this.columnStride = 1;
+  this.offset = 0;
 }
 /**
 Self modifying version of viewDice().
 @throws IllegalArgumentException if some of the parameters are equal or not in range 0..2.
 */
 protected AbstractMatrix3D vDice(int axis0, int axis1, int axis2) {
-	super.vDice(axis0,axis1,axis2);
-	
-	// swap offsets
-	int[][] offsets = new int[3][];
-	offsets[0] = this.sliceOffsets;
-	offsets[1] = this.rowOffsets;
-	offsets[2] = this.columnOffsets;
-
-	this.sliceOffsets = offsets[axis0];
-	this.rowOffsets = offsets[axis1];
-	this.columnOffsets = offsets[axis2];
+  super.vDice(axis0,axis1,axis2);
+  
+  // swap offsets
+  int[][] offsets = new int[3][];
+  offsets[0] = this.sliceOffsets;
+  offsets[1] = this.rowOffsets;
+  offsets[2] = this.columnOffsets;
+
+  this.sliceOffsets = offsets[axis0];
+  this.rowOffsets = offsets[axis1];
+  this.columnOffsets = offsets[axis2];
 
-	return this;
+  return this;
 }
 /**
 Constructs and returns a new 2-dimensional <i>slice view</i> representing the slices and rows of the given column.
@@ -265,22 +265,22 @@
 @see #viewRow(int)
 */
 public DoubleMatrix2D viewColumn(int column) {
-	checkColumn(column);
-	
-	int viewRows = this.slices;
-	int viewColumns = this.rows;
-	
-	int viewRowZero = sliceZero;
-	int viewColumnZero = rowZero;
-	int viewOffset = this.offset + _columnOffset(_columnRank(column));
+  checkColumn(column);
+  
+  int viewRows = this.slices;
+  int viewColumns = this.rows;
+  
+  int viewRowZero = sliceZero;
+  int viewColumnZero = rowZero;
+  int viewOffset = this.offset + _columnOffset(_columnRank(column));
 
-	int viewRowStride = this.sliceStride;
-	int viewColumnStride = this.rowStride;
+  int viewRowStride = this.sliceStride;
+  int viewColumnStride = this.rowStride;
 
-	int[] viewRowOffsets = this.sliceOffsets;
-	int[] viewColumnOffsets = this.rowOffsets;
+  int[] viewRowOffsets = this.sliceOffsets;
+  int[] viewColumnOffsets = this.rowOffsets;
 
-	return new SelectedSparseDoubleMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
+  return new SelectedSparseDoubleMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
 }
 /**
 Constructs and returns a new 2-dimensional <i>slice view</i> representing the slices and columns of the given row.
@@ -297,22 +297,22 @@
 @see #viewColumn(int)
 */
 public DoubleMatrix2D viewRow(int row) {
-	checkRow(row);
-	
-	int viewRows = this.slices;
-	int viewColumns = this.columns;
-	
-	int viewRowZero = sliceZero;
-	int viewColumnZero = columnZero;
-	int viewOffset = this.offset + _rowOffset(_rowRank(row));
+  checkRow(row);
+  
+  int viewRows = this.slices;
+  int viewColumns = this.columns;
+  
+  int viewRowZero = sliceZero;
+  int viewColumnZero = columnZero;
+  int viewOffset = this.offset + _rowOffset(_rowRank(row));
 
-	int viewRowStride = this.sliceStride;
-	int viewColumnStride = this.columnStride;
+  int viewRowStride = this.sliceStride;
+  int viewColumnStride = this.columnStride;
 
-	int[] viewRowOffsets = this.sliceOffsets;
-	int[] viewColumnOffsets = this.columnOffsets;
+  int[] viewRowOffsets = this.sliceOffsets;
+  int[] viewColumnOffsets = this.columnOffsets;
 
-	return new SelectedSparseDoubleMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
+  return new SelectedSparseDoubleMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
 }
 /**
  * Construct and returns a new selection view.
@@ -323,7 +323,7 @@
  * @return  a new view.
  */
 protected DoubleMatrix3D viewSelectionLike(int[] sliceOffsets, int[] rowOffsets, int[] columnOffsets) {
-	return new SelectedSparseDoubleMatrix3D(this.elements,sliceOffsets,rowOffsets,columnOffsets,this.offset);
+  return new SelectedSparseDoubleMatrix3D(this.elements,sliceOffsets,rowOffsets,columnOffsets,this.offset);
 }
 /**
 Constructs and returns a new 2-dimensional <i>slice view</i> representing the rows and columns of the given slice.
@@ -340,21 +340,21 @@
 @see #viewColumn(int)
 */
 public DoubleMatrix2D viewSlice(int slice) {
-	checkSlice(slice);
-	
-	int viewRows = this.rows;
-	int viewColumns = this.columns;
-	
-	int viewRowZero = rowZero;
-	int viewColumnZero = columnZero;
-	int viewOffset = this.offset + _sliceOffset(_sliceRank(slice));
+  checkSlice(slice);
+  
+  int viewRows = this.rows;
+  int viewColumns = this.columns;
+  
+  int viewRowZero = rowZero;
+  int viewColumnZero = columnZero;
+  int viewOffset = this.offset + _sliceOffset(_sliceRank(slice));
 
-	int viewRowStride = this.rowStride;
-	int viewColumnStride = this.columnStride;
+  int viewRowStride = this.rowStride;
+  int viewColumnStride = this.columnStride;
 
-	int[] viewRowOffsets = this.rowOffsets;
-	int[] viewColumnOffsets = this.columnOffsets;
+  int[] viewRowOffsets = this.rowOffsets;
+  int[] viewColumnOffsets = this.columnOffsets;
 
-	return new SelectedSparseDoubleMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
+  return new SelectedSparseDoubleMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix1D.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix1D.java?rev=883974&r1=883973&r2=883974&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix1D.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix1D.java Wed Nov 25 03:41:28 2009
@@ -44,20 +44,20 @@
 @version 1.0, 09/24/99
 */
 class SelectedSparseObjectMatrix1D extends ObjectMatrix1D {
-	/*
-	 * The elements of the matrix.
-	 */
-	protected AbstractIntObjectMap elements; 
-	
-	/**
-	  * The offsets of visible indexes of this matrix.
-	  */
-	protected int[] offsets;
+  /*
+   * The elements of the matrix.
+   */
+  protected AbstractIntObjectMap elements; 
+  
+  /**
+    * The offsets of visible indexes of this matrix.
+    */
+  protected int[] offsets;
 
-	/**
-	  * The offset.
-	  */
-	protected int offset;	
+  /**
+    * The offset.
+    */
+  protected int offset;  
 /**
  * Constructs a matrix view with the given parameters.
  * @param size the number of cells the matrix shall have.
@@ -68,12 +68,12 @@
  * @param offset   
  */
 protected SelectedSparseObjectMatrix1D(int size, AbstractIntObjectMap elements, int zero, int stride, int[] offsets, int offset) {
-	setUp(size,zero,stride);
-	
-	this.elements = elements;
-	this.offsets = offsets;
-	this.offset = offset;
-	this.isNoView = false;
+  setUp(size,zero,stride);
+  
+  this.elements = elements;
+  this.offsets = offsets;
+  this.offset = offset;
+  this.isNoView = false;
 }
 /**
  * Constructs a matrix view with the given parameters.
@@ -81,7 +81,7 @@
  * @param  indexes   The indexes of the cells that shall be visible.
  */
 protected SelectedSparseObjectMatrix1D(AbstractIntObjectMap elements, int[] offsets) {
-	this(offsets.length,elements,0,1,offsets,0);
+  this(offsets.length,elements,0,1,offsets,0);
 }
 /**
  * Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -91,7 +91,7 @@
  * @return the position.
  */
 protected int _offset(int absRank) {
-	return offsets[absRank];
+  return offsets[absRank];
 }
 /**
  * Returns the matrix cell value at coordinate <tt>index</tt>.
@@ -104,24 +104,24 @@
  * @return    the value of the specified cell.
  */
 public Object getQuick(int index) {
-	//if (debug) if (index<0 || index>=size) checkIndex(index);
-	//return elements.get(index(index));
-	//manually inlined:
-	return elements.get(offset + offsets[zero + index*stride]);
+  //if (debug) if (index<0 || index>=size) checkIndex(index);
+  //return elements.get(index(index));
+  //manually inlined:
+  return elements.get(offset + offsets[zero + index*stride]);
 }
 /**
  * Returns <tt>true</tt> if both matrices share at least one identical cell.
  */
 protected boolean haveSharedCellsRaw(ObjectMatrix1D other) {
-	if (other instanceof SelectedSparseObjectMatrix1D) {
-		SelectedSparseObjectMatrix1D otherMatrix = (SelectedSparseObjectMatrix1D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	else if (other instanceof SparseObjectMatrix1D) {
-		SparseObjectMatrix1D otherMatrix = (SparseObjectMatrix1D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	return false;
+  if (other instanceof SelectedSparseObjectMatrix1D) {
+    SelectedSparseObjectMatrix1D otherMatrix = (SelectedSparseObjectMatrix1D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  else if (other instanceof SparseObjectMatrix1D) {
+    SparseObjectMatrix1D otherMatrix = (SparseObjectMatrix1D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  return false;
 }
 /**
  * Returns the position of the element with the given relative rank within the (virtual or non-virtual) internal 1-dimensional array.
@@ -130,9 +130,9 @@
  * @param     rank   the rank of the element.
  */
 protected int index(int rank) {
-	//return this.offset + super.index(rank);
-	// manually inlined:
-	return offset + offsets[zero + rank*stride];
+  //return this.offset + super.index(rank);
+  // manually inlined:
+  return offset + offsets[zero + rank*stride];
 }
 /**
  * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified size.
@@ -144,7 +144,7 @@
  * @return  a new empty matrix of the same dynamic type.
  */
 public ObjectMatrix1D like(int size) {
-	return new SparseObjectMatrix1D(size);
+  return new SparseObjectMatrix1D(size);
 }
 /**
  * Construct and returns a new 2-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver.
@@ -156,7 +156,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 public ObjectMatrix2D like2D(int rows, int columns) {
-	return new SparseObjectMatrix2D(rows,columns);
+  return new SparseObjectMatrix2D(rows,columns);
 }
 /**
  * Sets the matrix cell at coordinate <tt>index</tt> to the specified value.
@@ -169,23 +169,23 @@
  * @param    value the value to be filled into the specified cell.
  */
 public void setQuick(int index, Object value) {
-	//if (debug) if (index<0 || index>=size) checkIndex(index);
-	//int i =	index(index);
-	//manually inlined:
-	int i = offset + offsets[zero + index*stride];
-	if (value == null)
-		this.elements.removeKey(i);
-	else 
-		this.elements.put(i, value);
+  //if (debug) if (index<0 || index>=size) checkIndex(index);
+  //int i =  index(index);
+  //manually inlined:
+  int i = offset + offsets[zero + index*stride];
+  if (value == null)
+    this.elements.removeKey(i);
+  else 
+    this.elements.put(i, value);
 }
 /**
  * Sets up a matrix with a given number of cells.
  * @param size the number of cells the matrix shall have.
  */
 protected void setUp(int size) {
-	super.setUp(size);
-	this.stride = 1;
-	this.offset = 0;
+  super.setUp(size);
+  this.stride = 1;
+  this.offset = 0;
 }
 /**
  * Construct and returns a new selection view.
@@ -194,6 +194,6 @@
  * @return  a new view.
  */
 protected ObjectMatrix1D viewSelectionLike(int[] offsets) {
-	return new SelectedSparseObjectMatrix1D(this.elements,offsets);
+  return new SelectedSparseObjectMatrix1D(this.elements,offsets);
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix2D.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix2D.java?rev=883974&r1=883973&r2=883974&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix2D.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix2D.java Wed Nov 25 03:41:28 2009
@@ -44,21 +44,21 @@
 @version 1.0, 09/24/99
 */
 class SelectedSparseObjectMatrix2D extends ObjectMatrix2D {
-	/*
-	 * The elements of the matrix.
-	 */
-	protected AbstractIntObjectMap elements; 
-	
-	/**
-	  * The offsets of the visible cells of this matrix.
-	  */
-	protected int[] rowOffsets;
-	protected int[] columnOffsets;
-	
-	/**
-	  * The offset.
-	  */
-	protected int offset;	
+  /*
+   * The elements of the matrix.
+   */
+  protected AbstractIntObjectMap elements; 
+  
+  /**
+    * The offsets of the visible cells of this matrix.
+    */
+  protected int[] rowOffsets;
+  protected int[] columnOffsets;
+  
+  /**
+    * The offset.
+    */
+  protected int offset;  
 /**
  * Constructs a matrix view with the given parameters.
  * @param rows the number of rows the matrix shall have.
@@ -73,15 +73,15 @@
  * @param  offset   
  */
 protected SelectedSparseObjectMatrix2D(int rows, int columns, AbstractIntObjectMap elements, int rowZero, int columnZero, int rowStride, int columnStride, int[] rowOffsets, int[] columnOffsets, int offset) {
-	// be sure parameters are valid, we do not check...
-	setUp(rows,columns,rowZero,columnZero,rowStride,columnStride);
-	
-	this.elements = elements;
-	this.rowOffsets = rowOffsets;
-	this.columnOffsets = columnOffsets;
-	this.offset = offset;
-	
-	this.isNoView = false;
+  // be sure parameters are valid, we do not check...
+  setUp(rows,columns,rowZero,columnZero,rowStride,columnStride);
+  
+  this.elements = elements;
+  this.rowOffsets = rowOffsets;
+  this.columnOffsets = columnOffsets;
+  this.offset = offset;
+  
+  this.isNoView = false;
 }
 /**
  * Constructs a matrix view with the given parameters.
@@ -91,7 +91,7 @@
  * @param  offset   
  */
 protected SelectedSparseObjectMatrix2D(AbstractIntObjectMap elements, int[] rowOffsets, int[] columnOffsets, int offset) {
-	this(rowOffsets.length,columnOffsets.length,elements,0,0,1,1,rowOffsets,columnOffsets,offset);
+  this(rowOffsets.length,columnOffsets.length,elements,0,0,1,1,rowOffsets,columnOffsets,offset);
 }
 /**
  * Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -101,7 +101,7 @@
  * @return the position.
  */
 protected int _columnOffset(int absRank) {
-	return columnOffsets[absRank];
+  return columnOffsets[absRank];
 }
 /**
  * Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -111,7 +111,7 @@
  * @return the position.
  */
 protected int _rowOffset(int absRank) {
-	return rowOffsets[absRank];
+  return rowOffsets[absRank];
 }
 /**
  * Returns the matrix cell value at coordinate <tt>[row,column]</tt>.
@@ -125,10 +125,10 @@
  * @return    the value at the specified coordinate.
  */
 public Object getQuick(int row, int column) {
-	//if (debug) if (column<0 || column>=columns || row<0 || row>=rows) throw new IndexOutOfBoundsException("row:"+row+", column:"+column);
-	//return elements.get(index(row,column));
-	//manually inlined:
-	return elements.get(offset + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride]);
+  //if (debug) if (column<0 || column>=columns || row<0 || row>=rows) throw new IndexOutOfBoundsException("row:"+row+", column:"+column);
+  //return elements.get(index(row,column));
+  //manually inlined:
+  return elements.get(offset + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride]);
 }
 /**
  * Returns <tt>true</tt> if both matrices share common cells.
@@ -140,15 +140,15 @@
  * </ul>
  */
 protected boolean haveSharedCellsRaw(ObjectMatrix2D other) {
-	if (other instanceof SelectedSparseObjectMatrix2D) {
-		SelectedSparseObjectMatrix2D otherMatrix = (SelectedSparseObjectMatrix2D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	else if (other instanceof SparseObjectMatrix2D) {
-		SparseObjectMatrix2D otherMatrix = (SparseObjectMatrix2D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	return false;
+  if (other instanceof SelectedSparseObjectMatrix2D) {
+    SelectedSparseObjectMatrix2D otherMatrix = (SelectedSparseObjectMatrix2D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  else if (other instanceof SparseObjectMatrix2D) {
+    SparseObjectMatrix2D otherMatrix = (SparseObjectMatrix2D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  return false;
 }
 /**
  * Returns the position of the given coordinate within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -157,9 +157,9 @@
  * @param     column   the index of the column-coordinate.
  */
 protected int index(int row, int column) {
-	//return this.offset + super.index(row,column);
-	//manually inlined:
-	return this.offset + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
+  //return this.offset + super.index(row,column);
+  //manually inlined:
+  return this.offset + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
 }
 /**
  * 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.
@@ -172,7 +172,7 @@
  * @return  a new empty matrix of the same dynamic type.
  */
 public ObjectMatrix2D like(int rows, int columns) {
-	return new SparseObjectMatrix2D(rows, columns);
+  return new SparseObjectMatrix2D(rows, columns);
 }
 /**
  * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver.
@@ -183,7 +183,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 public ObjectMatrix1D like1D(int size) {
-	return new SparseObjectMatrix1D(size);
+  return new SparseObjectMatrix1D(size);
 }
 /**
  * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, sharing the same cells.
@@ -196,7 +196,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 protected ObjectMatrix1D like1D(int size, int zero, int stride) {
-	throw new InternalError(); // this method is never called since viewRow() and viewColumn are overridden properly.
+  throw new InternalError(); // this method is never called since viewRow() and viewColumn are overridden properly.
 }
 /**
  * Sets the matrix cell at coordinate <tt>[row,column]</tt> to the specified value.
@@ -210,40 +210,40 @@
  * @param    value the value to be filled into the specified cell.
  */
 public void setQuick(int row, int column, Object value) {
-	//if (debug) if (column<0 || column>=columns || row<0 || row>=rows) throw new IndexOutOfBoundsException("row:"+row+", column:"+column);
-	//int index =	index(row,column);
-	//manually inlined:
-	int index = offset + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
+  //if (debug) if (column<0 || column>=columns || row<0 || row>=rows) throw new IndexOutOfBoundsException("row:"+row+", column:"+column);
+  //int index =  index(row,column);
+  //manually inlined:
+  int index = offset + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
 
-	if (value == null)
-		this.elements.removeKey(index);
-	else 
-		this.elements.put(index, value);
+  if (value == null)
+    this.elements.removeKey(index);
+  else 
+    this.elements.put(index, value);
 }
 /**
  * Sets up a matrix with a given number of rows and columns.
  * @param rows the number of rows the matrix shall have.
  * @param columns the number of columns the matrix shall have.
- * @throws	IllegalArgumentException if <tt>(Object)columns*rows > Integer.MAX_VALUE</tt>.
+ * @throws  IllegalArgumentException if <tt>(Object)columns*rows > Integer.MAX_VALUE</tt>.
  */
 protected void setUp(int rows, int columns) {
-	super.setUp(rows,columns);
-	this.rowStride = 1;
-	this.columnStride = 1;
-	this.offset = 0;
+  super.setUp(rows,columns);
+  this.rowStride = 1;
+  this.columnStride = 1;
+  this.offset = 0;
 }
 /**
 Self modifying version of viewDice().
 */
 protected AbstractMatrix2D vDice() {
-	super.vDice();
-	// swap
-	int[] tmp = rowOffsets; rowOffsets = columnOffsets; columnOffsets = tmp;
+  super.vDice();
+  // swap
+  int[] tmp = rowOffsets; rowOffsets = columnOffsets; columnOffsets = tmp;
 
-	// flips stay unaffected
+  // flips stay unaffected
 
-	this.isNoView = false;
-	return this;
+  this.isNoView = false;
+  return this;
 }
 /**
 Constructs and returns a new <i>slice view</i> representing the rows of the given column.
@@ -253,12 +253,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>
 
@@ -268,13 +268,13 @@
 @see #viewRow(int)
 */
 public ObjectMatrix1D viewColumn(int column) {
-	checkColumn(column);
-	int viewSize = this.rows;
-	int viewZero = this.rowZero;
-	int viewStride = this.rowStride;
-	int[] viewOffsets = this.rowOffsets;
-	int viewOffset = this.offset + _columnOffset(_columnRank(column));
-	return new SelectedSparseObjectMatrix1D(viewSize,this.elements,viewZero,viewStride,viewOffsets,viewOffset);
+  checkColumn(column);
+  int viewSize = this.rows;
+  int viewZero = this.rowZero;
+  int viewStride = this.rowStride;
+  int[] viewOffsets = this.rowOffsets;
+  int viewOffset = this.offset + _columnOffset(_columnRank(column));
+  return new SelectedSparseObjectMatrix1D(viewSize,this.elements,viewZero,viewStride,viewOffsets,viewOffset);
 }
 /**
 Constructs and returns a new <i>slice view</i> representing the columns of the given row.
@@ -284,12 +284,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>
 
@@ -299,13 +299,13 @@
 @see #viewColumn(int)
 */
 public ObjectMatrix1D viewRow(int row) {
-	checkRow(row);
-	int viewSize = this.columns;
-	int viewZero = columnZero;
-	int viewStride = this.columnStride;
-	int[] viewOffsets = this.columnOffsets;
-	int viewOffset = this.offset + _rowOffset(_rowRank(row));
-	return new SelectedSparseObjectMatrix1D(viewSize,this.elements,viewZero,viewStride,viewOffsets,viewOffset);
+  checkRow(row);
+  int viewSize = this.columns;
+  int viewZero = columnZero;
+  int viewStride = this.columnStride;
+  int[] viewOffsets = this.columnOffsets;
+  int viewOffset = this.offset + _rowOffset(_rowRank(row));
+  return new SelectedSparseObjectMatrix1D(viewSize,this.elements,viewZero,viewStride,viewOffsets,viewOffset);
 }
 /**
  * Construct and returns a new selection view.
@@ -315,6 +315,6 @@
  * @return  a new view.
  */
 protected ObjectMatrix2D viewSelectionLike(int[] rowOffsets, int[] columnOffsets) {
-	return new SelectedSparseObjectMatrix2D(this.elements,rowOffsets,columnOffsets,this.offset);
+  return new SelectedSparseObjectMatrix2D(this.elements,rowOffsets,columnOffsets,this.offset);
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix3D.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix3D.java?rev=883974&r1=883973&r2=883974&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix3D.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SelectedSparseObjectMatrix3D.java Wed Nov 25 03:41:28 2009
@@ -44,23 +44,23 @@
 @version 1.0, 09/24/99
 */
 class SelectedSparseObjectMatrix3D extends ObjectMatrix3D {
-	/**
-	  * The elements of this matrix.
-	  */
-	protected AbstractIntObjectMap elements;
-	
-	/**
-	  * The offsets of the visible cells of this matrix.
-	  */
-	protected int[] sliceOffsets;
-	protected int[] rowOffsets;
-	protected int[] columnOffsets;
-	
-	/**
-	  * The offset.
-	  */
-	protected int offset;	
-	
+  /**
+    * The elements of this matrix.
+    */
+  protected AbstractIntObjectMap elements;
+  
+  /**
+    * The offsets of the visible cells of this matrix.
+    */
+  protected int[] sliceOffsets;
+  protected int[] rowOffsets;
+  protected int[] columnOffsets;
+  
+  /**
+    * The offset.
+    */
+  protected int offset;  
+  
 /**
  * Constructs a matrix view with the given parameters.
  * @param elements the cells.
@@ -69,21 +69,21 @@
  * @param  columnOffsets   The column offsets of the cells that shall be visible.
  */
 protected SelectedSparseObjectMatrix3D(AbstractIntObjectMap elements, int[] sliceOffsets, int[] rowOffsets, int[] columnOffsets, int offset) {
-	// be sure parameters are valid, we do not check...
-	int slices = sliceOffsets.length;
-	int rows = rowOffsets.length;
-	int columns = columnOffsets.length;
-	setUp(slices,rows, columns);
-	
-	this.elements = elements;
-	
-	this.sliceOffsets = sliceOffsets;
-	this.rowOffsets = rowOffsets;
-	this.columnOffsets = columnOffsets;
-
-	this.offset = offset;
-	
-	this.isNoView = false;
+  // be sure parameters are valid, we do not check...
+  int slices = sliceOffsets.length;
+  int rows = rowOffsets.length;
+  int columns = columnOffsets.length;
+  setUp(slices,rows, columns);
+  
+  this.elements = elements;
+  
+  this.sliceOffsets = sliceOffsets;
+  this.rowOffsets = rowOffsets;
+  this.columnOffsets = columnOffsets;
+
+  this.offset = offset;
+  
+  this.isNoView = false;
 }
 /**
  * Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -93,7 +93,7 @@
  * @return the position.
  */
 protected int _columnOffset(int absRank) {
-	return columnOffsets[absRank];
+  return columnOffsets[absRank];
 }
 /**
  * Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -103,7 +103,7 @@
  * @return the position.
  */
 protected int _rowOffset(int absRank) {
-	return rowOffsets[absRank];
+  return rowOffsets[absRank];
 }
 /**
  * Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -113,7 +113,7 @@
  * @return the position.
  */
 protected int _sliceOffset(int absRank) {
-	return sliceOffsets[absRank];
+  return sliceOffsets[absRank];
 }
 /**
  * Returns the matrix cell value at coordinate <tt>[slice,row,column]</tt>.
@@ -128,10 +128,10 @@
  * @return    the value at the specified coordinate.
  */
 public Object getQuick(int slice, int row, int column) {
-	//if (debug) if (slice<0 || slice>=slices || row<0 || row>=rows || column<0 || column>=columns) throw new IndexOutOfBoundsException("slice:"+slice+", row:"+row+", column:"+column);
-	//return elements.get(index(slice,row,column));
-	//manually inlined:
-	return elements.get(offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride]);
+  //if (debug) if (slice<0 || slice>=slices || row<0 || row>=rows || column<0 || column>=columns) throw new IndexOutOfBoundsException("slice:"+slice+", row:"+row+", column:"+column);
+  //return elements.get(index(slice,row,column));
+  //manually inlined:
+  return elements.get(offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride]);
 }
 /**
  * Returns <tt>true</tt> if both matrices share common cells.
@@ -143,15 +143,15 @@
  * </ul>
  */
 protected boolean haveSharedCellsRaw(ObjectMatrix3D other) {
-	if (other instanceof SelectedSparseObjectMatrix3D) {
-		SelectedSparseObjectMatrix3D otherMatrix = (SelectedSparseObjectMatrix3D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	else if (other instanceof SparseObjectMatrix3D) {
-		SparseObjectMatrix3D otherMatrix = (SparseObjectMatrix3D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	return false;
+  if (other instanceof SelectedSparseObjectMatrix3D) {
+    SelectedSparseObjectMatrix3D otherMatrix = (SelectedSparseObjectMatrix3D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  else if (other instanceof SparseObjectMatrix3D) {
+    SparseObjectMatrix3D otherMatrix = (SparseObjectMatrix3D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  return false;
 }
 /**
  * Returns the position of the given coordinate within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -161,9 +161,9 @@
  * @param     column   the index of the third-coordinate.
  */
 protected int index(int slice, int row, int column) {
-	//return this.offset + super.index(slice,row,column);
-	//manually inlined:
-	return this.offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
+  //return this.offset + super.index(slice,row,column);
+  //manually inlined:
+  return this.offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
 }
 /**
  * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified number of slices, rows and columns.
@@ -177,7 +177,7 @@
  * @return  a new empty matrix of the same dynamic type.
  */
 public ObjectMatrix3D like(int slices, int rows, int columns) {
-	return new SparseObjectMatrix3D(slices,rows,columns); 
+  return new SparseObjectMatrix3D(slices,rows,columns); 
 }
 /**
  * Construct and returns a new 2-d matrix <i>of the corresponding dynamic type</i>, sharing the same cells.
@@ -193,7 +193,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 protected ObjectMatrix2D like2D(int rows, int columns, int rowZero, int columnZero, int rowStride, int columnStride) {
-	throw new InternalError(); // this method is never called since viewRow() and viewColumn are overridden properly.
+  throw new InternalError(); // this method is never called since viewRow() and viewColumn are overridden properly.
 }
 /**
  * Sets the matrix cell at coordinate <tt>[slice,row,column]</tt> to the specified value.
@@ -208,47 +208,47 @@
  * @param    value the value to be filled into the specified cell.
  */
 public void setQuick(int slice, int row, int column, Object value) {
-	//if (debug) if (slice<0 || slice>=slices || row<0 || row>=rows || column<0 || column>=columns) throw new IndexOutOfBoundsException("slice:"+slice+", row:"+row+", column:"+column);
-	//int index =	index(slice,row,column);
-	//manually inlined:
-	int index = offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
-	if (value == null)
-		this.elements.removeKey(index);
-	else 
-		this.elements.put(index, value);
+  //if (debug) if (slice<0 || slice>=slices || row<0 || row>=rows || column<0 || column>=columns) throw new IndexOutOfBoundsException("slice:"+slice+", row:"+row+", column:"+column);
+  //int index =  index(slice,row,column);
+  //manually inlined:
+  int index = offset + sliceOffsets[sliceZero + slice*sliceStride] + rowOffsets[rowZero + row*rowStride] + columnOffsets[columnZero + column*columnStride];
+  if (value == null)
+    this.elements.removeKey(index);
+  else 
+    this.elements.put(index, value);
 }
 /**
  * Sets up a matrix with a given number of slices and rows.
  * @param slices the number of slices the matrix shall have.
  * @param rows the number of rows the matrix shall have.
  * @param columns the number of columns the matrix shall have.
- * @throws	IllegalArgumentException if <tt>(Object)rows*slices > Integer.MAX_VALUE</tt>.
+ * @throws  IllegalArgumentException if <tt>(Object)rows*slices > Integer.MAX_VALUE</tt>.
  */
 protected void setUp(int slices, int rows, int columns) {
-	super.setUp(slices,rows,columns);
-	this.sliceStride = 1;
-	this.rowStride = 1;
-	this.columnStride = 1;
-	this.offset = 0;
+  super.setUp(slices,rows,columns);
+  this.sliceStride = 1;
+  this.rowStride = 1;
+  this.columnStride = 1;
+  this.offset = 0;
 }
 /**
 Self modifying version of viewDice().
 @throws IllegalArgumentException if some of the parameters are equal or not in range 0..2.
 */
 protected AbstractMatrix3D vDice(int axis0, int axis1, int axis2) {
-	super.vDice(axis0,axis1,axis2);
-	
-	// swap offsets
-	int[][] offsets = new int[3][];
-	offsets[0] = this.sliceOffsets;
-	offsets[1] = this.rowOffsets;
-	offsets[2] = this.columnOffsets;
-
-	this.sliceOffsets = offsets[axis0];
-	this.rowOffsets = offsets[axis1];
-	this.columnOffsets = offsets[axis2];
+  super.vDice(axis0,axis1,axis2);
+  
+  // swap offsets
+  int[][] offsets = new int[3][];
+  offsets[0] = this.sliceOffsets;
+  offsets[1] = this.rowOffsets;
+  offsets[2] = this.columnOffsets;
+
+  this.sliceOffsets = offsets[axis0];
+  this.rowOffsets = offsets[axis1];
+  this.columnOffsets = offsets[axis2];
 
-	return this;
+  return this;
 }
 /**
 Constructs and returns a new 2-dimensional <i>slice view</i> representing the slices and rows of the given column.
@@ -265,22 +265,22 @@
 @see #viewRow(int)
 */
 public ObjectMatrix2D viewColumn(int column) {
-	checkColumn(column);
-	
-	int viewRows = this.slices;
-	int viewColumns = this.rows;
-	
-	int viewRowZero = sliceZero;
-	int viewColumnZero = rowZero;
-	int viewOffset = this.offset + _columnOffset(_columnRank(column));
+  checkColumn(column);
+  
+  int viewRows = this.slices;
+  int viewColumns = this.rows;
+  
+  int viewRowZero = sliceZero;
+  int viewColumnZero = rowZero;
+  int viewOffset = this.offset + _columnOffset(_columnRank(column));
 
-	int viewRowStride = this.sliceStride;
-	int viewColumnStride = this.rowStride;
+  int viewRowStride = this.sliceStride;
+  int viewColumnStride = this.rowStride;
 
-	int[] viewRowOffsets = this.sliceOffsets;
-	int[] viewColumnOffsets = this.rowOffsets;
+  int[] viewRowOffsets = this.sliceOffsets;
+  int[] viewColumnOffsets = this.rowOffsets;
 
-	return new SelectedSparseObjectMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
+  return new SelectedSparseObjectMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
 }
 /**
 Constructs and returns a new 2-dimensional <i>slice view</i> representing the slices and columns of the given row.
@@ -297,22 +297,22 @@
 @see #viewColumn(int)
 */
 public ObjectMatrix2D viewRow(int row) {
-	checkRow(row);
-	
-	int viewRows = this.slices;
-	int viewColumns = this.columns;
-	
-	int viewRowZero = sliceZero;
-	int viewColumnZero = columnZero;
-	int viewOffset = this.offset + _rowOffset(_rowRank(row));
+  checkRow(row);
+  
+  int viewRows = this.slices;
+  int viewColumns = this.columns;
+  
+  int viewRowZero = sliceZero;
+  int viewColumnZero = columnZero;
+  int viewOffset = this.offset + _rowOffset(_rowRank(row));
 
-	int viewRowStride = this.sliceStride;
-	int viewColumnStride = this.columnStride;
+  int viewRowStride = this.sliceStride;
+  int viewColumnStride = this.columnStride;
 
-	int[] viewRowOffsets = this.sliceOffsets;
-	int[] viewColumnOffsets = this.columnOffsets;
+  int[] viewRowOffsets = this.sliceOffsets;
+  int[] viewColumnOffsets = this.columnOffsets;
 
-	return new SelectedSparseObjectMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
+  return new SelectedSparseObjectMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
 }
 /**
  * Construct and returns a new selection view.
@@ -323,7 +323,7 @@
  * @return  a new view.
  */
 protected ObjectMatrix3D viewSelectionLike(int[] sliceOffsets, int[] rowOffsets, int[] columnOffsets) {
-	return new SelectedSparseObjectMatrix3D(this.elements,sliceOffsets,rowOffsets,columnOffsets,this.offset);
+  return new SelectedSparseObjectMatrix3D(this.elements,sliceOffsets,rowOffsets,columnOffsets,this.offset);
 }
 /**
 Constructs and returns a new 2-dimensional <i>slice view</i> representing the rows and columns of the given slice.
@@ -340,21 +340,21 @@
 @see #viewColumn(int)
 */
 public ObjectMatrix2D viewSlice(int slice) {
-	checkSlice(slice);
-	
-	int viewRows = this.rows;
-	int viewColumns = this.columns;
-	
-	int viewRowZero = rowZero;
-	int viewColumnZero = columnZero;
-	int viewOffset = this.offset + _sliceOffset(_sliceRank(slice));
+  checkSlice(slice);
+  
+  int viewRows = this.rows;
+  int viewColumns = this.columns;
+  
+  int viewRowZero = rowZero;
+  int viewColumnZero = columnZero;
+  int viewOffset = this.offset + _sliceOffset(_sliceRank(slice));
 
-	int viewRowStride = this.rowStride;
-	int viewColumnStride = this.columnStride;
+  int viewRowStride = this.rowStride;
+  int viewColumnStride = this.columnStride;
 
-	int[] viewRowOffsets = this.rowOffsets;
-	int[] viewColumnOffsets = this.columnOffsets;
+  int[] viewRowOffsets = this.rowOffsets;
+  int[] viewColumnOffsets = this.columnOffsets;
 
-	return new SelectedSparseObjectMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
+  return new SelectedSparseObjectMatrix2D(viewRows,viewColumns,this.elements,viewRowZero,viewColumnZero,viewRowStride,viewColumnStride,viewRowOffsets,viewColumnOffsets,viewOffset);
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SparseDoubleMatrix1D.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SparseDoubleMatrix1D.java?rev=883974&r1=883973&r2=883974&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SparseDoubleMatrix1D.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SparseDoubleMatrix1D.java Wed Nov 25 03:41:28 2009
@@ -53,10 +53,10 @@
  */
 @Deprecated
 public class SparseDoubleMatrix1D extends DoubleMatrix1D {
-	/*
-	 * The elements of the matrix.
-	 */
-	protected AbstractIntDoubleMap elements; 
+  /*
+   * The elements of the matrix.
+   */
+  protected AbstractIntDoubleMap elements; 
 /**
  * Constructs a matrix with a copy of the given values.
  * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the matrix, and vice-versa.
@@ -64,8 +64,8 @@
  * @param values The values to be filled into the new matrix.
  */
 public SparseDoubleMatrix1D(double[] values) {
-	this(values.length);
-	assign(values);
+  this(values.length);
+  assign(values);
 }
 /**
  * Constructs a matrix with a given number of cells.
@@ -74,7 +74,7 @@
  * @throws IllegalArgumentException if <tt>size<0</tt>.
  */
 public SparseDoubleMatrix1D(int size) {
-	this(size,size/1000,0.2,0.5);
+  this(size,size/1000,0.2,0.5);
 }
 /**
  * Constructs a matrix with a given number of parameters.
@@ -86,12 +86,12 @@
  *                          If not known, set <tt>initialCapacity=0</tt> or small.     
  * @param minLoadFactor        the minimum load factor of the hash map.
  * @param maxLoadFactor        the maximum load factor of the hash map.
- * @throws	IllegalArgumentException if <tt>initialCapacity < 0 || (minLoadFactor < 0.0 || minLoadFactor >= 1.0) || (maxLoadFactor <= 0.0 || maxLoadFactor >= 1.0) || (minLoadFactor >= maxLoadFactor)</tt>.
+ * @throws  IllegalArgumentException if <tt>initialCapacity < 0 || (minLoadFactor < 0.0 || minLoadFactor >= 1.0) || (maxLoadFactor <= 0.0 || maxLoadFactor >= 1.0) || (minLoadFactor >= maxLoadFactor)</tt>.
  * @throws IllegalArgumentException if <tt>size<0</tt>.
  */
 public SparseDoubleMatrix1D(int size, int initialCapacity, double minLoadFactor, double maxLoadFactor) {
-	setUp(size);
-	this.elements = new OpenIntDoubleHashMap(initialCapacity, minLoadFactor, maxLoadFactor);
+  setUp(size);
+  this.elements = new OpenIntDoubleHashMap(initialCapacity, minLoadFactor, maxLoadFactor);
 }
 /**
  * Constructs a matrix view with a given number of parameters.
@@ -103,9 +103,9 @@
  * @throws IllegalArgumentException if <tt>size<0</tt>.
  */
 protected SparseDoubleMatrix1D(int size, AbstractIntDoubleMap elements, int offset, int stride) {
-	setUp(size,offset,stride);
-	this.elements = elements;
-	this.isNoView = false;
+  setUp(size,offset,stride);
+  this.elements = elements;
+  this.isNoView = false;
 }
 /**
  * Sets all cells to the state specified by <tt>value</tt>.
@@ -113,17 +113,17 @@
  * @return <tt>this</tt> (for convenience only).
  */
 public DoubleMatrix1D assign(double value) {
-	// overriden for performance only
-	if (this.isNoView && value==0) this.elements.clear();
-	else super.assign(value);
-	return this;
+  // 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.
  */
 public int cardinality() {
-	if (this.isNoView) return this.elements.size();
-	else return super.cardinality();
+  if (this.isNoView) return this.elements.size();
+  else return super.cardinality();
 }
 /**
  * Ensures that the receiver can hold at least the specified number of non-zero cells without needing to allocate new internal memory.
@@ -136,7 +136,7 @@
  * @param   minNonZeros   the desired minimum number of non-zero cells.
  */
 public void ensureCapacity(int minCapacity) {
-	this.elements.ensureCapacity(minCapacity);
+  this.elements.ensureCapacity(minCapacity);
 }
 /**
  * Returns the matrix cell value at coordinate <tt>index</tt>.
@@ -149,24 +149,24 @@
  * @return    the value of the specified cell.
  */
 public double getQuick(int index) {
-	//if (debug) if (index<0 || index>=size) checkIndex(index);
-	//return this.elements.get(index(index)); 
-	// manually inlined:
-	return elements.get(zero + index*stride);
+  //if (debug) if (index<0 || index>=size) checkIndex(index);
+  //return this.elements.get(index(index)); 
+  // manually inlined:
+  return elements.get(zero + index*stride);
 }
 /**
  * Returns <tt>true</tt> if both matrices share at least one identical cell.
  */
 protected boolean haveSharedCellsRaw(DoubleMatrix1D other) {
-	if (other instanceof SelectedSparseDoubleMatrix1D) {
-		SelectedSparseDoubleMatrix1D otherMatrix = (SelectedSparseDoubleMatrix1D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	else if (other instanceof SparseDoubleMatrix1D) {
-		SparseDoubleMatrix1D otherMatrix = (SparseDoubleMatrix1D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	return false;
+  if (other instanceof SelectedSparseDoubleMatrix1D) {
+    SelectedSparseDoubleMatrix1D otherMatrix = (SelectedSparseDoubleMatrix1D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  else if (other instanceof SparseDoubleMatrix1D) {
+    SparseDoubleMatrix1D otherMatrix = (SparseDoubleMatrix1D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  return false;
 }
 /**
  * Returns the position of the element with the given relative rank within the (virtual or non-virtual) internal 1-dimensional array.
@@ -175,9 +175,9 @@
  * @param     rank   the rank of the element.
  */
 protected int index(int rank) {
-	// overriden for manual inlining only
-	//return _offset(_rank(rank));
-	return zero + rank*stride;
+  // overriden for manual inlining only
+  //return _offset(_rank(rank));
+  return zero + rank*stride;
 }
 /**
  * Construct and returns a new empty matrix <i>of the same dynamic type</i> as the receiver, having the specified size.
@@ -189,7 +189,7 @@
  * @return  a new empty matrix of the same dynamic type.
  */
 public DoubleMatrix1D like(int size) {
-	return new SparseDoubleMatrix1D(size);
+  return new SparseDoubleMatrix1D(size);
 }
 /**
  * Construct and returns a new 2-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver.
@@ -201,7 +201,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 public DoubleMatrix2D like2D(int rows, int columns) {
-	return new SparseDoubleMatrix2D(rows,columns);
+  return new SparseDoubleMatrix2D(rows,columns);
 }
 /**
  * Sets the matrix cell at coordinate <tt>index</tt> to the specified value.
@@ -214,14 +214,14 @@
  * @param    value the value to be filled into the specified cell.
  */
 public void setQuick(int index, double value) {
-	//if (debug) if (index<0 || index>=size) checkIndex(index);
-	//int i =	index(index);
-	// manually inlined:
-	int i = zero + index*stride;
-	if (value == 0)
-		this.elements.removeKey(i);
-	else 
-		this.elements.put(i, value);
+  //if (debug) if (index<0 || index>=size) checkIndex(index);
+  //int i =  index(index);
+  // manually inlined:
+  int i = zero + index*stride;
+  if (value == 0)
+    this.elements.removeKey(i);
+  else 
+    this.elements.put(i, value);
 }
 /**
  * Releases any superfluous memory created by explicitly putting zero values into cells formerly having non-zero values; 
@@ -241,7 +241,7 @@
  * Putting zeros into cells already containing zeros does not generate obsolete memory since no memory was allocated to them in the first place.
  */
 public void trimToSize() {
-	this.elements.trimToSize();
+  this.elements.trimToSize();
 }
 /**
  * Construct and returns a new selection view.
@@ -250,6 +250,6 @@
  * @return  a new view.
  */
 protected DoubleMatrix1D viewSelectionLike(int[] offsets) {
-	return new SelectedSparseDoubleMatrix1D(this.elements,offsets);
+  return new SelectedSparseDoubleMatrix1D(this.elements,offsets);
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SparseDoubleMatrix2D.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SparseDoubleMatrix2D.java?rev=883974&r1=883973&r2=883974&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SparseDoubleMatrix2D.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/matrix/impl/SparseDoubleMatrix2D.java Wed Nov 25 03:41:28 2009
@@ -50,19 +50,19 @@
 Setting values in a loop row-by-row is quicker than column-by-column, because fewer hash collisions occur.
 Thus
 <pre>
-	for (int row=0; row < rows; row++) {
-		for (int column=0; column < columns; column++) {
-			matrix.setQuick(row,column,someValue);
-		}
-	}
+  for (int row=0; row < rows; row++) {
+    for (int column=0; column < columns; column++) {
+      matrix.setQuick(row,column,someValue);
+    }
+  }
 </pre>
 is quicker than
 <pre>
-	for (int column=0; column < columns; column++) {
-		for (int row=0; row < rows; row++) {
-			matrix.setQuick(row,column,someValue);
-		}
-	}
+  for (int column=0; column < columns; column++) {
+    for (int row=0; row < rows; row++) {
+      matrix.setQuick(row,column,someValue);
+    }
+  }
 </pre>
 
 @see org.apache.mahout.matrix.map
@@ -75,11 +75,11 @@
  */
 @Deprecated
 public class SparseDoubleMatrix2D extends DoubleMatrix2D {
-	/*
-	 * The elements of the matrix.
-	 */
-	protected AbstractIntDoubleMap elements;
-	protected int dummy;
+  /*
+   * The elements of the matrix.
+   */
+  protected AbstractIntDoubleMap elements;
+  protected int dummy;
 /**
  * Constructs a matrix with a copy of the given values.
  * <tt>values</tt> is required to have the form <tt>values[row][column]</tt>
@@ -91,18 +91,18 @@
  * @throws IllegalArgumentException if <tt>for any 1 &lt;= row &lt; values.length: values[row].length != values[row-1].length</tt>.
  */
 public SparseDoubleMatrix2D(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 and default memory usage.
  * 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 SparseDoubleMatrix2D(int rows, int columns) {
-	this(rows,columns,rows*(columns/1000),0.2,0.5);
+  this(rows,columns,rows*(columns/1000),0.2,0.5);
 }
 /**
  * Constructs a matrix with a given number of rows and columns using memory as specified.
@@ -115,12 +115,12 @@
  *                          If not known, set <tt>initialCapacity=0</tt> or small.     
  * @param minLoadFactor        the minimum load factor of the hash map.
  * @param maxLoadFactor        the maximum load factor of the hash map.
- * @throws	IllegalArgumentException if <tt>initialCapacity < 0 || (minLoadFactor < 0.0 || minLoadFactor >= 1.0) || (maxLoadFactor <= 0.0 || maxLoadFactor >= 1.0) || (minLoadFactor >= maxLoadFactor)</tt>.
- * @throws	IllegalArgumentException if <tt>rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE</tt>.
+ * @throws  IllegalArgumentException if <tt>initialCapacity < 0 || (minLoadFactor < 0.0 || minLoadFactor >= 1.0) || (maxLoadFactor <= 0.0 || maxLoadFactor >= 1.0) || (minLoadFactor >= maxLoadFactor)</tt>.
+ * @throws  IllegalArgumentException if <tt>rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE</tt>.
  */
 public SparseDoubleMatrix2D(int rows, int columns, int initialCapacity, double minLoadFactor, double maxLoadFactor) {
-	setUp(rows,columns); 
-	this.elements = new OpenIntDoubleHashMap(initialCapacity, minLoadFactor, maxLoadFactor);
+  setUp(rows,columns); 
+  this.elements = new OpenIntDoubleHashMap(initialCapacity, minLoadFactor, maxLoadFactor);
 }
 /**
  * Constructs a view with the given parameters.
@@ -131,12 +131,12 @@
  * @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.
+ * @throws  IllegalArgumentException if <tt>rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE</tt> or flip's are illegal.
  */
 protected 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;
+  setUp(rows,columns,rowZero,columnZero,rowStride,columnStride);
+  this.elements = elements;
+  this.isNoView = false;
 }
 /**
  * Sets all cells to the state specified by <tt>value</tt>.
@@ -144,10 +144,10 @@
  * @return <tt>this</tt> (for convenience only).
  */
 public DoubleMatrix2D assign(double value) {
-	// overriden for performance only
-	if (this.isNoView && value==0) this.elements.clear();
-	else super.assign(value);
-	return this;
+  // overriden for performance only
+  if (this.isNoView && value==0) this.elements.clear();
+  else super.assign(value);
+  return this;
 }
 /**
 Assigns the result of a function to each cell; <tt>x[row,col] = function(x[row,col])</tt>.
@@ -172,13 +172,13 @@
 @see org.apache.mahout.jet.math.Functions
 */
 public DoubleMatrix2D assign(org.apache.mahout.matrix.function.DoubleFunction function) {
-	if (this.isNoView && function instanceof org.apache.mahout.jet.math.Mult) { // x[i] = mult*x[i]
-		this.elements.assign(function);
-	}
-	else {
-		super.assign(function);
-	}
-	return this;
+  if (this.isNoView && function instanceof org.apache.mahout.jet.math.Mult) { // x[i] = mult*x[i]
+    this.elements.assign(function);
+  }
+  else {
+    super.assign(function);
+  }
+  return this;
 }
 /**
  * Replaces all cell values of the receiver with the values of another matrix.
@@ -187,78 +187,78 @@
  *
  * @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 instanceof SparseDoubleMatrix2D)) {
-		return super.assign(source);
-	}
-	SparseDoubleMatrix2D other = (SparseDoubleMatrix2D) source;
-	if (other==this) return this; // nothing to do
-	checkShape(other);
-	
-	if (this.isNoView && other.isNoView) { // quickest
-		this.elements.assign(other.elements);
-		return this;
-	}
-	return super.assign(source);
+  // overriden for performance only
+  if (! (source instanceof SparseDoubleMatrix2D)) {
+    return super.assign(source);
+  }
+  SparseDoubleMatrix2D other = (SparseDoubleMatrix2D) source;
+  if (other==this) return this; // nothing to do
+  checkShape(other);
+  
+  if (this.isNoView && other.isNoView) { // quickest
+    this.elements.assign(other.elements);
+    return this;
+  }
+  return super.assign(source);
 }
 public DoubleMatrix2D assign(final DoubleMatrix2D y, org.apache.mahout.matrix.function.DoubleDoubleFunction function) {
-	if (!this.isNoView) return super.assign(y,function);
-	
-	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]
-		this.elements.forEachPair(
-			new org.apache.mahout.matrix.function.IntDoubleProcedure() {
-				public boolean apply(int key, double value) {
-					int i = key/columns;
-					int j = key%columns;
-					double r = value * y.getQuick(i,j);
-					if (r!=value) elements.put(key,r);
-					return true;
-				}
-			}
-		);
-	}
-	
-	if (function== org.apache.mahout.jet.math.Functions.div) { // x[i] = x[i] / y[i]
-		this.elements.forEachPair(
-			new org.apache.mahout.matrix.function.IntDoubleProcedure() {
-				public boolean apply(int key, double value) {
-					int i = key/columns;
-					int j = key%columns;
-					double r = value / y.getQuick(i,j);
-					if (r!=value) elements.put(key,r);
-					return true;
-				}
-			}
-		);
-	}
-	
-	return super.assign(y,function);
+  if (!this.isNoView) return super.assign(y,function);
+  
+  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]
+    this.elements.forEachPair(
+      new org.apache.mahout.matrix.function.IntDoubleProcedure() {
+        public boolean apply(int key, double value) {
+          int i = key/columns;
+          int j = key%columns;
+          double r = value * y.getQuick(i,j);
+          if (r!=value) elements.put(key,r);
+          return true;
+        }
+      }
+    );
+  }
+  
+  if (function== org.apache.mahout.jet.math.Functions.div) { // x[i] = x[i] / y[i]
+    this.elements.forEachPair(
+      new org.apache.mahout.matrix.function.IntDoubleProcedure() {
+        public boolean apply(int key, double value) {
+          int i = key/columns;
+          int j = key%columns;
+          double r = value / y.getQuick(i,j);
+          if (r!=value) elements.put(key,r);
+          return true;
+        }
+      }
+    );
+  }
+  
+  return super.assign(y,function);
 }
 /**
  * Returns the number of cells having non-zero values.
  */
 public int cardinality() {
-	if (this.isNoView) return this.elements.size();
-	else return super.cardinality();
+  if (this.isNoView) return this.elements.size();
+  else return super.cardinality();
 }
 /**
  * Ensures that the receiver can hold at least the specified number of non-zero cells without needing to allocate new internal memory.
@@ -271,26 +271,26 @@
  * @param   minNonZeros   the desired minimum number of non-zero cells.
  */
 public void ensureCapacity(int minCapacity) {
-	this.elements.ensureCapacity(minCapacity);
+  this.elements.ensureCapacity(minCapacity);
 }
 public DoubleMatrix2D forEachNonZero(final org.apache.mahout.matrix.function.IntIntDoubleFunction function) {
-	if (this.isNoView) {
-		this.elements.forEachPair(
-			new org.apache.mahout.matrix.function.IntDoubleProcedure() {
-				public boolean apply(int key, double value) {
-					int i = key/columns;
-					int j = key%columns;
-					double r = function.apply(i,j,value);
-					if (r!=value) elements.put(key,r);
-					return true;
-				}
-			}
-		);
-	}
-	else {
-		super.forEachNonZero(function);
-	}
-	return this;
+  if (this.isNoView) {
+    this.elements.forEachPair(
+      new org.apache.mahout.matrix.function.IntDoubleProcedure() {
+        public boolean apply(int key, double value) {
+          int i = key/columns;
+          int j = key%columns;
+          double r = function.apply(i,j,value);
+          if (r!=value) elements.put(key,r);
+          return true;
+        }
+      }
+    );
+  }
+  else {
+    super.forEachNonZero(function);
+  }
+  return this;
 }
 /**
  * Returns the matrix cell value at coordinate <tt>[row,column]</tt>.
@@ -304,10 +304,10 @@
  * @return    the value at the specified coordinate.
  */
 public double getQuick(int row, int column) {
-	//if (debug) if (column<0 || column>=columns || row<0 || row>=rows) throw new IndexOutOfBoundsException("row:"+row+", column:"+column);
-	//return this.elements.get(index(row,column));
-	//manually inlined:
-	return this.elements.get(rowZero + row*rowStride + columnZero + column*columnStride);
+  //if (debug) if (column<0 || column>=columns || row<0 || row>=rows) throw new IndexOutOfBoundsException("row:"+row+", column:"+column);
+  //return this.elements.get(index(row,column));
+  //manually inlined:
+  return this.elements.get(rowZero + row*rowStride + columnZero + column*columnStride);
 }
 /**
  * Returns <tt>true</tt> if both matrices share common cells.
@@ -319,15 +319,15 @@
  * </ul>
  */
 protected boolean haveSharedCellsRaw(DoubleMatrix2D other) {
-	if (other instanceof SelectedSparseDoubleMatrix2D) {
-		SelectedSparseDoubleMatrix2D otherMatrix = (SelectedSparseDoubleMatrix2D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	else if (other instanceof SparseDoubleMatrix2D) {
-		SparseDoubleMatrix2D otherMatrix = (SparseDoubleMatrix2D) other;
-		return this.elements==otherMatrix.elements;
-	}
-	return false;
+  if (other instanceof SelectedSparseDoubleMatrix2D) {
+    SelectedSparseDoubleMatrix2D otherMatrix = (SelectedSparseDoubleMatrix2D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  else if (other instanceof SparseDoubleMatrix2D) {
+    SparseDoubleMatrix2D otherMatrix = (SparseDoubleMatrix2D) other;
+    return this.elements==otherMatrix.elements;
+  }
+  return false;
 }
 /**
  * Returns the position of the given coordinate within the (virtual or non-virtual) internal 1-dimensional array. 
@@ -336,9 +336,9 @@
  * @param     column   the index of the column-coordinate.
  */
 protected int index(int row, int column) {
-	// return super.index(row,column);
-	// manually inlined for speed:
-	return rowZero + row*rowStride + columnZero + column*columnStride;
+  // return super.index(row,column);
+  // manually inlined for speed:
+  return rowZero + row*rowStride + columnZero + column*columnStride;
 }
 /**
  * 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.
@@ -351,7 +351,7 @@
  * @return  a new empty matrix of the same dynamic type.
  */
 public DoubleMatrix2D like(int rows, int columns) {
-	return new SparseDoubleMatrix2D(rows, columns);
+  return new SparseDoubleMatrix2D(rows, columns);
 }
 /**
  * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, entirelly independent of the receiver.
@@ -362,7 +362,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 public DoubleMatrix1D like1D(int size) {
-	return new SparseDoubleMatrix1D(size);
+  return new SparseDoubleMatrix1D(size);
 }
 /**
  * Construct and returns a new 1-d matrix <i>of the corresponding dynamic type</i>, sharing the same cells.
@@ -375,7 +375,7 @@
  * @return  a new matrix of the corresponding dynamic type.
  */
 protected DoubleMatrix1D like1D(int size, int offset, int stride) {
-	return new SparseDoubleMatrix1D(size,this.elements,offset,stride);
+  return new SparseDoubleMatrix1D(size,this.elements,offset,stride);
 }
 /**
  * Sets the matrix cell at coordinate <tt>[row,column]</tt> to the specified value.
@@ -389,16 +389,16 @@
  * @param    value the value to be filled into the specified cell.
  */
 public void setQuick(int row, int column, double value) {
-	//if (debug) if (column<0 || column>=columns || row<0 || row>=rows) throw new IndexOutOfBoundsException("row:"+row+", column:"+column);
-	//int index =	index(row,column);
-	//manually inlined:
-	int index = rowZero + row*rowStride + columnZero + column*columnStride;
-
-	//if (value == 0 || Math.abs(value) < TOLERANCE)
-	if (value == 0)
-		this.elements.removeKey(index);
-	else 
-		this.elements.put(index, value);
+  //if (debug) if (column<0 || column>=columns || row<0 || row>=rows) throw new IndexOutOfBoundsException("row:"+row+", column:"+column);
+  //int index =  index(row,column);
+  //manually inlined:
+  int index = rowZero + row*rowStride + columnZero + column*columnStride;
+
+  //if (value == 0 || Math.abs(value) < TOLERANCE)
+  if (value == 0)
+    this.elements.removeKey(index);
+  else 
+    this.elements.put(index, value);
 }
 /**
  * Releases any superfluous memory created by explicitly putting zero values into cells formerly having non-zero values; 
@@ -418,7 +418,7 @@
  * Putting zeros into cells already containing zeros does not generate obsolete memory since no memory was allocated to them in the first place.
  */
 public void trimToSize() {
-	this.elements.trimToSize();
+  this.elements.trimToSize();
 }
 /**
  * Construct and returns a new selection view.
@@ -428,117 +428,117 @@
  * @return  a new view.
  */
 protected DoubleMatrix2D viewSelectionLike(int[] rowOffsets, int[] columnOffsets) {
-	return new SelectedSparseDoubleMatrix2D(this.elements,rowOffsets,columnOffsets,0);
+  return new SelectedSparseDoubleMatrix2D(this.elements,rowOffsets,columnOffsets,0);
 }
 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();
-
-	this.elements.forEachPair(
-		new org.apache.mahout.matrix.function.IntDoubleProcedure() {
-			public boolean apply(int key, double value) {
-				int i = key/columns;
-				int j = key%columns;
-				if (transposeA) { int tmp=i; i=j; j=tmp; }
-				zElements[zi + zStride*i] += value * yElements[yi + yStride*j];
-				//System.out.println("["+i+","+j+"]-->"+value);
-				return true;
-			}
-		}
-	);
-	
-	/*
-	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();
+
+  this.elements.forEachPair(
+    new org.apache.mahout.matrix.function.IntDoubleProcedure() {
+      public boolean apply(int key, double value) {
+        int i = key/columns;
+        int j = key%columns;
+        if (transposeA) { int tmp=i; i=j; j=tmp; }
+        zElements[zi + zStride*i] += value * yElements[yi + yStride*j];
+        //System.out.println("["+i+","+j+"]-->"+value);
+        return true;
+      }
+    }
+  );
+  
+  /*
+  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 (!(this.isNoView)) {
-		return super.zMult(B,C,alpha,beta,transposeA,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);
-
-	this.elements.forEachPair(
-		new org.apache.mahout.matrix.function.IntDoubleProcedure() {
-			public boolean apply(int key, double value) {
-				int i = key/columns;
-				int j = key%columns;
-				fun.multiplicator = value*alpha;
-				if (!transposeA)
-					Crows[i].assign(Brows[j],fun);
-				else
-					Crows[j].assign(Brows[i],fun);
-				return true;
-			}
-		}
-	);
+  if (!(this.isNoView)) {
+    return super.zMult(B,C,alpha,beta,transposeA,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);
+
+  this.elements.forEachPair(
+    new org.apache.mahout.matrix.function.IntDoubleProcedure() {
+      public boolean apply(int key, double value) {
+        int i = key/columns;
+        int j = key%columns;
+        fun.multiplicator = value*alpha;
+        if (!transposeA)
+          Crows[i].assign(Brows[j],fun);
+        else
+          Crows[j].assign(Brows[i],fun);
+        return true;
+      }
+    }
+  );
 
-	return C;
+  return C;
 }
 }