Class Cm128DeMatVecMultDispatcher

java.lang.Object
org.flag4j.linalg.ops.dispatch.BiTensorOpDispatcher<CMatrix,CVector,CVector>
org.flag4j.linalg.ops.dispatch.Cm128DeMatVecMultDispatcher

public class Cm128DeMatVecMultDispatcher extends BiTensorOpDispatcher<CMatrix,CVector,CVector>

A dispatcher that selects the most suitable matrix-vector multiplication kernel for a complex 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 also maintains a cache of recently used shape/kernels to further improve performance for repeated multiplication patterns.

Usage:

  • Use dispatch(CMatrix, CVector) to compute the 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 Cm128DeMatMultDispatchConfigs, 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(CMatrix, CVector) is safe to call from multiple threads.
See Also:
  • Constructor Details

    • Cm128DeMatVecMultDispatcher

      protected Cm128DeMatVecMultDispatcher(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<CMatrix,CVector,CVector>
      Parameters:
      aShape - Shape of first tensor in the operation.
      bShape - Shape of second tensor in the operation.
    • getInstance

      public static Cm128DeMatVecMultDispatcher 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 CVector dispatch(CMatrix a, CVector 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<CMatrix,CVector,CVector> 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<CMatrix,CVector,CVector>
      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.