com.aliasi.matrix
Class AbstractMatrix

java.lang.Object
  extended by com.aliasi.matrix.AbstractMatrix
All Implemented Interfaces:
Matrix
Direct Known Subclasses:
DenseMatrix, ProximityMatrix, SvdMatrix

public abstract class AbstractMatrix
extends Object
implements Matrix

An AbstractMatrix implements most of a matrix's functionality in terms of methods for accessing numbers of rows and columns and values.

Since:
LingPipe2.0
Version:
3.0
Author:
Bob Carpenter

Constructor Summary
protected AbstractMatrix()
          Construct an abstract matrix.
 
Method Summary
 Vector columnVector(int column)
          Returns the specified column of this matrix.
 boolean equals(Object that)
          Return true if the specified object is a matrix of the same dimensionality with the same values.
 int hashCode()
          Returns a hash code as specified in the Matrix interface's documentation.
abstract  int numColumns()
          Returns the number of columns in the matrix.
abstract  int numRows()
          Returns the number of rows in the matrix.
 Vector rowVector(int row)
          Returns the specified row of this matrix.
 void setValue(int row, int column, double value)
          Throw an unsupported operation exception.
abstract  double value(int row, int column)
          Returns the value in the matrix at the specified row and column.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMatrix

protected AbstractMatrix()
Construct an abstract matrix.

Method Detail

numRows

public abstract int numRows()
Description copied from interface: Matrix
Returns the number of rows in the matrix.

Specified by:
numRows in interface Matrix
Returns:
The number of rows in the matrix.

numColumns

public abstract int numColumns()
Description copied from interface: Matrix
Returns the number of columns in the matrix.

Specified by:
numColumns in interface Matrix
Returns:
The number of columns in the matrix.

value

public abstract double value(int row,
                             int column)
Description copied from interface: Matrix
Returns the value in the matrix at the specified row and column.

Specified by:
value in interface Matrix
Parameters:
row - The specified row.
column - The specified column.
Returns:
The value in the matrix at the specified row and column.

setValue

public void setValue(int row,
                     int column,
                     double value)
Throw an unsupported operation exception. This method should be overriden by value mutable subclasses.

Specified by:
setValue in interface Matrix
Parameters:
row - Ignored.
column - Ignored.
value - Ignored.
Throws:
UnsupportedOperationException - If not overridden by a subclass implementation.
IndexOutOfBoundsException - If the row or column indexes are out of bounds.

rowVector

public Vector rowVector(int row)
Returns the specified row of this matrix. The vector returned is backed by this matrix, and changes to its values or labels affect this matrix. The returned vector may be cloned to produce an equivalent vector that is not linked to this matrix.

No check is made that the row is within current bounds of the matrix, but attempts to access values for a row matrix that is out of bounds will throw a runtime exception if the underlying matrix's value(int,int) method throws an exception..

Specified by:
rowVector in interface Matrix
Parameters:
row - Row whose vector is returned.
Returns:
Vector for the specified row.
Throws:
IndexOutOfBoundsException - If the row index is out of bounds.

columnVector

public Vector columnVector(int column)
Returns the specified column of this matrix. The vector returned is backed by this matrix, and changes to its values or labels affect this matrix. The returned vector may be cloned to produce an equivalent vector that is not linked to this matrix.

No check is made that the column is within current bounds of the matrix, but attempts to access values for a column matrix that is out of bounds will throw a runtime exception if the underlying matrix's value(int,int) method throws an exception.

Specified by:
columnVector in interface Matrix
Parameters:
column - Column whose vector is returned.
Returns:
Vector for the specified column.

equals

public boolean equals(Object that)
Return true if the specified object is a matrix of the same dimensionality with the same values. Note that labels are ignored in establishing matrix identity. This definition is consistent witht he definition of hashCode().

Specified by:
equals in interface Matrix
Overrides:
equals in class Object
Parameters:
that - Object to test for equality with this matrix.
Returns:
true if the specified object is a matrix with the same dimensionality and values as this matrix.

hashCode

public int hashCode()
Returns a hash code as specified in the Matrix interface's documentation.

Specified by:
hashCode in interface Matrix
Overrides:
hashCode in class Object
Returns:
Hash code for this matrix.