Class Decomposition<T extends MatrixMixin<T,?,?,?>>

java.lang.Object
org.flag4j.linalg.decompositions.Decomposition<T>
Type Parameters:
T - The type of matrix that this decomposition operates on.
Direct Known Subclasses:
Balancer, Cholesky, LU, Schur, SVD, UnitaryDecomposition

public abstract class Decomposition<T extends MatrixMixin<T,?,?,?>> extends Object

An abstract base class representing a matrix decomposition.

This class provides a foundation for various matrix decompositions, such as LU, QR, SVD, Schur, and Hessenburg decompositions. Implementing classes must define the decomposition process by overriding the decompose(MatrixMixin) method.

Usage:

A typical workflow using a decomposition class follows these steps:

  1. Instantiate a concrete implementation of a decomposition.
  2. Call decompose(MatrixMixin) to perform the decomposition and a specific matrix.
  3. Retrieve decomposition results via additional getter methods provided by the subclass.

State Management:

The class maintains an internal state flag, hasDecomposed, which tracks whether a matrix decomposition has been performed. This ensures that methods depending on the decomposition can verify its existence before proceeding. The ensureHasDecomposed() method is provided to enforce this check. Below is a minimal example usage of ensureHasDecomposed() for a LU decomposition.


 class RealLU extends Decomposition<Matrix> {
     Matrix L;
     Matrix U;
     // Other fields and constructors...

     @Override
     public RealLU decompose(Matrix a) {
         // LU implementation...
         super.hasDecomposed = true;
         return this;
     }

     public Matrix getL() {
         super.ensureHasDecomposed();
         return L;
     }

     public Matrix getU() {
         super.ensureHasDecomposed();
         return U;
     }
 }
 
  • Field Details

    • hasDecomposed

      protected boolean hasDecomposed
      Flag indicating if this instance has computed a decomposition.
      • If true then this instance has decomposed a matrix.
      • If false then this instance has not yet decomposed a matrix.
  • Constructor Details

    • Decomposition

      public Decomposition()
  • Method Details

    • decompose

      public abstract Decomposition<T> decompose(T src)
      Applies decomposition to the source matrix.
      Parameters:
      src - The source matrix to decompose.
      Returns:
      A reference to this decomposer.
    • ensureHasDecomposed

      protected void ensureHasDecomposed()

      Ensures that this instance has computed a decomposition.

      This is useful to ensure that a decomposition has been computed in a method that depends on the result of the decomposition.

      Throws:
      IllegalStateException - If hasDecomposed == False.