Class ReDeMatMultDispatcher
java.lang.Object
org.flag4j.linalg.ops.dispatch.BiTensorOpDispatcher<Matrix,Matrix,Matrix>
org.flag4j.linalg.ops.dispatch.ReDeMatMultDispatcher
A dispatcher that selects the most suitable matrix multiplication kernel for two real dense matrices.
This class implements a threshold- and shape-based decision tree to optimize performance for various matrix multiplication scenarios (e.g., small matrices, square matrices, wide/tall matrices, matrix-vector products, etc.). It maintains a cache of recently used shape/kernels to further improve performance for repeated multiplication patterns.
Usage:
- Use
dispatch(Matrix, Matrix)
to multiply two matrices, dynamically choosing the best kernel. - This class is a singleton; call
getInstance()
to retrieve the instance if you need direct access to the underlying dispatcher.
Configuration:
The dispatcher reads various thresholds (e.g.,ASPECT_THRESH
, SML_THRESH
, etc.)
from ReDeMatMultDispatchConfigs
, allowing external tuning without modifying code.
Thread Safety:
- The dispatcher itself does not maintain mutable state beyond a cached kernel lookup, which is also thread-safe.
dispatch(Matrix, Matrix)
is safe to call from multiple threads.
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.linalg.ops.dispatch.BiTensorOpDispatcher
DEFAULT_CACHE_SIZE
-
Method Summary
Modifier and TypeMethodDescriptionstatic Matrix
Dispatches the multiplication of two matrices to an appropriate implementation based on the shapes of the two matrices.protected BiFunction
<Matrix, Matrix, Matrix> Computes the appropriate function to use when computing the matrix multiplication between two matrices.static ReDeMatMultDispatcher
Gets the singleton instance of this class.protected void
validateShapes
(Shape aShape, Shape bShape) Validates the shapes are valid for the operation.Methods inherited from class org.flag4j.linalg.ops.dispatch.BiTensorOpDispatcher
dispatch_
-
Method Details
-
validateShapes
Validates the shapes are valid for the operation.- Specified by:
validateShapes
in classBiTensorOpDispatcher<Matrix,
Matrix, Matrix> - Parameters:
aShape
- Shape of first tensor in the operation.bShape
- Shape of second tensor in the operation.
-
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
Dispatches the multiplication of two matrices to an appropriate implementation based on the shapes of the two matrices.- Parameters:
a
- Left matrix in the matrix multiplication.b
- Right matrix in the matrix multiplication.- Returns:
- The matrix product of
a
andb
.
-
getFunc
protected BiFunction<Matrix,Matrix, getFuncMatrix> (Shape aShape, Shape bShape, int data1Length, int data2Length) Computes the appropriate function to use when computing the matrix multiplication between two matrices.- Specified by:
getFunc
in classBiTensorOpDispatcher<Matrix,
Matrix, Matrix> - Parameters:
aShape
- Shape of the first matrix in the matrix multiplication problem.bShape
- Shape of the second matrix in the matrix multiplication problem.data1Length
- Full length of the data array within the first matrix.data2Length
- Full length of the data array within the second matrix.- Returns:
- The appropriate function to use when computing the matrix multiplication between two matrices.
-