org.jscience.mathematics.algebraic.matrices
Class AbstractIntegerMatrix

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
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Member
Direct Known Subclasses:
AbstractIntegerSquareMatrix, IntegerMatrix, IntegerSparseMatrix

public abstract class AbstractIntegerMatrix
extends AbstractMatrix

The AbstractIntegerMatrix class provides an object for encapsulating integer matrices.

See Also:
Serialized Form

Constructor Summary
protected AbstractIntegerMatrix(int rows, int cols)
          Constructs a matrix.
 
Method Summary
 AbstractIntegerMatrix abs()
          Applies the abs function on all the matrix components.
 AbelianGroup.Member add(AbelianGroup.Member m)
          Returns the addition of this matrix and another.
 AbstractIntegerMatrix add(AbstractIntegerMatrix m)
          Returns the addition of this matrix and another.
 AbstractIntegerMatrix directSum(AbstractIntegerMatrix m)
          Returns the direct sum of this matrix and another.
 boolean equals(AbstractIntegerMatrix m)
          Compares two ${nativeTyp} matrices for equality.
 boolean equals(AbstractIntegerMatrix m, double tol)
           
 boolean equals(java.lang.Object obj)
          Compares two ${nativeTyp} matrices for equality.
 double frobeniusNorm()
          Returns the Frobenius or Hilbert-Schmidt (l2) norm.
 AbstractIntegerVector getColumn(int j)
          Returns the ith column.
 Integer getElement(int i, int j)
          Returns an element of the matrix.
 int[] getMatrixAsColumns()
          Make a one-dimensional column packed copy of the internal array.
 int[] getMatrixAsRows()
          Make a one-dimensional row packed copy of the internal array.
abstract  int getPrimitiveElement(int i, int j)
          Returns an element of the matrix.
 AbstractIntegerVector getRow(int i)
          Returns the ith row.
 java.lang.Object getSet()
           
 AbstractIntegerMatrix getSubMatrix(int k1, int k2, int k3, int k4)
          Computes a sub matrix from the parameters index.
 int hashCode()
          Returns a hashcode for this NON EMPTY matrix.
 AbstractIntegerMatrix horizontalAxisSymmetry()
          Invert matrix elements order from the top to the bottom.
 int infNorm()
          Returns the linfinity-norm.
 AbstractDoubleMatrix mapElements(PrimitiveMapping f)
          Applies a function on all the matrix elements.
 int mass()
          Gets the mass of the matrix components.
 int max()
          Gets the max of the matrix components.
 double mean()
          Gets the mean of the matrix components.
 int min()
          Gets the min of the matrix components.
 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.
 Ring.Member multiply(Ring.Member m)
          Returns the multiplication of this matrix and another.
 AbelianGroup.Member negate()
          Returns the negative of this matrix.
static AbstractIntegerMatrix read(java.io.BufferedReader input)
          Read a matrix from a stream.
 AbstractIntegerMatrix reverse()
          Invert matrix elements order from the top to the bottom, from the right to the left.
 VectorSpace.Member scalarDivide(Field.Member x)
          Returns the division of this matrix by a scalar.
 AbstractIntegerMatrix scalarMultiply(int x)
          Returns the multiplication of this matrix by a scalar.
 Module.Member scalarMultiply(Ring.Member x)
          Returns the multiplication of this matrix by a scalar.
 int scalarProduct(AbstractIntegerMatrix m)
          Returns the scalar product of this matrix and another.
 void setAllElements(int m)
          Sets the value of all elements of the matrix.
 void setColumn(int j, AbstractIntegerVector v)
          Returns the ith column.
