org.jscience.mathematics.algebraic.matrices
Class IntegerSparseSquareMatrix

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.AbstractIntegerSquareMatrix
                  extended by org.jscience.mathematics.algebraic.matrices.IntegerSparseSquareMatrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, SquareMatrix, Member

public class IntegerSparseSquareMatrix
extends AbstractIntegerSquareMatrix
implements java.lang.Cloneable, java.io.Serializable

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

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jscience.mathematics.algebraic.matrices.AbstractIntegerSquareMatrix
LU, LUpivot
 
Constructor Summary
IntegerSparseSquareMatrix(int size)
          Constructs an empty matrix.
IntegerSparseSquareMatrix(int[][] array)
          Constructs a matrix from an array.
IntegerSparseSquareMatrix(IntegerSparseSquareMatrix mat)
          Copy constructor.
 
Method Summary
 AbstractIntegerSquareMatrix add(AbstractIntegerSquareMatrix m)
          Returns the addition of this matrix and another.
 IntegerSparseSquareMatrix add(IntegerSparseSquareMatrix m)
          Returns the addition of this matrix and another.
 IntegerSquareMatrix add(IntegerSquareMatrix m)
          DOCUMENT ME!
 AbstractDoubleSquareMatrix[] choleskyDecompose()
          Returns the Cholesky decomposition of this matrix.
 java.lang.Object clone()
          Clone matrix into a new matrix.
 int det()
          Returns the determinant.
 boolean equals(AbstractIntegerSquareMatrix m, double tol)
          Compares two double sparse square matrices for equality.
 boolean equals(IntegerSparseSquareMatrix m)
          DOCUMENT ME!
 boolean equals(IntegerSparseSquareMatrix m, double tol)
          DOCUMENT ME!
 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.
 AbstractDoubleSquareMatrix[] luDecompose(int[] pivot)
          Returns the LU decomposition of this matrix.
 AbstractDoubleMatrix mapElements(PrimitiveMapping f)
          Applies a function on all the matrix elements.
 AbstractIntegerSquareMatrix multiply(AbstractIntegerSquareMatrix m)
          Returns the multiplication of this matrix and another.
 AbstractIntegerVector multiply(AbstractIntegerVector v)
          Returns the multiplication of a vector by this matrix.
 IntegerSparseSquareMatrix multiply(IntegerSparseSquareMatrix m)
          Returns the multiplication of this matrix and another.
 IntegerSquareMatrix multiply(IntegerSquareMatrix m)
          DOCUMENT ME!
 AbstractIntegerMatrix scalarMultiply(int x)
          Returns the multiplication of this matrix by a scalar.
 int scalarProduct(AbstractIntegerSquareMatrix m)
          Returns the scalar product of this matrix and another.
 int scalarProduct(IntegerSquareMatrix m)
          DOCUMENT ME!
 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.
 AbstractIntegerSquareMatrix subtract(AbstractIntegerSquareMatrix m)
          Returns the subtraction of this matrix and another.
 IntegerSparseSquareMatrix subtract(IntegerSparseSquareMatrix m)
          Returns the addition of this matrix and another.
 IntegerSquareMatrix subtract(IntegerSquareMatrix m)
          DOCUMENT ME!
 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.
 int trace()
          Returns the trace.
 Matrix transpose()
          Returns the transpose of this matrix.
 
Methods inherited from class org.jscience.mathematics.algebraic.matrices.AbstractIntegerSquareMatrix
add, directSum, inverse, isSymmetric, isUnitary, negate, qrDecompose, scalarProduct, singularValueDecompose, subtract, tensorProduct
 
Methods inherited from class org.jscience.mathematics.algebraic.matrices.AbstractIntegerMatrix
abs, add, directSum, equals, equals, equals, getColumn, getElement, getMatrixAsColumns, getMatrixAsRows, getRow, getSet, getSubMatrix, hashCode, horizontalAxisSymmetry, mass, max, mean, min, multiply, multiply, 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.Matrix
getColumn, getElement, getRow, numColumns, numRows, toArray
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, getElement, numDimensions, numElements, numElements, toArray, toArray
 

