org.openmali.number.matrix
Class MatrixMxNrad

java.lang.Object
  extended by org.openmali.number.matrix.MatrixMxNrad
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Matrix3rad, Matrix4rad

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

A general matrix implementing basic radical algebra. The implementation is aimed for applications where trigonomic constants are applicable, where exact arithmatic can be performed and is useful, and where speed is not an issue.

See Also:
Serialized Form

Field Summary
protected  int colSkip
          A matrix might be part of another, larger matrix.
protected  int dataBegin
          A matrix might be part of another, larger matrix.
protected  Radical1[] values
          The data of the Matrix
 
Constructor Summary
protected MatrixMxNrad(boolean readOnly, int rows, int cols)
          Constructs an nRow by nCol identity matrix.
protected MatrixMxNrad(boolean readOnly, int dataBegin, int colskip, int rows, int cols, Radical1[] values)
           
protected MatrixMxNrad(boolean readOnly, int rows, int cols, Radical1[] values)
          Constructs an nRow by nCol matrix initialized to the values in the matrix array.
protected MatrixMxNrad(boolean readOnly, MatrixMxNrad matrix)
          Constructs a new GMatrix and copies the initial values from the parameter matrix.
  MatrixMxNrad(int rows, int cols)
          Constructs an nRow by nCol identity matrix.
protected MatrixMxNrad(int dataBegin, int colskip, int rows, int cols, Radical1[] values)
           
  MatrixMxNrad(int rows, int cols, Radical1[] values)
          Constructs an nRow by nCol matrix initialized to the values in the matrix array.
  MatrixMxNrad(MatrixMxNrad matrix)
          Constructs a new GMatrix and copies the initial values from the parameter matrix.
 
Method Summary
 void add(float scalar)
          Adds a scalar to this Matrix.
 void add(MatrixMxNrad m2)
          Sets the value of this matrix to sum of itself and matrix m2.
 void add(MatrixMxNrad m1, MatrixMxNrad m2)
          Sets the value of this matrix to the matrix sum of matrices m1 and m2.
 MatrixMxNrad clone()
          
 void copySubMatrix(int rowSource, int colSource, int numRows, int numCols, int rowDest, int colDest, MatrixMxNrad target)
          Copies a sub-matrix derived from this matrix into the target matrix.
 boolean equals(MatrixMxNrad mat2)
          Returns true if all of the data members of Matrix4d m1 are equal to the corresponding data members in this Matrix4d.
 boolean equals(java.lang.Object o)
          Returns true if the Object o1 is of type GMatrix and all of the data members of t1 are equal to the corresponding data members in this Matrix.
 Radical1 get(int row, int column, Radical1 passback)
          Retrieves the value at the specified row and column of this matrix.
 void getColumn(int col, TupleNrad<?> tuple)
          Places the values of the specified column into the vector parameter.
 int getNumCols()
           
 int getNumRows()
           
 Radical1 getReference(int row, int column)
           
 void getRow(int row, TupleNrad<?> tuple)
          Places the values of the specified row into the vector parameter.
 MatrixMxNrad getSharedSubMatrix(boolean readOnly, int beginRow, int beginCol, int rows, int cols)
          Creates a Submatrix of mat, that begins in beginRow and beginCol.
 MatrixMxNrad getSharedSubMatrix(int beginRow, int beginCol, int rows, int cols)
          Creates a Submatrix of mat, that begins in beginRow and beginCol.
 int hashCode()
          Returns a hash number based on the data values in this object.
 boolean isDirty()
           
 boolean isReadOnly()
           
 boolean isSquare()
           
 boolean isSubMatrix()
           
 void mul(float scalar)
          Multiplies this Matrix with a scalar.
 void mul(MatrixMxNrad gmat)
          Sets the value of this matrix to the result of multiplying itself with matrix m1 (this = this * m1).
 void mul(MatrixMxNrad m1, MatrixMxNrad m2)
          Sets the value of this matrix to the result of multiplying the two argument matrices together (this = m1 * m2).
 void mul(TupleNrad<?> v1, TupleNrad<?> v2)
          Computes the outer product of the two vectors; multiplies the the first vector by the transpose of the second vector and places the matrix result into this matrix.
 void mulTransposeBoth(MatrixMxNrad m1, MatrixMxNrad m2)
          Multiplies the transpose of matrix m1 times the transpose of matrix m2, and places the result into this.
 void mulTransposeLeft(MatrixMxNrad m1, MatrixMxNrad m2)
          Multiplies the transpose of matrix m1 times the matrix m2, and places the result into this.
 void negate()
          Negates the value of this matrix: this = -this.
 void negate(MatrixMxNrad m)
          Sets the value of this matrix to the negation of the Matrix parameter.
