|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.openmali.vecmath2.MatrixMxNf
public class MatrixMxNf
A float precision, general, real, two dimensional m x n matrix class. Row and column numbering is zero-based. The representation is row major. Inspired by Kenji Hiranabe's GMatrix implementation
| 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 boolean[] |
isDirty
|
protected int |
roTrick
This is used to costlessly make the Matrix read-only. |
protected float[] |
values
The data of the Matrix |
| Constructor Summary | |
|---|---|
protected |
MatrixMxNf(boolean readOnly,
int rows,
int cols)
Constructs an nRow by nCol identity matrix. |
protected |
MatrixMxNf(boolean readOnly,
int rows,
int cols,
float[] values)
Constructs an rows by cols matrix initialized to the values in the matrix array. |
protected |
MatrixMxNf(boolean readOnly,
int dataBegin,
int colskip,
int rows,
int cols,
float[] values,
boolean[] isDirty)
Hidden constructor for #sharedSubMatrixMxNf(MatrixMxNf, int, int) and #getSharedSubMatrix(int, int, int, int). |
protected |
MatrixMxNf(boolean readOnly,
MatrixMxNf matrix)
Constructs a new MatrixMxNf and copies the initial values from the parameter matrix. |
|
MatrixMxNf(int rows,
int cols)
Constructs an nRow by nCol identity matrix. |
|
MatrixMxNf(int rows,
int cols,
float[] values)
Constructs an nRow by nCol matrix initialized to the values in the matrix array. |
protected |
MatrixMxNf(int dataBegin,
int colskip,
int rows,
int cols,
float[] values)
Hidden constructor for #sharedSubMatrixMxNf(MatrixMxNf, int, int) and #getSharedSubMatrix(int, int, int, int). |
|
MatrixMxNf(MatrixMxNf matrix)
Constructs a new GMatrix and copies the initial values from the parameter matrix. |
| Method Summary | |
|---|---|
MatrixMxNf |
add(float scalar)
Adds a scalar to this Matrix. |
MatrixMxNf |
add(int row,
int column,
float summand)
Adds the given summand to the element identified by row and column. |
MatrixMxNf |
add(MatrixMxNf m2)
Sets the value of this matrix to sum of itself and matrix m2. |
MatrixMxNf |
add(MatrixMxNf m1,
MatrixMxNf m2)
Sets the value of this matrix to the matrix sum of matrices m1 and m2. |
MatrixMxNf |
asReadOnly()
|
MatrixMxNf |
clone()
|
float |
cond()
Matrix condition (2 norm) |
void |
copySubMatrix(int rowSource,
int colSource,
int numRows,
int numCols,
int rowDest,
int colDest,
MatrixMxNf target)
Copies a sub-matrix derived from this matrix into the target matrix. |
int |
deserialize(int pos,
byte[] buffer)
Deserializes this instanc'es data from the byte array. |
MatrixMxNf |
div(int row,
int column,
float divisor)
Devides the element identified by row and column with the given divisor. |
boolean |
epsilonEquals(MatrixMxNf mat2,
float epsilon)
Returns true if the L-infinite distance between this matrix and matrix m1 is less than or equal to the epsilon parameter, otherwise returns false. |
boolean |
equals(MatrixMxNf 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. |
float |
get(int row,
int column)
Retrieves the value at the specified row and column of this matrix. |
protected float |
get(int row,
int colSkip,
int column)
|
void |
get(Matrix3f mat)
Places the values in the upper 3x3 of this Matrix into the matrix mat. |
void |
get(Matrix4f mat)
Places the values in the upper 4x4 of this GMatrix into the matrix mat. |
void |
get(MatrixMxNf mat)
Places the values in the this matrix into the matrix mat; mat should be at least as large as this Matrix. |
void |
getColumn(int col,
float[] buffer)
Places the values of the specified column into the array parameter. |
void |
getColumn(int col,
TupleNf<?> tuple)
Places the values of the specified column into the vector parameter. |
void |
getColumnMajor(float[] values)
Sets the value of this matrix to the values found in the array parameter. |
void |
getColumnMajor(float[] values,
int offset)
Sets the value of this matrix to the values found in the array parameter. |
int |
getNumCols()
|
int |
getNumRows()
|
MatrixMxNf |
getReadOnly()
|
void |
getRow(int row,
float[] buffer)
Places the values of the specified row into the array parameter. |
void |
getRow(int row,
TupleNf<?> tuple)
Places the values of the specified row into the vector parameter. |
void |
getRowMajor(float[] values)
Sets the value of this matrix to the values found in the array parameter. |
void |
getRowMajor(float[] values,
int offset)
Sets the value of this matrix to the values found in the array parameter. |
protected int |
getSerializationBufferSize()
|
MatrixMxNf |
getSharedSubMatrix(boolean readOnly,
int beginRow,
int beginCol,
int rows,
int cols)
Creates a Submatrix of mat, that begins in beginRow and beginCol. |
MatrixMxNf |
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. |
MatrixMxNf |
identityMinus()
Subtracts this matrix from the identity matrix and puts the values back into this (this = I - this). |
void |
interpolate(MatrixMxNf m1,
MatrixMxNf m2,
float alpha)
Interpolates each value of this Matrix by the value alpha. |
MatrixMxNf |
invert()
Inverts this matrix in place. |
MatrixMxNf |
invert(MatrixMxNf m)
Inverts matrix m and places the new values into this matrix. |
boolean |
isDirty()
|
boolean |
isPositiveDefinite()
Tests whether the matrix is positive definite. |
boolean |
isPositiveDefinite(int n)
Tests whether a submatrix is positive definite. |
boolean |
isReadOnly()
|
boolean |
isSquare()
|
boolean |
isSubMatrix()
|
int |
LUD(MatrixMxNf lu,
VectorNf permutation)
LU Decomposition; this matrix must be a square matrix; the LU GMatrix parameter must be the same size as this matrix. |
MatrixMxNf |
mul(float scalar)
Multiplies this Matrix with a scalar. |
MatrixMxNf |
mul(int row,
int column,
float factor)
Multiplies the element identified by row and column with the given factor. |
MatrixMxNf |
mul(MatrixMxNf mat2)
Sets the value of this matrix to the result of multiplying itself with matrix m1 (this = this * m1). |
MatrixMxNf |
mul(MatrixMxNf m1,
MatrixMxNf m2)
Sets the value of this matrix to the result of multiplying the two argument matrices together (this = m1 * m2). |
MatrixMxNf |
mul(TupleNf<?> v1,
TupleNf<?> 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. |
MatrixMxNf |
mulComp(MatrixMxNf mat2)
Sets the value of this matrix to the result of multiplying this matrix and the other one componentwisely (this = this x m2). |
MatrixMxNf |
mulComp(MatrixMxNf m1,
MatrixMxNf m2)
Sets the value of this matrix to the result of multiplying the two argument matrices componentwisely (this = m1 x m2). |
MatrixMxNf |
mulTransposeBoth(MatrixMxNf m1,
MatrixMxNf m2)
Multiplies the transpose of matrix m1 times the transpose of matrix m2, and places the result into this. |
MatrixMxNf |
mulTransposeLeft(MatrixMxNf m1,
MatrixMxNf m2)
Multiplies the transpose of matrix m1 times the matrix m2, and places the result into this. |
MatrixMxNf |
mulTransposeRight(MatrixMxNf m1,
MatrixMxNf m2)
Multiplies matrix m1 times the transpose of matrix m2, and places the result into this. |
MatrixMxNf |
negate()
Negates the value of this matrix: this = -this. |
MatrixMxNf |
negate(MatrixMxNf m)
Sets the value of this matrix to the negation of the Matrix parameter. |
static MatrixMxNf |
newReadOnly(int rows,
int cols)
Constructs an nRow by nCol identity matrix. |
static MatrixMxNf |
newReadOnly(int rows,
int cols,
float[] values)
Constructs an nRow by nCol matrix initialized to the values in the matrix array. |
static MatrixMxNf |
newReadOnly(MatrixMxNf matrix)
Constructs a new GMatrix and copies the initial values from the parameter matrix. |
float |
norm1()
Calculates the One-norm. |
float |
norm2()
Calculates the One-norm. |
float |
normFrobenius()
Calculates the Frobenius-norm. |
float |
normInfinity()
Calculates the Infinity-norm. |
int |
rank()
Computes the effective numerical rank, obtained from SVD. |
void |
readExternal(java.io.ObjectInput in)
|
int |
serialize(int pos,
byte[] buffer)
Serializes this instanc'es data into the byte array. |
MatrixMxNf |
set(int row,
int column,
float value)
Modifies the value at the specified row and column of this matrix. |
protected MatrixMxNf |
set(int row,
int colSkip,
int column,
float value)
|
void |
set(Matrix3f mat)
Sets the value of this matrix to that of the Matrix3f provided. |
void |
set(Matrix4f mat)
Sets the value of this matrix to that of the Matrix4f provided. |
void |
set(MatrixMxNf mat)
Sets the value of this matrix to the values found in matrix mat. |
boolean |
setClean()
Marks this Matrix non-dirty. |
MatrixMxNf |
setColumn(int col,
float[] values)
Copies the values from the array into the specified column of this matrix. |
MatrixMxNf |
setColumn(int col,
TupleNf<?> tuple)
Copy the values from the array into the specified column of this matrix. |
void |
setColumnMajor(float[] values)
Sets the value of this matrix to the values found in the array parameter. |
void |
setColumnMajor(float[] values,
int offset)
Sets the value of this matrix to the values found in the array parameter. |
MatrixMxNf |
setIdentity()
Sets this GMatrix to the identity matrix. |
MatrixMxNf |
setRow(int row,
float[] values)
Copies the values from the array into the specified row of this matrix. |
MatrixMxNf |
setRow(int row,
TupleNf<?> tuple)
Copies the values from the array into the specified row of this matrix. |
void |
setRowMajor(float[] values)
Sets the value of this matrix to the values found in the array parameter. |
void |
setRowMajor(float[] values,
int offset)
Sets the value of this matrix to the values found in the array parameter. |
MatrixMxNf |
setScale(float scale)
Sets this matrix to a uniform scale matrix; all of the values are reset. |
MatrixMxNf |
setZero()
Sets all the values in this matrix to zero. |
static MatrixMxNf |
sharedSubMatrixMxNf(MatrixMxNf mat,
int beginRow,
int beginCol,
int rows,
int cols)
Creates a shared Submatrix of mat. |
static MatrixMxNf |
sharedSubMatrixMxNf(MatrixMxNf mat,
int beginRow,
int beginCol,
int rows,
int cols,
boolean readOnly)
Creates a shared Submatrix of mat. |
void |
solve(MatrixMxNf m2,
MatrixMxNf result)
Solves this * X = m2. |
boolean |
solve(TupleNf<?> b,
TupleNf<?> passback)
Performs gaussian elimination with parial pivoting. |
MatrixMxNf |
sub(float scalar)
Subtracts a scalar from this Matrix. |
MatrixMxNf |
sub(int row,
int column,
float value)
Subtracts the given summand from the element identified by row and column. |
MatrixMxNf |
sub(MatrixMxNf m2)
Sets the value of this matrix to the matrix difference of itself and matrix m2 (this = this - m2). |
MatrixMxNf |
sub(MatrixMxNf m1,
MatrixMxNf m2)
Sets the value of this matrix to the matrix difference of matrices m1 and m2 (this = m1 - m2). |
int |
SVD(MatrixMxNf u,
MatrixMxNf w,
MatrixMxNf v)
Finds the singular value decomposition (SVD) of this matrix such that this = U*W*transpose(V); and returns the rank of this matrix; the values of U,W,V are all overwritten. |
java.lang.String |
toString()
|
float |
trace()
|
MatrixMxNf |
transpose()
Transposes this matrix in place, this can only be done on square matrices. |
MatrixMxNf |
transpose(MatrixMxNf mat)
Places the matrix values of the transpose of matrix mat into this matrix. |
void |
writeExternal(java.io.ObjectOutput out)
|
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected final float[] values
protected final int dataBegin
dataBegin describes, where the data of this matrix begins.
protected final int colSkip
colskip describes, how many columns the submatrix has, so we really are able to simulate the submatrix.cols.
protected final int roTrick
protected final boolean[] isDirty
| Constructor Detail |
|---|
protected MatrixMxNf(boolean readOnly,
int rows,
int cols)
readOnly - rows - number of rows in this matrix.cols - number of columns in this matrix.
protected MatrixMxNf(boolean readOnly,
int rows,
int cols,
float[] values)
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
protected MatrixMxNf(boolean readOnly,
MatrixMxNf matrix)
readOnly - matrix - the source of the initial values of the new GMatrix
protected MatrixMxNf(boolean readOnly,
int dataBegin,
int colskip,
int rows,
int cols,
float[] values,
boolean[] isDirty)
readOnly - dataBegin - colskip - rows - cols - values - isDirty -
public MatrixMxNf(int rows,
int cols)
rows - number of rows in this matrix.cols - number of columns in this matrix.
public MatrixMxNf(int rows,
int cols,
float[] values)
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 fashionpublic MatrixMxNf(MatrixMxNf matrix)
matrix - the source of the initial values of the new GMatrix
protected MatrixMxNf(int dataBegin,
int colskip,
int rows,
int cols,
float[] values)
dataBegin - colskip - values - | Method Detail |
|---|
public final int getNumRows()
public final int getNumCols()
public final boolean isSquare()
public final boolean isReadOnly()
public final boolean setClean()
public final boolean isDirty()
public final boolean isSubMatrix()
true, if this Matrix is backed by another (usually larger) matrix.
public final MatrixMxNf set(int row,
int column,
float value)
row - the row number to be modified (zero indexed)column - the column number to be modified (zero indexed)value - the new matrix element value
protected final MatrixMxNf set(int row,
int colSkip,
int column,
float value)
public final float get(int row,
int column)
row - the row number to be retrieved (zero indexed)column - the column number to be retrieved (zero indexed)
protected final float get(int row,
int colSkip,
int column)
public final MatrixMxNf add(int row,
int column,
float summand)
row - the row number to be modified (zero indexed)column - the column number to be modified (zero indexed)summand - the value to add
public final MatrixMxNf sub(int row,
int column,
float value)
row - the row number to be modified (zero indexed)column - the column number to be modified (zero indexed)value - the value to subtract
public final MatrixMxNf mul(int row,
int column,
float factor)
row - the row number to be modified (zero indexed)column - the column number to be modified (zero indexed)factor - the factor to multiply by
public final MatrixMxNf div(int row,
int column,
float divisor)
row - the row number to be modified (zero indexed)column - the column number to be modified (zero indexed)divisor - the factor to multiply by
public final MatrixMxNf setRow(int row,
float[] values)
row - the row of this matrix into which the array values will be copied.values - the source array
public final MatrixMxNf setRow(int row,
TupleNf<?> tuple)
row - the row of this matrix into which the vector values will be copied.tuple - the source vector
public final void getRow(int row,
float[] buffer)
row - the target row numberbuffer - the array into which the row values will be placed
public final void getRow(int row,
TupleNf<?> tuple)
row - the target row numbertuple - the vector into which the row values will be placed
public final MatrixMxNf setColumn(int col,
float[] values)
col - the column of this matrix into which the array values will be copied.values - the source array
public final MatrixMxNf setColumn(int col,
TupleNf<?> tuple)
col - the column of this matrix into which the vector values will be copied.tuple - the source vector
public final void getColumn(int col,
float[] buffer)
col - the target column numberbuffer - the array into which the column values will be placed
public final void getColumn(int col,
TupleNf<?> tuple)
col - the target column numbertuple - the vector into which the column values will be placed
public final void setRowMajor(float[] values,
int offset)
values - the row major source arrayoffset - the offset in the (source) values arraypublic final void setRowMajor(float[] values)
values - the row major source array
public final void setColumnMajor(float[] values,
int offset)
values - the column major source arrayoffset - the offset in the (source) values arraypublic final void setColumnMajor(float[] values)
values - the column major source arraypublic void set(Matrix3f mat)
mat - the source matrixpublic final void set(Matrix4f mat)
mat - the source matrixpublic final void set(MatrixMxNf mat)
mat - the source matrix
public final void getRowMajor(float[] values,
int offset)
values - the row major source arrayoffset - the offset in the (target) values arraypublic final void getRowMajor(float[] values)
values - the row major source array
public final void getColumnMajor(float[] values,
int offset)
values - the column major source arrayoffset - the offset in the (target) values arraypublic final void getColumnMajor(float[] values)
values - the column major source arraypublic void get(Matrix3f mat)
mat - The matrix that will hold the new valuespublic final void get(Matrix4f mat)
mat - The matrix that will hold the new valuespublic final void get(MatrixMxNf mat)
mat - The matrix that will hold the new valuespublic MatrixMxNf setScale(float scale)
scale - the new scale value
public final MatrixMxNf setZero()
public final MatrixMxNf setIdentity()
public final MatrixMxNf negate()
public final MatrixMxNf negate(MatrixMxNf m)
m - The source matrix
public final MatrixMxNf identityMinus()
public MatrixMxNf invert()
public MatrixMxNf invert(MatrixMxNf m)
m - the matrix to be inverted
public MatrixMxNf transpose()
public MatrixMxNf transpose(MatrixMxNf mat)
mat - the matrix to be transposed (but not modified)
public float norm1()
public final float norm2()
public float normInfinity()
public float normFrobenius()
public boolean isPositiveDefinite(int n)
n - the size of the submatrix to be tested
true if the submatrix is positive definite,
and false otherwisepublic boolean isPositiveDefinite()
true if the matrix is positive definite,
and false otherwisepublic final float trace()
public final int rank()
public final float cond()
public final void copySubMatrix(int rowSource,
int colSource,
int numRows,
int numCols,
int rowDest,
int colDest,
MatrixMxNf target)
rowSource - the top-most row of the sub-matrixcolSource - the left-most column of the sub-matrixnumRows - the number of rows in the sub-matrixnumCols - the number of columns in the sub-matrixrowDest - the top-most row of the position of the copied sub-matrix
within the target matrixcolDest - the left-most column of the position of the copied
sub-matrix within the target matrixtarget - the matrix into which the sub-matrix will be copiedpublic final MatrixMxNf add(float scalar)
scalar -
public final MatrixMxNf add(MatrixMxNf m2)
m2 - the other matrix
public final MatrixMxNf add(MatrixMxNf m1,
MatrixMxNf m2)
m1 - the first matrixm2 - the second matrix
public final MatrixMxNf sub(float scalar)
scalar -
public final MatrixMxNf sub(MatrixMxNf m2)
m2 - the other matrix
public final MatrixMxNf sub(MatrixMxNf m1,
MatrixMxNf m2)
m1 - the first matrixm2 - the second matrix
public MatrixMxNf mul(float scalar)
scalar -
public MatrixMxNf mul(MatrixMxNf m1,
MatrixMxNf m2)
m1 - the first matrixm2 - the second matrix
public MatrixMxNf mul(MatrixMxNf mat2)
mat2 - the other matrix
public final MatrixMxNf mulComp(MatrixMxNf m1,
MatrixMxNf m2)
m1 - the first matrixm2 - the second matrix
public final MatrixMxNf mulComp(MatrixMxNf mat2)
mat2 - the other matrix
public MatrixMxNf mul(TupleNf<?> v1,
TupleNf<?> v2)
v1 - the first vector, treated as a row vectorv2 - the second vector, treated as a column vector
public MatrixMxNf mulTransposeBoth(MatrixMxNf m1,
MatrixMxNf m2)
m1 - The matrix on the left hand side of the multiplicationm2 - The matrix on the right hand side of the multiplication
public MatrixMxNf mulTransposeLeft(MatrixMxNf m1,
MatrixMxNf m2)
m1 - The matrix on the left hand side of the multiplicationm2 - The matrix on the right hand side of the multiplication
public MatrixMxNf mulTransposeRight(MatrixMxNf m1,
MatrixMxNf m2)
public final void solve(MatrixMxNf m2,
MatrixMxNf result)
m2 - right hand sideresult - if this is square, least squares solution otherwise
public boolean solve(TupleNf<?> b,
TupleNf<?> passback)
VectorNf.LUDBackSolve(MatrixMxNf, VectorNf, VectorNf) seems to do the same. For large Matrices it is probably even more GC-friendly.
public int SVD(MatrixMxNf u,
MatrixMxNf w,
MatrixMxNf v)
u - The computed U matrix in the equation this = U*W*transpose(V)w - The computed W matrix in the equation this = U*W*transpose(V)v - The computed V matrix in the equation this = U*W*transpose(V)
public int LUD(MatrixMxNf lu,
VectorNf permutation)
permutation - The row permutation effected by the partial pivoting
public void interpolate(MatrixMxNf m1,
MatrixMxNf m2,
float alpha)
m1 - m2 - alpha - public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(MatrixMxNf mat2)
mat2 - The matrix with which the comparison is made.
public boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - the object with which the comparison is made.
public boolean epsilonEquals(MatrixMxNf mat2,
float epsilon)
mat2 - The matrix to be compared to this matrixepsilon - the threshold valuepublic java.lang.String toString()
toString in class java.lang.Objectpublic MatrixMxNf clone()
clone in class java.lang.Object
public MatrixMxNf getSharedSubMatrix(boolean readOnly,
int beginRow,
int beginCol,
int rows,
int cols)
readOnly - beginRow - the row to start this matrix atbeginCol - the column to start this matrix atrows - cols -
MatrixMxNf(int, int, int, int, float[])
public MatrixMxNf getSharedSubMatrix(int beginRow,
int beginCol,
int rows,
int cols)
beginRow - the row to start this matrix atbeginCol - the column to start this matrix atrows - cols -
public MatrixMxNf asReadOnly()
getReadOnly()public MatrixMxNf getReadOnly()
asReadOnly()
public int serialize(int pos,
byte[] buffer)
pos - buffer -
public int deserialize(int pos,
byte[] buffer)
pos - buffer -
protected int getSerializationBufferSize()
public void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
java.io.IOException
public void readExternal(java.io.ObjectInput in)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public static MatrixMxNf newReadOnly(int rows,
int cols)
rows - number of rows in this matrix.cols - number of columns in this matrix.
public static MatrixMxNf newReadOnly(int rows,
int cols,
float[] values)
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 fashionpublic static MatrixMxNf newReadOnly(MatrixMxNf matrix)
matrix - the source of the initial values of the new GMatrix
public static MatrixMxNf sharedSubMatrixMxNf(MatrixMxNf mat,
int beginRow,
int beginCol,
int rows,
int cols,
boolean readOnly)
getSharedSubMatrix(int, int, int, int).
mat - beginRow - beginCol - rows - cols -
public static MatrixMxNf sharedSubMatrixMxNf(MatrixMxNf mat,
int beginRow,
int beginCol,
int rows,
int cols)
getSharedSubMatrix(int, int, int, int).
mat - beginRow - beginCol - rows - cols -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||