HFE
Class Matrix4

java.lang.Object
  |
  +--HFE.Matrix4
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Matrix4
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

The class Matrix4 provides matrix operations for matrices over the finite field F_4 which is specified in Field4. The class provides only operations which are needed in the HFE package. The class is based upon the Jama package, which was produced by The MathWorks, Inc. and the National Institute of Standards and Technology. Jama can be downloaded from the NIST page http://math.nist.gov/javanumerics/jama/.

Version:
0.1
See Also:
Serialized Form

Field Summary
private  int[][] A
          Array for internal storage of elements.
private  int m
          Row (m) and column (n) dimensions.
private  int n
          Row (m) and column (n) dimensions.
 
Constructor Summary
Matrix4(int[][] A)
          Construct a matrix using the given array with checking.
Matrix4(int[][] A, int m, int n)
          Construct a matrix using the given array without checking.
Matrix4(int m, int n)
          Construct an m-by-n matrix of zeros.
Matrix4(int m, int n, java.util.Random rnd)
          Generats an m-by-n random matrix.
 
Method Summary
 Matrix4 add(Matrix4 B)
          C = A + B
(package private)  void addEquals(Matrix4 B)
          A += B
 void addRowsEquals(int i, int j)
          A[i] += A[j].
 void addRowsEquals(int f, int i, int j)
          A[i] += f*A[j].
private  void checkMatrixDimensions(Matrix4 B)
          Check if size(A) == size(B)
 java.lang.Object clone()
          Clone the Matrix object.
 Matrix4 copy()
          Make a deep copy of a matrix Allocates new memory
 int get(int i, int j)
          Get a single element.
 int[][] getArray()
          Returns a pointer to the internal two-dimensional array.
 int[][] getArrayCopy()
          Copy the internal two-dimensional array.
 int getColumnDimension()
          Get column dimension.
 int[] getColumnPackedCopy()
          Make a one-dimensional column packed copy of the internal array.
 Matrix4 getMatrix(int[] r, int[] c)
          Get a submatrix.
 Matrix4 getMatrix(int[] r, int j0, int j1)
          Get a submatrix.
 Matrix4 getMatrix(int i0, int i1, int[] c)
          Get a submatrix.
 Matrix4 getMatrix(int i0, int i1, int j0, int j1)
          Get a submatrix.
 int getRowDimension()
          Get row dimension.
 int[] getRowPackedCopy()
          Make a one-dimensional row packed copy of the internal array.
static Matrix4 identity(int m, int n)
          Generate identity matrix
 boolean isEqual(Matrix4 B)
          Compares two matrices.
 LUDecomposition4 lu()
          LU Decomposition
static void main(java.lang.String[] args)
          Tests everything in this class
 void mul(int[] b, int[] res)
          Linear algebraic matrix/vector multiplication, res = A * b.
 Matrix4 mul(Matrix4 B)
          Linear algebraic matrix multiplication, A * B.
 void set(int i, int j, int s)
          Set a single element.
 void set(java.util.Random rnd)
          Generats an m-by-n random matrix.
 void setMatrix(int[] r, int[] c, Matrix4 X)
          Set a submatrix.
 void setMatrix(int[] r, int j0, int j1, Matrix4 X)
          Set a submatrix.
 void setMatrix(int i0, int i1, int[] c, Matrix4 X)
          Set a submatrix.
 void setMatrix(int i0, int i1, int j0, int j1, Matrix4 X)
          Set a submatrix.
 void setRowZero(int i)
          Set a row elementwise zero.
 Matrix4 sub(Matrix4 B)
          C = A - B
(package private)  void subEquals(Matrix4 B)
          A -= B
static void testIt()
          Tests the functionality of the whole class.
 Matrix4 transpose()
          Matrix transpose.
 
Methods inherited from class java.lang.Object
, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

A

private int[][] A
Array for internal storage of elements.

m

private int m
Row (m) and column (n) dimensions.

n

private int n
Row (m) and column (n) dimensions.
Constructor Detail

Matrix4

public Matrix4(int m,
               int n)
Construct an m-by-n matrix of zeros.
Parameters:
m - Number of rows.
n - Number of colums.

Matrix4

public Matrix4(int[][] A)
Construct a matrix using the given array with checking. The constructor checks if all the elements are in F_4 and if the array is rectangular. It does not clone the given array.
Parameters:
A - Elements of the matrix as a 2D array.

Matrix4

public Matrix4(int[][] A,
               int m,
               int n)
Construct a matrix using the given array without checking. The constructor does not check if all the elements are in F_4 or if the array is rectangular but assumes that. It does neither clone this array.
Parameters:
A - Elements of the matrix as a 2D array.
m - Number of rows.
n - Number of colums.

Matrix4

public Matrix4(int m,
               int n,
               java.util.Random rnd)
Generats an m-by-n random matrix.
Parameters:
m - Number of rows.
n - Number of colums.
rnd - number generator
Method Detail

copy

public Matrix4 copy()
Make a deep copy of a matrix Allocates new memory

clone

public java.lang.Object clone()
Clone the Matrix object.
Overrides:
clone in class java.lang.Object

getArray

public int[][] getArray()
Returns a pointer to the internal two-dimensional array.
Returns:
Pointer to the two-dimensional array of matrix elements.

getArrayCopy

public int[][] getArrayCopy()
Copy the internal two-dimensional array.
Returns:
Two-dimensional array copy of matrix elements.

getColumnPackedCopy