static MatrixMxNrad newReadOnly(int rows, int cols)
          Constructs an nRow by nCol identity matrix.
static MatrixMxNrad newReadOnly(int rows, int cols, Radical1[] values)
          Constructs an nRow by nCol matrix initialized to the values in the matrix array.
static MatrixMxNrad newReadOnly(MatrixMxNrad matrix)
          Constructs a new GMatrix and copies the initial values from the parameter matrix.
 void set(int row, int column, Radical1 value)
          Modifies the value at the specified row and column of this matrix.
 void set(MatrixMxNrad values)
           
 boolean setClean()
          Marks this Matrix non-dirty.
 void setColumn(int col, TupleNrad<?> tuple)
          Copy the values from the array into the specified column of this matrix.
 void setIdentity()
          Sets this GMatrix to the identity matrix.
 void setReference(int row, int column, Radical1 ref)
          sets the underlying reference of this matrix.
 void setZero()
          Sets all the values in this matrix to zero.
static MatrixMxNf sharedSubMatrixMxNrad(MatrixMxNf mat, int beginRow, int beginCol, int rows, int cols, boolean readOnly)
          creates a shared Submatrix of mat.
static MatrixMxNrad sharedSubMatrixMxNrad(MatrixMxNrad mat, int beginRow, int beginCol, int rows, int cols)
          creates a shared Submatrix of mat.
 void sub(float scalar)
          Subtracts a scalar from this Matrix.
 void sub(MatrixMxNrad m2)
          Sets the value of this matrix to the matrix difference of itself and matrix m2 (this = this - m2).
 void sub(MatrixMxNrad m1, MatrixMxNrad m2)
          Sets the value of this matrix to the matrix difference of matrices m1 and m2 (this = m1 - m2).
 java.lang.String toString()
          
 void transpose()
          Transposes this matrix in place.
 void transpose(MatrixMxNrad mat)
          Places the matrix values of the transpose of matrix mat into this matrix.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

values

protected final Radical1[] values
The data of the Matrix. (1D array. The (i, j) element is stored in elementData[ i * col + j ])


dataBegin

protected final int dataBegin
A matrix might be part of another, larger matrix. Because we don't want to copy changes on the backing-matrix everytime to the submatrix, they share the same data-array.
dataBegin describes, where the data of this matrix begins.
For normal use this is 0.


colSkip

protected final int colSkip
A matrix might be part of another, larger matrix. Because we don't want to copy changes on the backing-matrix everytime to the submatrix, they share the same data-array.
colskip describes, how many columns the submatrix has, so we really are able to simulate the submatrix.
For normal use this is equal to cols.

Constructor Detail

MatrixMxNrad

protected MatrixMxNrad(boolean readOnly,
                       int rows,
                       int cols)
Constructs an nRow by nCol identity matrix. Note that even though row and column numbering begins with zero, nRow and nCol will be one larger than the maximum possible matrix index values.

Parameters:
readOnly -
rows - number of rows in this matrix.
cols - number of columns in this matrix.

MatrixMxNrad

protected MatrixMxNrad(boolean readOnly,
                       int rows,
                       int cols,
                       Radical1[] values)
Constructs an nRow by nCol matrix initialized to the values in the matrix array. The array values are copied in one row at a time in row major fashion. The array should be at least nRow*nCol in length. Note that even though row and column numbering begins with zero, nRow and nCol will be one larger than the maximum possible matrix index values.

Parameters:
readOnly -
rows - number of rows in this matrix.
cols - number of columns in this matrix.
values - a 1D array that specifies a matrix in row major fashion

MatrixMxNrad

