Class ReDeMatVecMultDispatcher

java.lang.Object
org.flag4j.linalg.ops.dispatch.BiTensorOpDispatcher<Matrix,Vector,Vector>
org.flag4j.linalg.ops.dispatch.ReDeMatVecMultDispatcher

public final class ReDeMatVecMultDispatcher extends BiTensorOpDispatcher<Matrix,Vector,Vector>

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:
  • Constructor Details

    • ReDeMatVecMultDispatcher

      protected ReDeMatVecMultDispatcher(int cacheSize)
      Creates a matrix multiplication dispatcher with the specified cacheSize.
      Parameters:
      cacheSize - The size of the cache for this matrix multiplication dispatcher.
  • Method Details

    • validateShapes

      protected void validateShapes(Shape aShape, Shape bShape)
      Validates the shapes are valid for the operation.
      Specified by:
      validateShapes in class BiTensorOpDispatcher<Matrix,Vector,Vector>
      Parameters:
      aShape - Shape of first tensor in the operation.
      bShape - Shape of second tensor in the operation.
    • getInstance

      public static ReDeMatVecMultDispatcher 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

      public static Vector dispatch(Matrix a, Vector b)
      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 and b.
    • getFunc

      protected BiFunction<Matrix,Vector,Vector> getFunc(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 class BiTensorOpDispatcher<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.