|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.math.IntegerMatrixMath
public class IntegerMatrixMath
This class provides a library for mathematical operations on matrices of ints. Rows and column numbers of matrices are specified with zero-based indices. All calls expect matrix arguments to be non-null. In addition, all rows of the matrix are expected to have the same number of columns.
Yellow (ctsay) |
Yellow (ctsay) |
Constructor Summary | |
---|---|
private |
IntegerMatrixMath()
|
Method Summary | |
---|---|
protected static void |
_checkSameDimension(java.lang.String caller,
int[][] matrix1,
int[][] matrix2)
Check that the two matrix arguments are of the same dimension. |
protected static int |
_checkSquare(java.lang.String caller,
int[][] matrix)
Check that the argument matrix is a square matrix. |
protected static int |
_columns(int[][] matrix)
Return the number of columns of a matrix. |
protected static java.lang.String |
_dimensionString(int[][] matrix)
Return a string that describes the number of rows and columns. |
protected static int |
_rows(int[][] matrix)
Return the number of rows of a matrix. |
static int[][] |
add(int[][] matrix,
int z)
Return a new matrix that is constructed from the argument by adding the second argument to every element. |
static int[][] |
add(int[][] matrix1,
int[][] matrix2)
Return a new matrix that is constructed from the argument by adding the second matrix to the first one. |
static int[][] |
allocCopy(int[][] matrix)
Return a new matrix that is a copy of the matrix argument. |
static int[][] |
applyBinaryOperation(IntegerBinaryOperation op,
int[][] matrix,
int z)
Return a new array that is formed by applying an instance of a IntegerBinaryOperation 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 int[][] |
applyBinaryOperation(IntegerBinaryOperation op,
int[][] matrix1,
int[][] matrix2)
Return a new array that is formed by applying an instance of a IntegerBinaryOperation 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 int[][] |
applyBinaryOperation(IntegerBinaryOperation op,
int z,
int[][] matrix)
Return a new array that is formed by applying an instance of a IntegerBinaryOperation 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 int[][] |
applyUnaryOperation(IntegerUnaryOperation op,
int[][] matrix)
Return a new array that is formed by applying an instance of a IntegerUnaryOperation to each element in the input matrix (op.operate(matrix[i][j])). |
static int[][] |
bitwiseAnd(int[][] matrix,
int z)
Return a new matrix that is the formed by bitwise ANDing z with each element of the input matrix (matrix[i][j] & z). |
static int[][] |
bitwiseAnd(int[][] matrix1,
int[][] matrix2)
Return a new array that is the element-by-element bitwise AND of the two input matrices (matrix1[i][j] & matrix2[i][j]). |
static int[][] |
bitwiseComplement(int[][] matrix)
Return a new array that formed by the bitwise complement of each element in the input matrix (~matrix[i][j]). |
static int[][] |
bitwiseOr(int[][] matrix,
int z)
Return a new matrix that is the formed by bitwise ORing z with each element of the input matrix (matrix[i][j] | z). |
static int[][] |
bitwiseOr(int[][] matrix1,
int[][] matrix2)
Return a new array that is the element-by-element bitwise OR of the two input matrices (matrix1[i][j] | matrix2[i][j]). |
static int[][] |
bitwiseXor(int[][] matrix,
int z)
Return a new matrix that is the formed by bitwise XORing z with each element of the input matrix (matrix[i][j] ^ z). |
static int[][] |
bitwiseXor(int[][] matrix1,
int[][] matrix2)
Return a new array that is the element-by-element bitwise XOR of the two input matrices (matrix1[i][j] & matrix2[i][j]). |
static int[][] |
crop(int[][] matrix,
int rowStart,
int colStart,
int rowSpan,
int colSpan)
Return a new matrix that is a sub-matrix of the input matrix argument. |
static int[][] |
diag(int[] 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 int[][] |
divide(int[][] matrix,
int z)
Return a new matrix that is constructed from the argument by dividing the second argument to every element. |
static int[][] |
divideElements(int[][] matrix1,
int[][] matrix2)
Return a new matrix that is constructed by element by element division of the two matrix arguments. |
static int[] |
fromMatrixToArray(int[][] matrix)
Return a new array that is filled with the contents of the matrix. |
static int[] |
fromMatrixToArray(int[][] matrix,
int maxRow,
int maxCol)
Return a new array that is filled with the contents of the matrix. |
static int[][] |
identity(int dim)
Return an new identity matrix with the specified dimension. |
static int[][] |
identityMatrixInt(int dim)
Return an new identity matrix with the specified dimension. |
static void |
matrixCopy(int[][] srcMatrix,
int[][] destMatrix)
Replace the first matrix argument elements with the values of the second matrix argument. |
static void |
matrixCopy(int[][] srcMatrix,
int srcRowStart,
int srcColStart,
int[][] 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 int[][] |
modulo(int[][] matrix,
int z)
Return a new matrix that is constructed by computing the remainders between each element in the matrix and z. |
static int[][] |
modulo(int[][] matrix1,
int[][] matrix2)
Return a new matrix that is constructed by computing the remainders between each element in the first matrix argument and the corresponding element in the second matrix argument. |
static int[][] |
multiply(int[][] matrix,
int scaleFactor)
Return a new matrix that is constructed by multiplying the matrix by a scaleFactor. |
static int[] |
multiply(int[][] matrix,
int[] 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 int[][] |
multiply(int[][] matrix1,
int[][] matrix2)
Return a new matrix that is constructed from the argument by multiplying the first matrix by the second one. |
static int[] |
multiply(int[] array,
int[][] 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 int[][] |
multiplyElements(int[][] matrix1,
int[][] matrix2)
Return a new matrix that is constructed by element by element multiplication of the two matrix arguments. |
static int[][] |
negative(int[][] matrix)
Return a new matrix that is the additive inverse of the argument matrix. |
static int[][] |
shiftArithmetic(int[][] matrix,
int shiftAmount)
Return a new matrix that is constructed from the argument by arithmetically shifting the elements in the matrix by the second argument. |
static int[][] |
shiftLogical(int[][] matrix,
int shiftAmount)
Return a new matrix that is constructed from the argument by logically shifting the elements in the matrix by the second argument. |
static int[][] |
subtract(int[][] matrix1,
int[][] matrix2)
Return a new matrix that is constructed from the argument by subtracting the second matrix from the first one. |
static int |
sum(int[][] matrix)
Return the sum of the elements of a matrix. |
static Complex[][] |
toComplexMatrix(int[][] matrix)
Return a new matrix that is formed by converting the integers in the argument matrix to complex numbers. |
static double[][] |
toDoubleMatrix(int[][] matrix)
Return a new matrix that is formed by converting the ints in the argument matrix to doubles. |
static float[][] |
toFloatMatrix(int[][] matrix)
Return a new matrix that is formed by converting the ints in the argument matrix to floats. |
static long[][] |
toLongMatrix(int[][] matrix)
Return a new matrix that is formed by converting the ints in the argument matrix to longs. |
static int[][] |
toMatrixFromArray(int[] array,
int rows,
int cols)
Return a new matrix of ints that is initialized from a 1-D array. |
static java.lang.String |
toString(int[][] matrix)
Return a new String representing the matrix, formatted as in Java array initializers. |
static java.lang.String |
toString(int[][] 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 int |
trace(int[][] 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 int[][] |
transpose(int[][] matrix)
Return a new matrix that is constructed by transposing the input matrix. |
static boolean |
within(int[][] matrix1,
int[][] matrix2,
int distance)
Return true if the elements of the two matrices differ by no more than the specified distance. |
static boolean |
within(int[][] matrix1,
int[][] matrix2,
int[][] errorMatrix)
Return true if the elements of the two matrices differ by no more than the specified distances. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
private IntegerMatrixMath()
Method Detail |
---|
public static final int[][] add(int[][] matrix, int z)
matrix
- A matrix of ints.z
- The int number to add.
public static final int[][] add(int[][] matrix1, int[][] matrix2)
matrix1
- The first matrix of ints.matrix2
- The second matrix of ints.
public static final int[][] allocCopy(int[][] matrix)
matrix
- A matrix of ints.
public static final int[][] applyBinaryOperation(IntegerBinaryOperation op, int z, int[][] matrix)
public static final int[][] applyBinaryOperation(IntegerBinaryOperation op, int[][] matrix, int z)
public static final int[][] applyBinaryOperation(IntegerBinaryOperation op, int[][] matrix1, int[][] matrix2)
public static final int[][] applyUnaryOperation(IntegerUnaryOperation op, int[][] matrix)
public static final int[][] bitwiseAnd(int[][] matrix, int z)
public static final int[][] bitwiseAnd(int[][] matrix1, int[][] matrix2)
public static final int[][] bitwiseComplement(int[][] matrix)
public static final int[][] bitwiseOr(int[][] matrix, int z)
public static final int[][] bitwiseOr(int[][] matrix1, int[][] matrix2)
public static final int[][] bitwiseXor(int[][] matrix, int z)
public static final int[][] bitwiseXor(int[][] matrix1, int[][] matrix2)
public static final int[][] crop(int[][] matrix, int rowStart, int colStart, int rowSpan, int colSpan)
matrix
- A matrix of ints.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 int[][] diag(int[] array)
public static final int[][] divide(int[][] matrix, int z)
matrix
- A matrix of ints.z
- The int number to divide.
public static final int[][] divideElements(int[][] matrix1, int[][] matrix2)
public static final int[] fromMatrixToArray(int[][] matrix)
matrix
- A matrix of ints.
public static final int[] fromMatrixToArray(int[][] matrix, int maxRow, int maxCol)
matrix
- A matrix of ints.
public static final int[][] identity(int dim)
public static final int[][] identityMatrixInt(int dim)
public static final void matrixCopy(int[][] srcMatrix, int[][] destMatrix)
destMatrix
- A matrix of ints, used as the destination.srcMatrix
- A matrix of ints, used as the source.public static final void matrixCopy(int[][] srcMatrix, int srcRowStart, int srcColStart, int[][] destMatrix, int destRowStart, int destColStart, int rowSpan, int colSpan)
srcMatrix
- A matrix of ints, 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 ints, 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 int[][] modulo(int[][] matrix, int z)
public static final int[][] modulo(int[][] matrix1, int[][] matrix2)
public static final int[][] multiply(int[][] matrix, int scaleFactor)
public static final int[] multiply(int[][] matrix, int[] array)
public static final int[] multiply(int[] array, int[][] matrix)
public static final int[][] multiply(int[][] matrix1, int[][] 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 ints.matrix2
- The second matrix of ints.
multiplyElements(int[][], int[][])
public static final int[][] multiplyElements(int[][] matrix1, int[][] matrix2)
Note that this method does pointwise matrix multiplication.
See multiply(int[][], int[][])
for standard
matrix multiplication.
public static final int[][] negative(int[][] matrix)
public static final int[][] shiftArithmetic(int[][] matrix, int shiftAmount)
matrix
- A first matrix of ints.shiftAmount
- The amount to shift by, positive for left shift,
negative for right shift.
public static final int[][] shiftLogical(int[][] matrix, int shiftAmount)
matrix
- A first matrix of ints.shiftAmount
- The amount to shift by, positive for left shift,
negative for right shift.
public static final int[][] subtract(int[][] matrix1, int[][] matrix2)
public static final int sum(int[][] matrix)
public static final Complex[][] toComplexMatrix(int[][] matrix)
matrix
- A matrix of integers.
public static final double[][] toDoubleMatrix(int[][] matrix)
matrix
- An matrix of int.
public static final float[][] toFloatMatrix(int[][] matrix)
matrix
- An matrix of int.
public static final long[][] toLongMatrix(int[][] matrix)
matrix
- An matrix of int.
public static final int[][] toMatrixFromArray(int[] array, int rows, int cols)
array
- An array of ints.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(int[][] matrix)
public static final java.lang.String toString(int[][] 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 int trace(int[][] matrix)
public static final int[][] transpose(int[][] matrix)
public static final boolean within(int[][] matrix1, int[][] matrix2, int 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(int[][] matrix1, int[][] matrix2, int[][] 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, int[][] matrix1, int[][] matrix2)
caller
- A string representing the caller method name.matrix1
- A matrix of ints.matrix2
- A matrix of ints.protected static final int _checkSquare(java.lang.String caller, int[][] matrix)
caller
- A string representing the caller method name.matrix
- A matrix of ints.
protected static final int _columns(int[][] matrix)
matrix
- The matrix.
protected static final java.lang.String _dimensionString(int[][] matrix)
matrix
- The matrix that is to be described.
protected static final int _rows(int[][] matrix)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |