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

java.lang.Object
org.flag4j.linalg.decompositions.lu.LU<T>
Type Parameters:
T - Type of the matrix to decompose.
All Implemented Interfaces:
Decomposition<T>
Direct Known Subclasses:
ComplexLU, FieldLU, RealLU

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

This abstract class specifies methods for computing the LU decomposition of a matrix.

The LU decomposition, decomposes a matrix A into a unit lower triangular matrix L and an upper triangular matrix U such that A=LU.

If partial pivoting is used, the decomposition will also yield a permutation matrix P such that PA=LU.

If full pivoting is used, the decomposition will yield an additional permutation matrix Q such that PAQ=LU.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Simple enum containing pivoting options for pivoting in LU decomposition.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int[]
     
    protected T
    Storage for L and U matrices.
    protected int
     
    protected int
     
    Permutation matrix to store row swaps if partial pivoting is used.
    Flag indicating what pivoting to use.
    Permutation matrix to store column swaps if full pivoting is used.
    protected int[]
     
    protected final double
    Tolerance for determining if pivot value is to be considered zero in LU decomposition with no pivoting.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    LU(LU.Pivoting pivoting)
    Constructs a LU decomposer to decompose the specified matrix.
    protected
    LU(LU.Pivoting pivoting, double zeroPivotTol)
    Constructs a LU decomposer to decompose the specified matrix.
  • Method Summary

    Modifier and Type
    Method
    Description
    LU<T>
    decompose(T src)
    Applies LU decomposition to the source matrix using the pivoting specified in the constructor.
    protected abstract void
    Computes the LU decomposition using full/rook pivoting (i.e. row and column swapping).
    abstract T
    Gets the unit lower triangular matrix of the decomposition.
    Gets the L and U matrices of the decomposition combined in a single matrix.
    int
    Gets the number of column swaps used in the last decomposition.
    int
    Gets the number of row swaps used in the last decomposition.
    Gets the row permutation matrix of the decomposition.
    Gets the column permutation matrix of the decomposition.
    abstract T
    Gets the upper triangular matrix of the decomposition.
    protected abstract void
    initLU(T src)
    Initializes the LU matrix by copying the source matrix to decompose.
    protected abstract void
    Computes the LU decomposition using no pivoting (i.e. rows and columns are not swapped).
    protected abstract void
    Computes the LU decomposition using partial pivoting (i.e. row swapping).
    protected void
    swapCols(int colIdx1, int colIdx2)
    Tracks the swapping of two columns during gaussian elimination with full pivoting.
    protected void
    swapRows(int rowIdx1, int rowIdx2)
    Tracks the swapping of two rows during gaussian elimination with partial or full pivoting.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • pivotFlag

      public final LU.Pivoting pivotFlag
      Flag indicating what pivoting to use.
    • zeroPivotTol

      protected final double zeroPivotTol
      Tolerance for determining if pivot value is to be considered zero in LU decomposition with no pivoting.
    • LU

      protected T extends MatrixMixin<T,?,?,?> LU
      Storage for L and U matrices. Stored in a single matrix
    • P

      protected PermutationMatrix P
      Permutation matrix to store row swaps if partial pivoting is used.
    • Q

      protected PermutationMatrix Q
      Permutation matrix to store column swaps if full pivoting is used.
    • numRowSwaps

      protected int numRowSwaps
    • numColSwaps

      protected int numColSwaps
    • rowSwaps

      protected int[] rowSwaps
    • colSwaps

      protected int[] colSwaps
  • Constructor Details

    • LU

      protected LU(LU.Pivoting pivoting)
      Constructs a LU decomposer to decompose the specified matrix.
      Parameters:
      pivoting - Pivoting to use. If pivoting is 2, full pivoting will be used. If pivoting is 1, partial pivoting will be used. If pivoting is any other value, no pivoting will be used.
    • LU

      protected LU(LU.Pivoting pivoting, double zeroPivotTol)
      Constructs a LU decomposer to decompose the specified matrix.
      Parameters:
      pivoting - Pivoting to use. If pivoting is 2, full pivoting will be used. If pivoting is 1, partial pivoting will be used. If pivoting is any other value, no pivoting will be used.
      zeroPivotTol - Tolerance for considering a pivot to be zero. If a pivot is less than the tolerance in absolute value, then it will be considered zero.
  • Method Details

    • decompose

      public LU<T> decompose(T src)
      Applies LU decomposition to the source matrix using the pivoting specified in the constructor.
      Specified by:
      decompose in interface Decomposition<T extends MatrixMixin<T,?,?,?>>
      Parameters:
      src - The source matrix to decompose. Not modified.
      Returns:
      A reference to this decomposer.
    • initLU

      protected abstract void initLU(T src)
      Initializes the LU matrix by copying the source matrix to decompose.
      Parameters:
      src - Source matrix to decompose.
    • noPivot

      protected abstract void noPivot()
      Computes the LU decomposition using no pivoting (i.e. rows and columns are not swapped).
    • partialPivot

      protected abstract void partialPivot()
      Computes the LU decomposition using partial pivoting (i.e. row swapping).
    • fullPivot

      protected abstract void fullPivot()
      Computes the LU decomposition using full/rook pivoting (i.e. row and column swapping).
    • getLU

      public T getLU()
      Gets the L and U matrices of the decomposition combined in a single matrix.
      Returns:
      The L and U matrices of the decomposition stored together in a single matrix. The diagonal of L is all ones and is not stored allowing the diagonal of U to be stored along the diagonal of the combined matrix.
    • getL

      public abstract T getL()
      Gets the unit lower triangular matrix of the decomposition.
      Returns:
      The unit lower triangular matrix of the decomposition.
    • getU

      public abstract T getU()
      Gets the upper triangular matrix of the decomposition.
      Returns:
      The upper triangular matrix of the decomposition.
    • getP

      public PermutationMatrix getP()
      Gets the row permutation matrix of the decomposition.
      Returns:
      The row permutation matrix of the decomposition. If no pivoting was used, null will be returned.
    • getQ

      public PermutationMatrix getQ()
      Gets the column permutation matrix of the decomposition.
      Returns:
      The column permutation matrix of the decomposition. If full pivoting was not used, null will be returned.
    • getNumRowSwaps

      public int getNumRowSwaps()
      Gets the number of row swaps used in the last decomposition.
      Returns:
      The number of row swaps used in the last decomposition.
    • getNumColSwaps

      public int getNumColSwaps()
      Gets the number of column swaps used in the last decomposition.
      Returns:
      The number of column swaps used in the last decomposition.
    • swapRows

      protected void swapRows(int rowIdx1, int rowIdx2)
      Tracks the swapping of two rows during gaussian elimination with partial or full pivoting.
      Parameters:
      rowIdx1 - First row index in swap.
      rowIdx2 - Second row index in swap.
    • swapCols

      protected void swapCols(int colIdx1, int colIdx2)
      Tracks the swapping of two columns during gaussian elimination with full pivoting.
      Parameters:
      colIdx1 - First column index in swap.
      colIdx2 - Second column index in swap.