abstract  void setElement(int i, int j, int x)
          Sets the value of an element of the matrix.
 void setRow(int i, AbstractIntegerVector v)
          Returns the ith row.
 AbstractIntegerMatrix setSubMatrix(int k, int l, AbstractIntegerMatrix m)
          Set a sub matrix.
 AbelianGroup.Member subtract(AbelianGroup.Member m)
          Returns the subtraction of this matrix by another.
 AbstractIntegerMatrix subtract(AbstractIntegerMatrix m)
          Returns the subtraction of this matrix by another.
 AbstractIntegerMatrix tensorProduct(AbstractIntegerMatrix m)
          Returns the tensor product of this matrix and another.
 AbstractComplexMatrix toComplexMatrix()
          Converts this matrix to a complex matrix.
 AbstractDoubleMatrix toDoubleMatrix()
          Converts this matrix to a 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.
 AbstractIntegerMatrix verticalAxisSymmetry()
          Invert matrix elements order from the right to the left.
 
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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 

Constructor Detail

AbstractIntegerMatrix

protected AbstractIntegerMatrix(int rows,
                                int cols)
Constructs a matrix.

Method Detail

equals

public boolean equals(java.lang.Object obj)
Compares two ${nativeTyp} matrices for equality.

Overrides:
equals in class java.lang.Object
Parameters:
obj - a int matrix

equals

public boolean equals(AbstractIntegerMatrix m)
Compares two ${nativeTyp} matrices for equality. Two matrices are considered to be equal if the Frobenius norm of their difference is within the zero tolerance.

Parameters:
m - a double matrix

equals

public boolean equals(AbstractIntegerMatrix m,
                      double tol)

toString

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

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Returns a hashcode for this NON EMPTY matrix.

Overrides:
hashCode in class java.lang.Object

toDoubleMatrix

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

Returns:
a double matrix

toComplexMatrix

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

Returns:
a complex matrix

getPrimitiveElement

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

Parameters:
i - row index of the element
j - column index of the element
Throws:
IllegalDimensionException - If attempting to access an invalid element.

getElement

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

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.

getRow

public AbstractIntegerVector getRow(int i)
Returns the ith row.

Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!

getColumn

public AbstractIntegerVector getColumn(int j)
Returns the ith column.

Parameters:
j - DOCUMENT ME!
Returns:
DOCUMENT ME!

setRow

public void setRow(int i,
                   AbstractIntegerVector v)
Returns the ith row.


setColumn

public void setColumn(int j,
                      AbstractIntegerVector v)
Returns the ith column.


setElement

public abstract void setElement(int i,
                                int j,
                                int x)
Sets the value of an element of the matrix. Should only be used to initialise this matrix.

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 m)
Sets the value of all elements of the matrix.

Parameters:
m - a complex element

getSet

public final java.lang.Object getSet()

infNorm

public int infNorm()
Returns the linfinity-norm.


frobeniusNorm

public double frobeniusNorm()
Returns the Frobenius or Hilbert-Schmidt (l2) norm.


abs

public AbstractIntegerMatrix abs()
Applies the abs function on all the matrix components.


min

public int min()
Gets the min of the matrix components.

Returns:
the min.

mass

public int mass()
Gets the mass of the matrix components.

Returns:
the mass.

max

public int max()
Gets the max of the matrix components.

Returns:
the max.

mean

public double mean()
Gets the mean of the matrix components.

Returns:
the mean.

negate

public AbelianGroup.Member negate()
Returns the negative of this matrix.

Returns:
DOCUMENT ME!

add

public final AbelianGroup.Member add(AbelianGroup.Member m)
Returns the addition of this matrix and another.

Parameters:
m - a group member
Returns:
DOCUMENT ME!

add

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

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

subtract

public final AbelianGroup.Member subtract(AbelianGroup.Member m)
Returns the subtraction of this matrix by another.

Parameters:
m - a group member
Returns:
DOCUMENT ME!

subtract

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

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

scalarMultiply

public final Module.Member scalarMultiply(Ring.Member x)
Returns the multiplication of this matrix by a scalar.

Parameters:
x - a ring member
Returns:
DOCUMENT ME!

scalarMultiply

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

Parameters:
x - a int.
Returns:
a int matrix.

