Package org.flag4j.operations
Class RealDenseMatrixMultiplyDispatcher
java.lang.Object
org.flag4j.operations.RealDenseMatrixMultiplyDispatcher
Singleton class which stores a map of all viable real dense matrix multiply algorithms and uses that map to dispatch
a real dense matrix multiply problem to the appropriate algorithm.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static enum
Simple enum class containing all possible choices of real dense matrix multiply algorithms. -
Field Summary
Modifier and TypeFieldDescriptionlookup table for all real dense matrix multiply algorithms.private 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 RealDenseMatrixMultiplyDispatcher
Singleton instance of this class.private static final double
Ration measuring squareness. -
Constructor Summary
ModifierConstructorDescriptionprivate
Creates an instance containing a map of all viable real dense matrix multiply algorithms. -
Method Summary
Modifier and TypeMethodDescriptionstatic double[]
Dispatches a matrix multiply problem to the appropriate algorithm based on the size of the matrices.static double[]
Dispatches a matrix multiply problem to the appropriate algorithm based on the size of the matrices.static double[]
dispatchTranspose
(Matrix A, Matrix B) Dispatches a matrix multiply-transpose problem equivalent to A.mult(B.T()) to the appropriate algorithm based on the size of the matrices.Gets the singleton instance of this class.private static double
Computes the squareness ratio of a matrix.(package private) static RealDenseMatrixMultiplyDispatcher.AlgorithmNames
selectAlgorithm
(Shape shape1, Shape shape2) Dynamically chooses matrix multiply algorithm based on the shapes of the two matrices to multiply.(package private) static RealDenseMatrixMultiplyDispatcher.AlgorithmNames
selectAlgorithmTranspose
(Shape shape) Selects the matrix multiplication-transpose algorithm to use based on the size of the first matrix.
-
Field Details
-
singletonInstance
Singleton instance of this class. -
algorithmMap
private final Map<RealDenseMatrixMultiplyDispatcher.AlgorithmNames,RealDenseTensorBinaryOperation> algorithmMaplookup table for all real dense matrix multiply algorithms. -
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
-
RealDenseMatrixMultiplyDispatcher
private RealDenseMatrixMultiplyDispatcher()Creates an instance containing a map of all viable real dense matrix multiply algorithms.
-
-
Method Details
-
getInstance
Gets the singleton instance of this class. If this class has not been instanced, a new instance will be created.- Returns:
- The singleton instance of this class.
-
dispatch
-
dispatch
Dispatches a matrix multiply problem to the appropriate algorithm based on the size of the matrices.- 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.
-
dispatchTranspose
Dispatches a matrix multiply-transpose problem equivalent to A.mult(B.T()) to the appropriate algorithm based on the size of the matrices.- Parameters:
A
- First matrix in the multiplication.B
- Second matrix in the multiplication and the matrix to transpose.- Returns:
- The matrix multiply-transpose result of
A
andB
.
-
selectAlgorithm
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.
-
selectAlgorithmTranspose
Selects the matrix multiplication-transpose algorithm to use based on the size of the first matrix.- Parameters:
shape
- Shape of the first matrix.- Returns:
- The algorithm to use to compute the matrix multiplication-transpose.
-
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.
-