org.jscience.mathematics.algebraic.matrices
Class IntegerSparseMatrix

java.lang.Object
  extended by org.jscience.mathematics.algebraic.AbstractHypermatrix
      extended by org.jscience.mathematics.algebraic.AbstractMatrix
          extended by org.jscience.mathematics.algebraic.matrices.AbstractIntegerMatrix
              extended by org.jscience.mathematics.algebraic.matrices.IntegerSparseMatrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Member

public class IntegerSparseMatrix
extends AbstractIntegerMatrix
implements java.lang.Cloneable, java.io.Serializable

The IntegerSparseMatrix class provides an object for encapsulating sparse matrices. Uses compressed row storage.

See Also:
Serialized Form

Constructor Summary
IntegerSparseMatrix(int[][] array)
          Constructs a matrix from an array.
IntegerSparseMatrix(IntegerSparseMatrix mat)
          Copy constructor.
IntegerSparseMatrix(int rowCount, int colCount)
          Constructs an empty matrix.
 
Method Summary
 AbstractIntegerMatrix add(AbstractIntegerMatrix m)
          Returns the addition of this matrix and another.
 IntegerMatrix add(IntegerMatrix m)
           
 IntegerSparseMatrix add(IntegerSparseMatrix m)
          Returns the addition of this matrix and another.
 java.lang.Object clone()
          Clone matrix into a new matrix.
 boolean equals(AbstractIntegerMatrix m, double tol)
          Compares two double sparse matrices for equality.
 boolean equals(IntegerSparseMatrix m)
           
 boolean equals(IntegerSparseMatrix m, double tol)
           
 double frobeniusNorm()
          Returns the Frobenius (l2) norm.
 int getPrimitiveElement(int i, int j)
          Returns an element of the matrix.
 int infNorm()
          Returns the linfinity-norm.
 AbstractDoubleMatrix mapElements(PrimitiveMapping f)
          Applies a function on all the matrix elements.
 AbstractIntegerMatrix multiply(AbstractIntegerMatrix m)
          Returns the multiplication of this matrix and another.
 AbstractIntegerVector multiply(AbstractIntegerVector v)
          Returns the multiplication of a vector by this matrix.
 AbstractIntegerMatrix multiply(IntegerMatrix m)
           
 AbstractIntegerMatrix multiply(IntegerSparseMatrix m)
          Returns the multiplication of this matrix and another.
 AbstractIntegerMatrix scalarMultiply(int x)
          Returns the multiplication of this matrix by a scalar.
 int scalarProduct(AbstractIntegerMatrix m)
          Returns the scalar product of this matrix and another.
 int scalarProduct(IntegerMatrix m)
           
 void setAllElements(int x)
          Sets the value of all elements of the matrix.
 void setElement(int i, int j, int x)
          Sets the value of an element of the matrix.
 AbstractIntegerMatrix subtract(AbstractIntegerMatrix m)
          Returns the subtraction of this matrix and another.
 IntegerMatrix subtract(IntegerMatrix m)
           
 IntegerSparseMatrix subtract(IntegerSparseMatrix m)
          Returns the addition of this matrix and another.
 AbstractComplexMatrix toComplexMatrix()
          Converts this matrix to a complex matrix.
 AbstractDoubleMatrix toDoubleMatrix()
          Converts this matrix to an double matrix.
 int[][] toPrimitiveArray()
          Projects the matrix to an array.
 java.lang.String toString()
          Returns a string representing this matrix.
 Matrix transpose()
          Returns the transpose of this matrix.
 
Methods inherited from class org.jscience.mathematics.algebraic.matrices.AbstractIntegerMatrix
abs, add, directSum, equals, equals, getColumn, getElement, getMatrixAsColumns, getMatrixAsRows, getRow, getSet, getSubMatrix, hashCode, horizontalAxisSymmetry, mass, max, mean, min, multiply, negate, read, reverse, scalarDivide, scalarMultiply, setColumn, setRow, setSubMatrix, subtract, tensorProduct, verticalAxisSymmetry
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractMatrix
getElement, getInvalidElementMsg, numColumns, numRows, print, print, print, print, toArray, toArray
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractHypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 

Constructor Detail

IntegerSparseMatrix

public IntegerSparseMatrix(int rowCount,
                           int colCount)
Constructs an empty matrix.

Parameters:
rowCount - the number of rows
colCount - the number of columns

IntegerSparseMatrix

public IntegerSparseMatrix(int[][] array)
Constructs a matrix from an array.

Parameters:
array - an assigned value

IntegerSparseMatrix

public IntegerSparseMatrix(IntegerSparseMatrix mat)
Copy constructor.

Parameters:
mat - an assigned value
Method Detail

equals

public boolean equals(AbstractIntegerMatrix m,
                      double tol)
Compares two double sparse matrices for equality.

Overrides:
equals in class AbstractIntegerMatrix
Parameters:
m - a integer matrix

equals

public boolean equals(IntegerSparseMatrix m)

equals

public boolean equals(IntegerSparseMatrix m,
                      double tol)

toString

public java.lang.String toString()
Returns a string representing this matrix.

Overrides:
toString in class AbstractIntegerMatrix

toDoubleMatrix

public AbstractDoubleMatrix toDoubleMatrix()
Converts this matrix to an double matrix.

Overrides:
toDoubleMatrix in class AbstractIntegerMatrix
Returns:
an double matrix

toComplexMatrix

public AbstractComplexMatrix toComplexMatrix()
Converts this matrix to a complex matrix.

Overrides:
toComplexMatrix in class AbstractIntegerMatrix
Returns:
a complex matrix

getPrimitiveElement

public int getPrimitiveElement(int i,
                               int j)
Returns an element of the matrix.

Specified by:
getPrimitiveElement in class AbstractIntegerMatrix
Parameters:
i - row index of the element
j - column index of the element
Throws:
IllegalDimensionException - If attempting to access an invalid element.

setElement

public void setElement(int i,
                       int j,
                       int x)
Sets the value of an element of the matrix.

Specified by:
setElement in class AbstractIntegerMatrix
Parameters:
i - row index of the element
j - column index of the element
x - a number
Throws:
IllegalDimensionException - If attempting to access an invalid element.

setAllElements

public void setAllElements(int x)
Sets the value of all elements of the matrix. You should think about using a IntegerSquareMatrix.

Overrides:
setAllElements in class AbstractIntegerMatrix
Parameters:
x - a int element

infNorm

public int infNorm()
Returns the linfinity-norm.

Overrides:
infNorm in class AbstractIntegerMatrix

frobeniusNorm

public double frobeniusNorm()
Returns the Frobenius (l2) norm.

Overrides:
frobeniusNorm in class AbstractIntegerMatrix

add

public AbstractIntegerMatrix add(AbstractIntegerMatrix m)
Returns the addition of this matrix and another.

Overrides:
add in class AbstractIntegerMatrix
Parameters:
m - a integer matrix
Throws:
IllegalDimensionException - If the matrices are different sizes.

add

public IntegerMatrix add(IntegerMatrix m)

add

public IntegerSparseMatrix add(IntegerSparseMatrix m)
Returns the addition of this matrix and another.

Parameters:
m - a integer sparse matrix
Throws:
IllegalDimensionException - If the matrices are different sizes.

subtract

public AbstractIntegerMatrix subtract(AbstractIntegerMatrix m)
Returns the subtraction of this matrix and another.

Overrides:
subtract in class AbstractIntegerMatrix
Parameters:
m - a integer matrix
Throws:
IllegalDimensionException - If the matrices are different sizes.

subtract

public IntegerMatrix subtract(IntegerMatrix m)

subtract

public IntegerSparseMatrix subtract(IntegerSparseMatrix m)
Returns the addition of this matrix and another.

Parameters:
m - a integer sparse matrix
Throws:
IllegalDimensionException - If the matrices are different sizes.

scalarMultiply

public AbstractIntegerMatrix scalarMultiply(int x)
Returns the multiplication of this matrix by a scalar.

Overrides:
scalarMultiply in class AbstractIntegerMatrix
Parameters:
x - a integer
Returns:
a integer sparse matrix

scalarProduct

public int scalarProduct(AbstractIntegerMatrix m)
Returns the scalar product of this matrix and another.

Overrides:
scalarProduct in class AbstractIntegerMatrix
Parameters:
m - a integer matrix.
Throws:
IllegalDimensionException - If the matrices are different sizes.

scalarProduct

public int scalarProduct(IntegerMatrix m)

multiply

public AbstractIntegerVector multiply(AbstractIntegerVector v)
Returns the multiplication of a vector by this matrix.

Overrides:
multiply in class AbstractIntegerMatrix
Parameters:
v - a integer vector
Throws:
IllegalDimensionException - If the matrix and vector are incompatible.

multiply

public AbstractIntegerMatrix multiply(AbstractIntegerMatrix m)
Returns the multiplication of this matrix and another.

Overrides:
multiply in class AbstractIntegerMatrix
Parameters:
m - a integer matrix
Returns:
a AbstractIntegerMatrix or a AbstractIntegerSquareMatrix as appropriate
Throws:
IllegalDimensionException - If the matrices are incompatible.

multiply

public AbstractIntegerMatrix multiply(IntegerMatrix m)

multiply

public AbstractIntegerMatrix multiply(IntegerSparseMatrix m)
Returns the multiplication of this matrix and another.

Parameters:
m - a integer sparse matrix
Throws:
IllegalDimensionException - If the matrices are incompatible.

transpose

public Matrix transpose()
Returns the transpose of this matrix.

Specified by:
transpose in interface Matrix
Overrides:
transpose in class AbstractIntegerMatrix
Returns:
a integer sparse matrix

mapElements

public AbstractDoubleMatrix mapElements(PrimitiveMapping f)
Applies a function on all the matrix elements.

Overrides:
mapElements in class AbstractIntegerMatrix
Parameters:
f - a user-defined function
Returns:
a double sparse matrix

clone

public java.lang.Object clone()
Clone matrix into a new matrix.

Overrides:
clone in class java.lang.Object
Returns:
the cloned matrix.

toPrimitiveArray

public int[][] toPrimitiveArray()
Projects the matrix to an array.

Overrides:
toPrimitiveArray in class AbstractIntegerMatrix
Returns:
an int array.