protected MatrixMxNrad(boolean readOnly,
                       MatrixMxNrad matrix)
Constructs a new GMatrix and copies the initial values from the parameter matrix.

Parameters:
readOnly -
matrix - the source of the initial values of the new GMatrix

MatrixMxNrad

protected MatrixMxNrad(boolean readOnly,
                       int dataBegin,
                       int colskip,
                       int rows,
                       int cols,
                       Radical1[] values)
Parameters:
readOnly -
dataBegin -
colskip -
values -
See Also:
getSharedSubMatrix(int, int, int, int), MatrixMxNf.MatrixMxNf(int, int, int, int, float[])

MatrixMxNrad

public MatrixMxNrad(int rows,
                    int cols)
Constructs an nRow by nCol identity matrix. Note that even though row and column numbering begins with zero, nRow and nCol will be one larger than the maximum possible matrix index values.

Parameters:
rows - number of rows in this matrix.
cols - number of columns in this matrix.

MatrixMxNrad

public MatrixMxNrad(int rows,
                    int cols,
                    Radical1[] values)
Constructs an nRow by nCol matrix initialized to the values in the matrix array. The array values are copied in one row at a time in row major fashion. The array should be at least nRow*nCol in length. Note that even though row and column numbering begins with zero, nRow and nCol will be one larger than the maximum possible matrix index values.

Parameters:
rows - number of rows in this matrix.
cols - number of columns in this matrix.
values - a 1D array that specifies a matrix in row major fashion

MatrixMxNrad

public MatrixMxNrad(MatrixMxNrad matrix)
Constructs a new GMatrix and copies the initial values from the parameter matrix.

Parameters:
matrix - the source of the initial values of the new GMatrix

MatrixMxNrad

protected MatrixMxNrad(int dataBegin,
                       int colskip,
                       int rows,
                       int cols,
                       Radical1[] values)
Parameters:
dataBegin -
colskip -
values -
See Also:
getSharedSubMatrix(int, int, int, int), MatrixMxNf.MatrixMxNf(int, int, int, int, float[])
Method Detail

getNumRows

public final int getNumRows()
Returns:
number of rows in this matrix

getNumCols

public final int getNumCols()
Returns:
number of columns in this matrix

isSquare

public final boolean isSquare()
Returns:
Is this Matrix a square-Matrix?

isReadOnly

public final boolean isReadOnly()
Returns:
Is this Matrix a read-only-Matrix?

setClean

public final boolean setClean()
Marks this Matrix non-dirty. Any value-manipulation will mark it dirty again.

Returns:
the old value

isDirty

public final boolean isDirty()
Returns:
This Matrix' dirty-flag

isSubMatrix

public final boolean isSubMatrix()
Returns:
true, if this Matrix is backed by another (usually larger) matrix.

set

public final void set(int row,
                      int column,
                      Radical1 value)
Modifies the value at the specified row and column of this matrix.

Parameters:
row - the row number to be modified (zero indexed)
column - the column number to be modified (zero indexed)
value - the new matrix element value

setReference

public void setReference(int row,
                         int column,
                         Radical1 ref)
sets the underlying reference of this matrix. Note you can seriously mess up an object instance by using this. Consider the object read only for saftey.

Parameters:
row -
column -
ref -

get

public final Radical1 get(int row,
                          int column,
                          Radical1 passback)
Retrieves the value at the specified row and column of this matrix.

Parameters:
row - the row number to be retrieved (zero indexed)
column - the column number to be retrieved (zero indexed)
Returns:
the value at the indexed element

getReference

public final Radical1 getReference(int row,
                                   int column)

set

public void set(MatrixMxNrad values)

getRow

public final void getRow(int row,
                         TupleNrad<?> tuple)
Places the values of the specified row into the vector parameter.

Parameters:
row - the target row number
tuple - the vector into which the row values will be placed

setColumn

public final void setColumn(int col,
                            TupleNrad<?> tuple)
Copy the values from the array into the specified column of this matrix.

Parameters:
col - the column of this matrix into which the vector values will be copied.
tuple - the source vector

getColumn

public final void getColumn(int col,
                            TupleNrad<?> tuple)
Places the values of the specified column into the vector parameter.