scalarDivide

public final VectorSpace.Member scalarDivide(Field.Member x)
Returns the division of this matrix by a scalar. Always throws an exception.

Parameters:
x - a field member
Returns:
DOCUMENT ME!

scalarProduct

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

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

multiply

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

Parameters:
v - a int vector.
Throws:
IllegalDimensionException - If the matrix and vector are incompatible.

multiply

public final Ring.Member multiply(Ring.Member m)
Returns the multiplication of this matrix and another.

Parameters:
m - a ring member
Returns:
DOCUMENT ME!

multiply

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

Parameters:
m - a int matrix
Returns:
a AbstractIntegerMatrix or a AbstractIntegerSquareMatrix as appropriate
Throws:
IllegalDimensionException - If the matrices are incompatible.

directSum

public AbstractIntegerMatrix directSum(AbstractIntegerMatrix m)
Returns the direct sum of this matrix and another.


tensorProduct

public AbstractIntegerMatrix tensorProduct(AbstractIntegerMatrix m)
Returns the tensor product of this matrix and another.


transpose

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

Returns:
a int matrix

horizontalAxisSymmetry

public AbstractIntegerMatrix horizontalAxisSymmetry()
Invert matrix elements order from the top to the bottom.


verticalAxisSymmetry

public AbstractIntegerMatrix verticalAxisSymmetry()
Invert matrix elements order from the right to the left.


reverse

public AbstractIntegerMatrix reverse()
Invert matrix elements order from the top to the bottom, from the right to the left.


getSubMatrix

public AbstractIntegerMatrix getSubMatrix(int k1,
                                          int k2,
                                          int k3,
                                          int k4)
Computes a sub matrix from the parameters index. If k1<0 k1 elements are added at the beginning of the returned matrix If k2>numRows() k2-numRows() elements are added at the end of the returned matrix Finally, if k1>k2 the vector is returned inverted. If k3<0 k3 elements are added at the beginning of the returned matrix If k4>numColumns() k2-numColumns() elements are added at the end of the returned matrix Finally, if k3>k4 the matrix is returned inverted.

Parameters:
k1 - the beginning rows index
k2 - the finishing rows index
k3 - the beginning columns index
k4 - the finishing columns index
Returns:
the sub matrix.

setSubMatrix

public AbstractIntegerMatrix setSubMatrix(int k,
                                          int l,
                                          AbstractIntegerMatrix m)
Set a sub matrix. If k<0 k elements are added at the beginning of the returned matrix If k+v.numRows()>numRows() k+v.numRows()-numRows() elements are added at the end of the returned matrix If l<0 l elements are added at the beginning of the returned matrix If l+v.numColumns()>numColumns() l+v.numColumns()-numColumns() elements are added at the end of the returned matrix

Parameters:
k - Initial row index to offset the patching matrix
l - Initial column index to offset the patching matrix
m - the patching matrix

mapElements

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

Parameters:
f - a user-defined function
Returns:
a double matrix

toPrimitiveArray

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

Returns:
an int array.

getMatrixAsRows

public int[] getMatrixAsRows()
Make a one-dimensional row packed copy of the internal array. Useful to iterate over the elements with an org.jscience.util.ArrayIterator

Returns:
Matrix elements packed in a one-dimensional array by rows.

getMatrixAsColumns

public int[] getMatrixAsColumns()
Make a one-dimensional column packed copy of the internal array. Useful to iterate over the elements with an org.jscience.util.ArrayIterator

Returns:
Matrix elements packed in a one-dimensional array by columns.

read

public static AbstractIntegerMatrix read(java.io.BufferedReader input)
                                  throws java.io.IOException
Read a matrix from a stream. The format is the same the print method, so printed matrices can be read back in (provided they were printed using US Locale). Elements are separated by whitespace, all the elements for each row appear on a single line, the last row is followed by a blank line.

Parameters:
input - the input stream.
Throws:
java.io.IOException