Package org.flag4j.operations
Class MatrixMultiplyDispatcher
java.lang.Object
org.flag4j.operations.MatrixMultiplyDispatcher
Dispatches matrix multiplication to the appropriate algorithm based on the size of the matrices to be multiplied.
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static enum
Simple enum class containing all possible choices of matrix multiply algorithms. -
Field Summary
Modifier and TypeFieldDescriptionprivate static final int
Threshold for matrices to use the concurrent ikj algorithm.private static final int
Threshold for small matrices which should be multiplied using the standard ikj algorithm.private static final double
Ration measuring squareness. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionchooseAlgorithmComplex
(Shape shape1, Shape shape2) Dynamically chooses matrix multiply algorithm based on the shapes of the two matrices to multiply.Dynamically chooses the matrix multiplication-transpose algorithm to used based on the shape of the first matrix.Dynamically chooses matrix-vector multiply algorithm based on the shapes of the matrix to multiply.chooseAlgorithmRealComplex
(Shape shape1, Shape shape2) Dynamically chooses matrix multiply algorithm based on the shapes of the two matrices to multiply.Dynamically chooses the matrix multiplication-transpose algorithm to used based on the shape of the first matrix.Dynamically chooses matrix-vector multiply algorithm based on the shapes of the matrix to multiply.chooseAlgorithmRealVector
(Shape shape) Dynamically chooses matrix-vector multiply algorithm based on the shapes of the matrix to multiply.static CNumber[]
Dispatches a matrix multiplication problem to the appropriate algorithm based on the size.static CNumber[]
Dynamically chooses the appropriate matrix-vector multiplication algorithm based on the shapes of the matrix and vector.static CNumber[]
Dispatches a matrix multiplication problem to the appropriate algorithm based on the size.static CNumber[]
Dynamically chooses the appropriate matrix-vector multiplication algorithm based on the shapes of the matrix and vector.static CNumber[]
Dispatches a matrix multiplication problem to the appropriate algorithm based on the size.static CNumber[]
Dynamically chooses the appropriate matrix-vector multiplication algorithm based on the shapes of the matrix and vector.static double[]
Dynamically chooses the appropriate matrix-vector multiplication algorithm based on the shapes of the matrix and vector.static CNumber[]
Dispatches a matrix multiplication problem to the appropriate algorithm based on the size.static CNumber[]
dispatchTranspose
(CMatrix A, CMatrix B) Dispatches a matrix multiplication-transpose problem to the appropriate algorithm based on the size.static CNumber[]
dispatchTranspose
(CMatrix A, Matrix B) Dispatches a matrix multiplication-transpose problem to the appropriate algorithm based on the size.static CNumber[]
dispatchTranspose
(Matrix A, CMatrix B) Dispatches a matrix multiplication-transpose problem to the appropriate algorithm based on the size.private static double
Computes the squareness ratio of a matrix.
-
Field Details
-
SQUARENESS_RATIO
private static final double SQUARENESS_RATIORation measuring squareness. the closer to one, the more square the matrix is.- See Also:
-
SEQUENTIAL_SWAPPED_THRESHOLD
private static final int SEQUENTIAL_SWAPPED_THRESHOLDThreshold for small matrices which should be multiplied using the standard ikj algorithm.- See Also:
-
CONCURRENT_SWAPPED_THRESHOLD
private static final int CONCURRENT_SWAPPED_THRESHOLDThreshold for matrices to use the concurrent ikj algorithm.- See Also:
-
-
Constructor Details
-
MatrixMultiplyDispatcher
private MatrixMultiplyDispatcher()
-
-
Method Details
-
dispatch
-
dispatch
-
dispatch
-
dispatch
-
dispatch
Dispatches a matrix multiplication problem to the appropriate algorithm based on the size.- Parameters:
A
- First matrix in matrix multiplication.B
- Second matrix in matrix multiplication.- Returns:
- The result of the matrix multiplication.
- Throws:
IllegalArgumentException
- If the shapes of the two matrices are not conducive to matrix multiplication.
-
dispatch
Dispatches a matrix multiplication problem to the appropriate algorithm based on the size.- Parameters:
src1
- Entries of the first matrix.shape1
- Shape of the first matrix.src2
- Entries of the second matrix.shape2
- Shape of the second matrix.- Returns:
- The result of the matrix multiplication between the two matrices.
-
dispatch
Dispatches a matrix multiplication problem to the appropriate algorithm based on the size.- Parameters:
A
- First matrix in matrix multiplication.B
- Second matrix in matrix multiplication.- Returns:
- The result of the matrix multiplication.
- Throws:
IllegalArgumentException
- If the shapes of the two matrices are not conducive to matrix multiplication.
-
dispatch
Dispatches a matrix multiplication problem to the appropriate algorithm based on the size.- Parameters:
A
- First matrix in matrix multiplication.B
- Second matrix in matrix multiplication.- Returns:
- The result of the matrix multiplication.
- Throws:
IllegalArgumentException
- If the shapes of the two matrices are not conducive to matrix multiplication.
-
dispatchTranspose
Dispatches a matrix multiplication-transpose problem to the appropriate algorithm based on the size.- Parameters:
A
- First matrix in matrix multiplication.B
- Second matrix in matrix multiplication and the matrix to transpose.- Returns:
- The result of the matrix multiplication-transpose.
- Throws:
IllegalArgumentException
- If the shapes of the two matrices are not conducive to matrix multiplication-transpose.
-
dispatchTranspose
Dispatches a matrix multiplication-transpose problem to the appropriate algorithm based on the size.- Parameters:
A
- First matrix in matrix multiplication.B
- Second matrix in matrix multiplication and the matrix to transpose.- Returns:
- The result of the matrix multiplication-transpose.
- Throws:
IllegalArgumentException
- If the shapes of the two matrices are not conducive to matrix multiplication-transpose.
-
dispatchTranspose
Dispatches a matrix multiplication-transpose problem to the appropriate algorithm based on the size.- Parameters:
A
- First matrix in matrix multiplication.B
- Second matrix in matrix multiplication and the matrix to transpose.- Returns:
- The result of the matrix multiplication-transpose.
- Throws:
IllegalArgumentException
- If the shapes of the two matrices are not conducive to matrix multiplication-transpose.
-
chooseAlgorithmRealComplexTranspose
public static MatrixMultiplyDispatcher.AlgorithmName chooseAlgorithmRealComplexTranspose(Shape shape) Dynamically chooses the matrix multiplication-transpose algorithm to used based on the shape of the first matrix.- Parameters:
shape
- Shape of the first matrix.
-
chooseAlgorithmComplexTranspose
Dynamically chooses the matrix multiplication-transpose algorithm to used based on the shape of the first matrix.- Parameters:
shape
- Shape of the first matrix.
-
chooseAlgorithmRealVector
Dynamically chooses matrix-vector multiply algorithm based on the shapes of the matrix to multiply.- Parameters:
shape
- The shape of the matrix.- Returns:
- The algorithm to use in the matrix multiplication.
-
chooseAlgorithmComplex
public static MatrixMultiplyDispatcher.AlgorithmName chooseAlgorithmComplex(Shape shape1, Shape shape2) Dynamically chooses matrix multiply algorithm based on the shapes of the two matrices to multiply.- Parameters:
shape1
- The shape of the first matrix.shape2
- The shape fo the second matrix.- Returns:
- The algorithm to use in the matrix multiplication.
-
chooseAlgorithmComplexVector
Dynamically chooses matrix-vector multiply algorithm based on the shapes of the matrix to multiply.- Parameters:
shape
- The shape of the matrix.- Returns:
- The algorithm to use in the matrix multiplication.
-
chooseAlgorithmRealComplex
public static MatrixMultiplyDispatcher.AlgorithmName chooseAlgorithmRealComplex(Shape shape1, Shape shape2) Dynamically chooses matrix multiply algorithm based on the shapes of the two matrices to multiply.- Parameters:
shape1
- The shape of the first matrix.shape2
- The shape fo the second matrix.- Returns:
- The algorithm to use in the matrix multiplication.
-
chooseAlgorithmRealComplexVector
Dynamically chooses matrix-vector multiply algorithm based on the shapes of the matrix to multiply.- Parameters:
shape
- The shape of the matrix.- Returns:
- The algorithm to use in the matrix multiplication.
-
getRatio
Computes the squareness ratio of a matrix. This is a value between 0 and 1 with 1 being perfectly square and 0 being a row/column vector.- Parameters:
shape
- Shape of the matrix to compute the squareness ratio of.- Returns:
- The squareness ratio for the specified shape.
-