Parameters:
col - the target column number
tuple - the vector into which the column values will be placed

setZero

public final void setZero()
Sets all the values in this matrix to zero.


setIdentity

public final void setIdentity()
Sets this GMatrix to the identity matrix.


negate

public final void negate()
Negates the value of this matrix: this = -this.


negate

public final void negate(MatrixMxNrad m)
Sets the value of this matrix to the negation of the Matrix parameter.

Parameters:
m - The source matrix

transpose

public void transpose()
Transposes this matrix in place.


transpose

public void transpose(MatrixMxNrad mat)
Places the matrix values of the transpose of matrix mat into this matrix.

Parameters:
mat - the matrix to be transposed (but not modified)

copySubMatrix

public final void copySubMatrix(int rowSource,
                                int colSource,
                                int numRows,
                                int numCols,
                                int rowDest,
                                int colDest,
                                MatrixMxNrad target)
Copies a sub-matrix derived from this matrix into the target matrix. The upper left of the sub-matrix is located at (rowSource, colSource); the lower right of the sub-matrix is located at (lastRowSource,lastColSource). The sub-matrix is copied into the the target matrix starting at (rowDest, colDest).

Parameters:
rowSource - the top-most row of the sub-matrix
colSource - the left-most column of the sub-matrix
numRows - the number of rows in the sub-matrix
numCols - the number of columns in the sub-matrix
rowDest - the top-most row of the position of the copied sub-matrix within the target matrix
colDest - the left-most column of the position of the copied sub-matrix within the target matrix
target - the matrix into which the sub-matrix will be copied

add

public final void add(float scalar)
Adds a scalar to this Matrix.

Parameters:
scalar -

add

public final void add(MatrixMxNrad m2)
Sets the value of this matrix to sum of itself and matrix m2.

Parameters:
m2 - the other matrix

add

public final void add(MatrixMxNrad m1,
                      MatrixMxNrad m2)
Sets the value of this matrix to the matrix sum of matrices m1 and m2.

Parameters:
m1 - the first matrix
m2 - the second matrix

sub

public final void sub(float scalar)
Subtracts a scalar from this Matrix.

Parameters:
scalar -

sub

public final void sub(MatrixMxNrad m2)
Sets the value of this matrix to the matrix difference of itself and matrix m2 (this = this - m2).

Parameters:
m2 - the other matrix

sub

public final void sub(MatrixMxNrad m1,
                      MatrixMxNrad m2)
Sets the value of this matrix to the matrix difference of matrices m1 and m2 (this = m1 - m2).

Parameters:
m1 - the first matrix
m2 - the second matrix

mul

public final void mul(float scalar)
Multiplies this Matrix with a scalar.

Parameters:
scalar -

mul

public void mul(MatrixMxNrad m1,
                MatrixMxNrad m2)
Sets the value of this matrix to the result of multiplying the two argument matrices together (this = m1 * m2).

Parameters:
m1 - the first matrix
m2 - the second matrix

mul

public void mul(MatrixMxNrad gmat)
Sets the value of this matrix to the result of multiplying itself with matrix m1 (this = this * m1).

Parameters:
gmat - the other matrix

mul

public void mul(TupleNrad<?> v1,
                TupleNrad<?> v2)
Computes the outer product of the two vectors; multiplies the the first vector by the transpose of the second vector and places the matrix result into this matrix. This matrix must be as big or bigger than getSize(v1) x getSize(v2).

Parameters:
v1 - the first vector, treated as a row vector
v2 - the second vector, treated as a column vector

mulTransposeBoth

public void mulTransposeBoth(MatrixMxNrad m1,
                             MatrixMxNrad m2)
Multiplies the transpose of matrix m1 times the transpose of matrix m2, and places the result into this.

Parameters:
m1 - The matrix on the left hand side of the multiplication
m2 - The matrix on the right hand side of the multiplication

mulTransposeLeft

public void mulTransposeLeft(MatrixMxNrad m1,
                             MatrixMxNrad m2)
Multiplies the transpose of matrix m1 times the matrix m2, and places the result into this.

Parameters:
m1 - The matrix on the left hand side of the multiplication
m2 - The matrix on the right hand side of the multiplication

hashCode

public int hashCode()
Returns a hash number based on the data values in this object. Two different GMatrix objects with identical data values (ie, returns true for equals(GMatrix) ) will return the same hash number. Two objects with different data members may return the same hash value, although this is not likely.

Overrides:
hashCode in class java.lang.Object
Returns:
the integer hash value

equals

public boolean equals(MatrixMxNrad mat2)
Returns true if all of the data members of Matrix4d m1 are equal to the corresponding data members in this Matrix4d.

Parameters:
mat2 - The matrix with which the comparison is made.
Returns:
true or false

equals

public boolean equals(java.lang.Object o)
Returns true if the Object o1 is of type GMatrix and all of the data members of t1 are equal to the corresponding data members in this Matrix.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object with which the comparison is made.

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

clone

public MatrixMxNrad clone()

Overrides:
clone in class java.lang.Object

getSharedSubMatrix

public MatrixMxNrad getSharedSubMatrix(boolean readOnly,
                                       int beginRow,
                                       int beginCol,
                                       int rows,
                                       int cols)
Creates a Submatrix of mat, that begins in beginRow and beginCol.
Example: let mat be a 4x4 matrix, and we want to have a 2x2 submatrix at position (1,2):
x x x x
x x y y
x x y y
x x x x
the y's mark the fetched Submatrix.
The produced submatrix works on the same data array as mat, so changes are seen on the other one respectively.

Parameters:
readOnly -
beginRow - the row to start this matrix at
beginCol - the column to start this matrix at
rows -
cols -
Returns:
the new shared submatrix

getSharedSubMatrix

public MatrixMxNrad getSharedSubMatrix(int beginRow,
                                       int beginCol,
                                       int rows,
                                       int cols)
Creates a Submatrix of mat, that begins in beginRow and beginCol.
Example: let mat be a 4x4 matrix, and we want to have a 2x2 submatrix at position (1,2):
x x x x
x x y y
x x y y
x x x x
the y's mark the fetched Submatrix.
The produced submatrix works on the same data array as mat, so changes are seen on the other one respectively.

Parameters:
beginRow - the row to start this matrix at
beginCol - the column to start this matrix at
rows -
cols -
Returns:
the new shared submatrix

newReadOnly

public static MatrixMxNrad newReadOnly(int rows,
                                       int cols)
Constructs an nRow by nCol identity matrix. Note that even though row and column numbering begins with zero, nRow and nCol will be one larger than the maximum possible matrix index values.

Parameters:
rows - number of rows in this matrix.
cols - number of columns in this matrix.

newReadOnly

public static MatrixMxNrad newReadOnly(int rows,
                                       int cols,
                                       Radical1[] values)
Constructs an nRow by nCol matrix initialized to the values in the matrix array. The array values are copied in one row at a time in row major fashion. The array should be at least nRow*nCol in length. Note that even though row and column numbering begins with zero, nRow and nCol will be one larger than the maximum possible matrix index values.

Parameters:
rows - number of rows in this matrix.
cols - number of columns in this matrix.
values - a 1D array that specifies a matrix in row major fashion

newReadOnly

public static MatrixMxNrad newReadOnly(MatrixMxNrad matrix)
Constructs a new GMatrix and copies the initial values from the parameter matrix.

Parameters:
matrix - the source of the initial values of the new GMatrix

sharedSubMatrixMxNrad

public static MatrixMxNf sharedSubMatrixMxNrad(MatrixMxNf mat,
                                               int beginRow,
                                               int beginCol,
                                               int rows,
                                               int cols,
                                               boolean readOnly)
creates a shared Submatrix of mat. Does the same as getSharedSubMatrix(int, int, int, int)

See Also:
getSharedSubMatrix(int, int, int, int)

sharedSubMatrixMxNrad

public static MatrixMxNrad sharedSubMatrixMxNrad(MatrixMxNrad mat,
                                                 int beginRow,
                                                 int beginCol,
                                                 int rows,
                                                 int cols)
creates a shared Submatrix of mat. Does the same as getSharedSubMatrix(int, int, int, int)

See Also:
getSharedSubMatrix(int, int, int, int)