org.apache.mahout.math
Class SparseRowMatrix

java.lang.Object
  extended by org.apache.mahout.math.AbstractMatrix
      extended by org.apache.mahout.math.SparseRowMatrix
All Implemented Interfaces:
Cloneable, Iterable<MatrixSlice>, Matrix, VectorIterable

public class SparseRowMatrix
extends AbstractMatrix

sparse matrix with general element values whose rows are accessible quickly. Implemented as a row array of either SequentialAccessSparseVectors or RandomAccessSparseVectors.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.mahout.math.AbstractMatrix
AbstractMatrix.TransposeViewVector
 
Field Summary
 
Fields inherited from class org.apache.mahout.math.AbstractMatrix
COL, columnLabelBindings, columns, ROW, rowLabelBindings, rows
 
Constructor Summary
SparseRowMatrix(int rows, int columns)
          Construct a matrix of the given cardinality, with rows defaulting to RandomAccessSparseVector implementation
SparseRowMatrix(int rows, int columns, boolean randomAccess)
           
SparseRowMatrix(int rows, int columns, Vector[] rowVectors)
          Construct a sparse matrix starting with the provided row vectors.
SparseRowMatrix(int rows, int columns, Vector[] vectors, boolean shallowCopy, boolean randomAccess)
           
 
Method Summary
 Matrix assignColumn(int column, Vector other)
          Assign the other vector values to the column of the receiver
 Matrix assignRow(int row, Vector other)
          Assign the other vector values to the row of the receiver
 Matrix clone()
          Return a copy of the recipient
 int[] getNumNondefaultElements()
          Return the number of values in the recipient
 double getQuick(int row, int column)
          Return the value at the given indexes, without checking bounds
 Matrix like()
          Return an empty matrix of the same underlying class as the receiver
 Matrix like(int rows, int columns)
          Returns an empty matrix of the same underlying class as the receiver and of the specified size.
 void setQuick(int row, int column, double value)
          Set the value at the given index, without checking bounds
 Matrix transpose()
          Return a new matrix that is the transpose of the receiver
 Matrix viewPart(int[] offset, int[] size)
          Return a view into part of a matrix.
 Vector viewRow(int row)
          Returns a view of a row.
 
Methods inherited from class org.apache.mahout.math.AbstractMatrix
aggregate, aggregateColumns, aggregateRows, asFormatString, assign, assign, assign, assign, assign, columnSize, determinant, divide, get, get, getColumnLabelBindings, getRowLabelBindings, iterateAll, iterator, minus, numCols, numRows, numSlices, plus, plus, rowSize, set, set, set, set, set, set, setColumnLabelBindings, setRowLabelBindings, times, times, times, timesSquared, toString, viewColumn, viewDiagonal, viewPart, zSum
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SparseRowMatrix

public SparseRowMatrix(int rows,
                       int columns,
                       Vector[] rowVectors)
Construct a sparse matrix starting with the provided row vectors.

Parameters:
rows - The number of rows in the result
columns - The number of columns in the result
rowVectors - a Vector[] array of rows

SparseRowMatrix

public SparseRowMatrix(int rows,
                       int columns,
                       boolean randomAccess)

SparseRowMatrix

public SparseRowMatrix(int rows,
                       int columns,
                       Vector[] vectors,
                       boolean shallowCopy,
                       boolean randomAccess)

SparseRowMatrix

public SparseRowMatrix(int rows,
                       int columns)
Construct a matrix of the given cardinality, with rows defaulting to RandomAccessSparseVector implementation

Parameters:
rows -
columns -
Method Detail

clone

public Matrix clone()
Description copied from interface: Matrix
Return a copy of the recipient

Specified by:
clone in interface Matrix
Overrides:
clone in class AbstractMatrix
Returns:
a new Matrix

getQuick

public double getQuick(int row,
                       int column)
Description copied from interface: Matrix
Return the value at the given indexes, without checking bounds

Parameters:
row - an int row index
column - an int column index
Returns:
the double at the index

like

public Matrix like()
Description copied from interface: Matrix
Return an empty matrix of the same underlying class as the receiver

Returns:
a Matrix

like

public Matrix like(int rows,
                   int columns)
Description copied from interface: Matrix
Returns an empty matrix of the same underlying class as the receiver and of the specified size.

Parameters:
rows - the int number of rows
columns - the int number of columns

setQuick

public void setQuick(int row,
                     int column,
                     double value)
Description copied from interface: Matrix
Set the value at the given index, without checking bounds

Parameters:
row - an int row index into the receiver
column - an int column index into the receiver
value - a double value to set

getNumNondefaultElements

public int[] getNumNondefaultElements()
Description copied from interface: Matrix
Return the number of values in the recipient

Specified by:
getNumNondefaultElements in interface Matrix
Overrides:
getNumNondefaultElements in class AbstractMatrix
Returns:
an int[2] containing [row, column] count

viewPart

public Matrix viewPart(int[] offset,
                       int[] size)
Description copied from interface: Matrix
Return a view into part of a matrix. Changes to the view will change the original matrix.

Specified by:
viewPart in interface Matrix
Overrides:
viewPart in class AbstractMatrix
Parameters:
offset - an int[2] offset into the receiver
size - the int[2] size of the desired result
Returns:
a matrix that shares storage with part of the original matrix.

assignColumn

public Matrix assignColumn(int column,
                           Vector other)
Description copied from interface: Matrix
Assign the other vector values to the column of the receiver

Parameters:
column - the int row to assign
other - a Vector
Returns:
the modified receiver

assignRow

public Matrix assignRow(int row,
                        Vector other)
Description copied from interface: Matrix
Assign the other vector values to the row of the receiver

Parameters:
row - the int row to assign
other - a Vector
Returns:
the modified receiver

viewRow

public Vector viewRow(int row)
Description copied from class: AbstractMatrix
Returns a view of a row. Changes to the view will affect the original.

Specified by:
viewRow in interface Matrix
Overrides:
viewRow in class AbstractMatrix
Parameters:
row - an int row index
Returns:
a shallow view of the Vector at specified row (ie you may mutate the original matrix using this row)

transpose

public Matrix transpose()
Description copied from interface: Matrix
Return a new matrix that is the transpose of the receiver

Specified by:
transpose in interface Matrix
Overrides:
transpose in class AbstractMatrix
Returns:
the transpose


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.