Constructor Detail

IntegerSparseSquareMatrix

public IntegerSparseSquareMatrix(int size)
Constructs an empty matrix.

Parameters:
size - the number of rows/columns

IntegerSparseSquareMatrix

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

Parameters:
array - an assigned value
Throws:
IllegalDimensionException - If the array is not square.

IntegerSparseSquareMatrix

public IntegerSparseSquareMatrix(IntegerSparseSquareMatrix mat)
Copy constructor.

Parameters:
mat - an assigned value
Method Detail

equals

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

Parameters:
m - a integer matrix
tol - DOCUMENT ME!
Returns:
DOCUMENT ME!

equals

public boolean equals(IntegerSparseSquareMatrix m)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

equals

public boolean equals(IntegerSparseSquareMatrix m,
                      double tol)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
tol - DOCUMENT ME!
Returns:
DOCUMENT ME!

toString

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

Overrides:
toString in class AbstractIntegerMatrix
Returns:
DOCUMENT ME!

toDoubleMatrix

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

Overrides:
toDoubleMatrix in class AbstractIntegerSquareMatrix
Returns:
an double square matrix

toComplexMatrix

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

Overrides:
toComplexMatrix in class AbstractIntegerSquareMatrix
Returns:
a complex square 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
Returns:
DOCUMENT ME!
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

det

public int det()
Returns the determinant.

Overrides:
det in class AbstractIntegerSquareMatrix
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

trace

public int trace()
Returns the trace.

Overrides:
trace in class AbstractIntegerSquareMatrix
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

infNorm

public int infNorm()
Returns the linfinity-norm.

Overrides:
infNorm in class AbstractIntegerMatrix
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

frobeniusNorm

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

Overrides:
frobeniusNorm in class AbstractIntegerMatrix
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

add

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

Overrides:
add in class AbstractIntegerSquareMatrix
Parameters:
m - a integer matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are different sizes.

add

public IntegerSquareMatrix add(IntegerSquareMatrix m)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

add

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

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

subtract

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

Overrides:
subtract in class AbstractIntegerSquareMatrix
Parameters:
m - a integer matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are different sizes.

subtract

public IntegerSquareMatrix subtract(IntegerSquareMatrix m)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

subtract

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

Parameters:
m - a integer sparse matrix
Returns:
DOCUMENT ME!
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 AbstractIntegerSquareMatrix
Parameters:
x - a integer
Returns:
a double sparse matrix

scalarProduct

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

Overrides:
scalarProduct in class AbstractIntegerSquareMatrix
Parameters:
m - a integer matrix.
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are different sizes.

scalarProduct

public int scalarProduct(IntegerSquareMatrix m)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

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
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrix and vector are incompatible.

multiply

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

Overrides:
multiply in class AbstractIntegerSquareMatrix
Parameters:
m - a integer matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are incompatible.

multiply

public IntegerSquareMatrix multiply(IntegerSquareMatrix m)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

multiply

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

Parameters:
m - a integer sparse matrix
Returns:
DOCUMENT ME!
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 AbstractIntegerSquareMatrix
Returns:
a integer sparse matrix

luDecompose

public AbstractDoubleSquareMatrix[] luDecompose(int[] pivot)
Returns the LU decomposition of this matrix.

Overrides:
luDecompose in class AbstractIntegerSquareMatrix
Parameters:
pivot - an empty array of length numRows()+1 to hold the pivot information (null if not interested)
Returns:
an array with [0] containing the L-matrix and [1] containing the U-matrix.

choleskyDecompose

public AbstractDoubleSquareMatrix[] choleskyDecompose()
Returns the Cholesky decomposition of this matrix. Matrix must be symmetric and positive definite.

Overrides:
choleskyDecompose in class AbstractIntegerSquareMatrix
Returns:
an array with [0] containing the L-matrix and [1] containing the U-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 integer 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.