Class ReDeMatVecMultDispatcher
java.lang.Object
org.flag4j.linalg.ops.dispatch.BiTensorOpDispatcher<Matrix,Vector,Vector>
org.flag4j.linalg.ops.dispatch.ReDeMatVecMultDispatcher
A dispatcher that selects the most suitable matrix-vector multiplication kernel for a real dense matrix/vector pair.
This class implements a threshold- and shape-based decision tree to optimize performance for various matrix-vector multiplication scenarios (e.g., small matrices, square matrices, wide/tall matrices, etc.). It maintains a cache of recently used shape/kernels to further improve performance for repeated patterns.
Usage:
- Use
dispatch(Matrix, Vector)
to compute a matrix-vector product, 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, Vector)
is safe to call from multiple threads.
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.linalg.ops.dispatch.BiTensorOpDispatcher
DEFAULT_CACHE_SIZE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ReDeMatVecMultDispatcher
(int cacheSize) Creates a matrix multiplication dispatcher with the specifiedcacheSize
. -
Method Summary
Modifier and TypeMethodDescriptionstatic Vector
Dispatches the multiplication of two matrices to an appropriate implementation based on the shapes of the two matrices.protected BiFunction
<Matrix, Vector, Vector> Computes the appropriate function to use when computing the matrix multiplication between two matrices.static ReDeMatVecMultDispatcher
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_
-
Constructor Details
-
ReDeMatVecMultDispatcher
protected ReDeMatVecMultDispatcher(int cacheSize) Creates a matrix multiplication dispatcher with the specifiedcacheSize
.- Parameters:
cacheSize
- The size of the cache for this matrix multiplication dispatcher.
-
-
Method Details
-
validateShapes
Validates the shapes are valid for the operation.- Specified by:
validateShapes
in classBiTensorOpDispatcher<Matrix,
Vector, Vector> - 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,Vector, getFuncVector> (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,
Vector, Vector> - Parameters:
aShape
- Shape of the first matrix in the matrix-vector multiplication problem.bShape
- Shape of the vector in the matrix-vector multiplication problem.data1Length
- Full length of the data array within the first matrix.data2Length
- Full length of the data array within the vector.- Returns:
- The appropriate function to use when computing the matrix multiplication between two matrices.
-