public int[] getColumnPackedCopy()
Make a one-dimensional column packed copy of the internal array.
Returns:
Matrix elements packed in a one-dimensional array by columns.

getRowPackedCopy

public int[] getRowPackedCopy()
Make a one-dimensional row packed copy of the internal array.
Returns:
Matrix elements packed in a one-dimensional array by rows.

getRowDimension

public int getRowDimension()
Get row dimension.
Returns:
m, the number of rows.

getColumnDimension

public int getColumnDimension()
Get column dimension.
Returns:
n, the number of columns.

get

public int get(int i,
               int j)
Get a single element.
Parameters:
i - Row index.
j - Column index.
Returns:
A(i,j)
Throws:
ArrayIndexOutOfBoundsException -  

getMatrix

public Matrix4 getMatrix(int i0,
                         int i1,
                         int j0,
                         int j1)
Get a submatrix.
Parameters:
i0 - Initial row index
i1 - Final row index
j0 - Initial column index
j1 - Final column index
Returns:
A(i0:i1,j0:j1)
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

getMatrix

public Matrix4 getMatrix(int[] r,
                         int[] c)
Get a submatrix.
Parameters:
r - Array of row indices.
c - Array of column indices.
Returns:
A(r(:),c(:))
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

getMatrix

public Matrix4 getMatrix(int i0,
                         int i1,
                         int[] c)
Get a submatrix.
Parameters:
i0 - Initial row index
i1 - Final row index
c - Array of column indices.
Returns:
A(i0:i1,c(:))
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

getMatrix

public Matrix4 getMatrix(int[] r,
                         int j0,
                         int j1)
Get a submatrix.
Parameters:
r - Array of row indices.
i0 - Initial column index
i1 - Final column index
Returns:
A(r(:),j0:j1)
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

set

public void set(int i,
                int j,
                int s)
Set a single element.
Parameters:
i - Row index.
j - Column index.
s - A(i,j).
Throws:
ArrayIndexOutOfBoundsException -  

set

public void set(java.util.Random rnd)
Generats an m-by-n random matrix.
Parameters:
rnd - number generator

setMatrix

public void setMatrix(int i0,
                      int i1,
                      int j0,
                      int j1,
                      Matrix4 X)
Set a submatrix.
Parameters:
i0 - Initial row index
i1 - Final row index
j0 - Initial column index
j1 - Final column index
X - A(i0:i1,j0:j1)
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int[] r,
                      int[] c,
                      Matrix4 X)
Set a submatrix.
Parameters:
r - Array of row indices.
c - Array of column indices.
X - A(r(:),c(:))
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int[] r,
                      int j0,
                      int j1,
                      Matrix4 X)
Set a submatrix.
Parameters:
r - Array of row indices.
j0 - Initial column index
j1 - Final column index
X - A(r(:),j0:j1)
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int i0,
                      int i1,
                      int[] c,
                      Matrix4 X)
Set a submatrix.
Parameters:
i0 - Initial row index
i1 - Final row index
c - Array of column indices.
X - A(i0:i1,c(:))
Throws:
ArrayIndexOutOfBoundsException - Submatrix indices

setRowZero

public void setRowZero(int i)
Set a row elementwise zero.

transpose

public Matrix4 transpose()
Matrix transpose.
Returns:
A^T

add

public Matrix4 add(Matrix4 B)
C = A + B
Parameters:
B - another matrix
Returns:
A + B

addRowsEquals

public void addRowsEquals(int i,
                          int j)
A[i] += A[j]. Adds elementwise the two rows i,j

addRowsEquals

public void addRowsEquals(int f,
                          int i,
                          int j)
A[i] += f*A[j]. Adds elementwise the two rows i,j. The row j is first multiplied with the scalar f
Parameters:
f - scalar
i - number of the destination row
j - number of the source row

addEquals

void addEquals(Matrix4 B)
A += B
Parameters:
B - another matrix
Returns:
A + B

sub

public Matrix4 sub(Matrix4 B)
C = A - B
Parameters:
B - another matrix
Returns:
A - B

subEquals

void subEquals(Matrix4 B)
A -= B
Parameters:
B - another matrix
Returns:
A - B

mul

public Matrix4 mul(Matrix4 B)
Linear algebraic matrix multiplication, A * B. Multiplication is not in place.
Parameters:
B - another matrix with B.m == A.n (rows equals columns)
Returns:
Matrix product (in a new matrix!), A * B
Throws:
java.lang.IllegalArgumentException - Matrix inner dimensions must agree.

mul

public void mul(int[] b,
                int[] res)
Linear algebraic matrix/vector multiplication, res = A * b. Multiplication is in place.
Parameters:
b - a vector with b.length == A.n (rows equals columns)

lu

public LUDecomposition4 lu()
LU Decomposition
Returns:
LUDecomposition4
See Also:
LUDecomposition4

identity

public static Matrix4 identity(int m,
                               int n)
Generate identity matrix
Parameters:
m - Number of rows.
n - Number of colums.
Returns:
An m-by-n matrix with ones on the diagonal and zeros elsewhere.

isEqual

public boolean isEqual(Matrix4 B)
Compares two matrices.
Parameters:
B - another matrix
Returns:
true: Matrices are equal.
false: Matrices are not equal (e.g. different size, different elements)

testIt

public static void testIt()
Tests the functionality of the whole class. If there occurs any error it will be printed on stdout.

main

public static void main(java.lang.String[] args)
Tests everything in this class
See Also:
testIt()

checkMatrixDimensions

private void checkMatrixDimensions(Matrix4 B)
Check if size(A) == size(B)