public class FloatMatrixMath
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
protected static void |
_checkSameDimension(java.lang.String caller,
float[][] matrix1,
float[][] matrix2)
Check that the two matrix arguments are of the same dimension.
|
protected static int |
_checkSquare(java.lang.String caller,
float[][] matrix)
Check that the argument matrix is a square matrix.
|
protected static int |
_columns(float[][] matrix)
Return the number of columns of a matrix.
|
protected static java.lang.String |
_dimensionString(float[][] matrix)
Return a string that describes the number of rows and columns.
|
protected static java.lang.Object[] |
_orthogonalizeRows(float[][] rowArrays)
Given a set of row vectors rowArrays[0] ... rowArrays[n-1], compute :
A new set of row vectors out[0] ... out[n-1] which are the
orthogonalized versions of each input row vector.
|
protected static int |
_rows(float[][] matrix)
Return the number of rows of a matrix.
|
static float[][] |
add(float[][] matrix,
float z)
Return a new matrix that is constructed from the argument by
adding the second argument to every element.
|
static float[][] |
add(float[][] matrix1,
float[][] matrix2)
Return a new matrix that is constructed from the argument by
adding the second matrix to the first one.
|
static float[][] |
allocCopy(float[][] matrix)
Return a new matrix that is a copy of the matrix argument.
|
static float[][] |
applyBinaryOperation(FloatBinaryOperation op,
float[][] matrix,
float z)
Return a new array that is formed by applying an instance of a
FloatBinaryOperation to each element in the input matrix,
using the matrix elements as the left operands and z as the right
operand in all cases (op.operate(matrix[i][j], z)).
|
static float[][] |
applyBinaryOperation(FloatBinaryOperation op,
float[][] matrix1,
float[][] matrix2)
Return a new array that is formed by applying an instance of a
FloatBinaryOperation to the two matrices, element by element,
using the elements of the first matrix as the left operands
and the elements of the second matrix as the right operands.
|
static float[][] |
applyBinaryOperation(FloatBinaryOperation op,
float z,
float[][] matrix)
Return a new array that is formed by applying an instance of a
FloatBinaryOperation to each element in the input matrix,
using z as the left operand in all cases and the matrix elements
as the right operands (op.operate(z, matrix[i][j])).
|
static float[][] |
applyUnaryOperation(FloatUnaryOperation op,
float[][] matrix)
Return a new array that is formed by applying an instance of a
FloatUnaryOperation to each element in the input matrix
(op.operate(matrix[i][j])).
|
static float[][] |
crop(float[][] matrix,
int rowStart,
int colStart,
int rowSpan,
int colSpan)
Return a new matrix that is a sub-matrix of the input
matrix argument.
|
static float |
determinant(float[][] matrix)
Return the determinant of a square matrix.
|
static float[][] |
diag(float[] array)
Return a new matrix that is constructed by placing the
elements of the input array on the diagonal of the square
matrix, starting from the top left corner down to the bottom
right corner.
|
static float[][] |
divide(float[][] matrix,
float z)
Return a new matrix that is constructed from the argument by
dividing the second argument to every element.
|
static float[][] |
divideElements(float[][] matrix1,
float[][] matrix2)
Return a new matrix that is constructed by element by element
division of the two matrix arguments.
|
static float[] |
fromMatrixToArray(float[][] matrix)
Return a new array that is filled with the contents of the matrix.
|
static float[] |
fromMatrixToArray(float[][] matrix,
int maxRow,
int maxCol)
Return a new array that is filled with the contents of the matrix.
|
static float[][] |
hilbert(int dim)
Return a new matrix, which is defined by Aij = 1/(i+j+1),
the Hilbert matrix.
|
static float[][] |
identity(int dim)
Return an new identity matrix with the specified dimension.
|
static float[][] |
inverse(float[][] A)
Return a new matrix that is constructed by inverting the input
matrix.
|
static void |
matrixCopy(float[][] srcMatrix,
float[][] destMatrix)
Replace the first matrix argument elements with the values of
the second matrix argument.
|
static void |
matrixCopy(float[][] srcMatrix,
int srcRowStart,
int srcColStart,
float[][] destMatrix,
int destRowStart,
int destColStart,
int rowSpan,
int colSpan)
Replace the first matrix argument's values, in the specified row
and column range, with the second matrix argument's values, starting
from specified row and column of the second matrix.
|
static float[][] |
multiply(float[][] matrix,
float scaleFactor)
Return a new matrix that is constructed by multiplying the matrix
by a scaleFactor.
|
static float[] |
multiply(float[][] matrix,
float[] array)
Return a new array that is constructed from the argument by
pre-multiplying the array (treated as a row vector) by a matrix.
|
static float[][] |
multiply(float[][] matrix1,
float[][] matrix2)
Return a new matrix that is constructed from the argument by
multiplying the first matrix by the second one.
|
static float[] |
multiply(float[] array,
float[][] matrix)
Return a new array that is constructed from the argument by
post-multiplying the matrix by an array (treated as a row vector).
|
static float[][] |
multiplyElements(float[][] matrix1,
float[][] matrix2)
Return a new matrix that is constructed by element by element
multiplication of the two matrix arguments.
|
static float[][] |
negative(float[][] matrix)
Return a new matrix that is the additive inverse of the
argument matrix.
|
static float[][] |
orthogonalizeColumns(float[][] matrix)
Return a new matrix that is formed by orthogonalizing the
columns of the input matrix (the column vectors are
orthogonal).
|
static float[][] |
orthogonalizeRows(float[][] matrix)
Return a new matrix that is formed by orthogonalizing the rows of the
input matrix (the row vectors are orthogonal).
|
static float[][] |
orthonormalizeColumns(float[][] matrix)
Return a new matrix that is formed by orthogonalizing the
columns of the input matrix (the column vectors are orthogonal
and have norm 1).
|
static float[][] |
orthonormalizeRows(float[][] matrix)
Return a new matrix that is formed by orthonormalizing the
rows of the input matrix (the row vectors are orthogonal and
have norm 1).
|
static float[][][] |
qr(float[][] matrix)
Return a pair of matrices that are the decomposition of the
input matrix (which must have linearly independent column
vectors), which is m x n, into the matrix product of Q, which
is m x n with orthonormal column vectors, and R, which is an
invertible n x n upper triangular matrix.
|
static float[][] |
subtract(float[][] matrix1,
float[][] matrix2)
Return a new matrix that is constructed from the argument by
subtracting the second matrix from the first one.
|
static float |
sum(float[][] matrix)
Return the sum of the elements of a matrix.
|
static Complex[][] |
toComplexMatrix(float[][] matrix)
Return a new matrix that is formed by converting the floats
in the argument matrix to complex numbers.
|
static double[][] |
toDoubleMatrix(float[][] matrix)
Return a new matrix that is formed by converting the floats in
the argument matrix to doubles.
|
static int[][] |
toIntegerMatrix(float[][] matrix)
Return a new matrix that is formed by converting the floats in
the argument matrix to integers.
|
static long[][] |
toLongMatrix(float[][] matrix)
Return a new matrix that is formed by converting the floats in
the argument matrix to longs.
|
static float[][] |
toMatrixFromArray(float[] array,
int rows,
int cols)
Return a new matrix of floats that is initialized from a 1-D
array.
|
static java.lang.String |
toString(float[][] matrix)
Return a new String representing the matrix, formatted as
in Java array initializers.
|
static java.lang.String |
toString(float[][] matrix,
java.lang.String elementDelimiter,
java.lang.String matrixBegin,
java.lang.String matrixEnd,
java.lang.String vectorBegin,
java.lang.String vectorDelimiter,
java.lang.String vectorEnd)
Return a new String representing the matrix, formatted as
specified by the ArrayStringFormat argument.
|
static float |
trace(float[][] matrix)
Return the trace of a square matrix, which is the sum of the
diagonal entries A11 + A22 + ... + Ann
Throw an IllegalArgumentException if the matrix is not square.
|
static float[][] |
transpose(float[][] matrix)
Return a new matrix that is constructed by transposing the input
matrix.
|
static boolean |
within(float[][] matrix1,
float[][] matrix2,
float distance)
Return true if the elements of the two matrices differ by no more
than the specified distance.
|
static boolean |
within(float[][] matrix1,
float[][] matrix2,
float[][] errorMatrix)
Return true if the elements of the two matrices differ by no more
than the specified distances.
|
public static final float[][] add(float[][] matrix, float z)
matrix
- A matrix of floats.z
- The float number to add.public static final float[][] add(float[][] matrix1, float[][] matrix2)
matrix1
- The first matrix of floats.matrix2
- The second matrix of floats.public static final float[][] allocCopy(float[][] matrix)
matrix
- A matrix of floats.public static final float[][] applyBinaryOperation(FloatBinaryOperation op, float z, float[][] matrix)
public static final float[][] applyBinaryOperation(FloatBinaryOperation op, float[][] matrix, float z)
public static final float[][] applyBinaryOperation(FloatBinaryOperation op, float[][] matrix1, float[][] matrix2)
public static final float[][] applyUnaryOperation(FloatUnaryOperation op, float[][] matrix)
public static final float[][] crop(float[][] matrix, int rowStart, int colStart, int rowSpan, int colSpan)
matrix
- A matrix of floats.rowStart
- An int specifying which row to start on.colStart
- An int specifying which column to start on.rowSpan
- An int specifying how many rows to copy.colSpan
- An int specifying how many columns to copy.public static final float determinant(float[][] matrix)
public static final float[][] diag(float[] array)
public static final float[][] divide(float[][] matrix, float z)
matrix
- A matrix of floats.z
- The float number to divide.public static final float[][] divideElements(float[][] matrix1, float[][] matrix2)
public static final float[] fromMatrixToArray(float[][] matrix)
matrix
- A matrix of floats.public static final float[] fromMatrixToArray(float[][] matrix, int maxRow, int maxCol)
matrix
- A matrix of floats.public static final float[][] hilbert(int dim)
public static final float[][] identity(int dim)
public static final float[][] inverse(float[][] A)
public static final void matrixCopy(float[][] srcMatrix, float[][] destMatrix)
destMatrix
- A matrix of floats, used as the destination.srcMatrix
- A matrix of floats, used as the source.public static final void matrixCopy(float[][] srcMatrix, int srcRowStart, int srcColStart, float[][] destMatrix, int destRowStart, int destColStart, int rowSpan, int colSpan)
srcMatrix
- A matrix of floats, used as the destination.srcRowStart
- An int specifying the starting row of the source.srcColStart
- An int specifying the starting column of the
source.destMatrix
- A matrix of floats, used as the destination.destRowStart
- An int specifying the starting row of the dest.destColStart
- An int specifying the starting column of the
dest.rowSpan
- An int specifying how many rows to copy.colSpan
- An int specifying how many columns to copy.public static final float[][] multiply(float[][] matrix, float scaleFactor)
public static final float[] multiply(float[][] matrix, float[] array)
public static final float[] multiply(float[] array, float[][] matrix)
public static final float[][] multiply(float[][] matrix1, float[][] matrix2)
Note that this method is different from the other multiply() methods in that this method does not do pointwise multiplication.
matrix1
- The first matrix of floats.matrix2
- The second matrix of floats.multiplyElements(float[][], float[][])
public static final float[][] multiplyElements(float[][] matrix1, float[][] matrix2)
Note that this method does pointwise matrix multiplication.
See multiply(float[][], float[][])
for standard
matrix multiplication.
public static final float[][] negative(float[][] matrix)
public static final float[][] orthogonalizeColumns(float[][] matrix)
public static final float[][] orthogonalizeRows(float[][] matrix)
public static final float[][] orthonormalizeColumns(float[][] matrix)
public static final float[][] orthonormalizeRows(float[][] matrix)
public static final float[][][] qr(float[][] matrix)
matrix
- The input matrix of floats.public static final float[][] subtract(float[][] matrix1, float[][] matrix2)
public static final float sum(float[][] matrix)
public static final Complex[][] toComplexMatrix(float[][] matrix)
matrix
- A matrix of floats.public static final double[][] toDoubleMatrix(float[][] matrix)
matrix
- An matrix of float.public static final int[][] toIntegerMatrix(float[][] matrix)
matrix
- An matrix of float.public static final long[][] toLongMatrix(float[][] matrix)
matrix
- An matrix of float.public static final float[][] toMatrixFromArray(float[] array, int rows, int cols)
array
- An array of floats.rows
- An integer representing the number of rows of the new
matrix.cols
- An integer representing the number of columns of the new
matrix.public static final java.lang.String toString(float[][] matrix)
public static final java.lang.String toString(float[][] matrix, java.lang.String elementDelimiter, java.lang.String matrixBegin, java.lang.String matrixEnd, java.lang.String vectorBegin, java.lang.String vectorDelimiter, java.lang.String vectorEnd)
public static final float trace(float[][] matrix)
public static final float[][] transpose(float[][] matrix)
public static final boolean within(float[][] matrix1, float[][] matrix2, float distance)
matrix1
- The first matrix.matrix2
- The second matrix.distance
- The distance to use for comparison.java.lang.IllegalArgumentException
- If the matrices do not have the same dimension.
This is a run-time exception, so it need not be declared explicitly.public static final boolean within(float[][] matrix1, float[][] matrix2, float[][] errorMatrix)
matrix1
- The first matrix.matrix2
- The second matrix.errorMatrix
- The distance to use for comparison.java.lang.IllegalArgumentException
- If the matrices do not have the same dimension.
This is a run-time exception, so it need not be declared explicitly.protected static final void _checkSameDimension(java.lang.String caller, float[][] matrix1, float[][] matrix2)
caller
- A string representing the caller method name.matrix1
- A matrix of floats.matrix2
- A matrix of floats.protected static final int _checkSquare(java.lang.String caller, float[][] matrix)
caller
- A string representing the caller method name.matrix
- A matrix of floats.protected static final int _columns(float[][] matrix)
protected static final java.lang.String _dimensionString(float[][] matrix)
matrix
- The matrix that is to be described.protected static final java.lang.Object[] _orthogonalizeRows(float[][] rowArrays)
protected static final int _rows(float[][] matrix)
matrix
- The matrix.