Class QrHelperFunctions_ZDRM

java.lang.Object
org.ejml.dense.row.decompose.qr.QrHelperFunctions_ZDRM

public class QrHelperFunctions_ZDRM extends Object

Contains different functions that are useful for computing the QR decomposition of a matrix.

Two different families of functions are provided for help in computing reflectors. Internally both of these functions switch between normalization by division or multiplication. Multiplication is most often significantly faster than division (2 or 3 times) but produces less accurate results on very small numbers. It checks to see if round off error is significant and decides which one it should do.

Tests were done using the stability benchmark in jmatbench and there doesn't seem to be any advantage to always dividing by the max instead of checking and deciding. The most noticeable difference between the two methods is with very small numbers.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    computeRowMax(ZMatrixRMaj A, int row, int col0, int col1)
    Finds the magnitude of the largest element in the row
    static double
    computeTauGammaAndDivide(int start, int stop, double[] x, double max, Complex_F64 tau)
    Performs the following operations:
    static void
    divideElements(int j, int numRows, double[] u, int startU, double realA, double imagA)
    Performs the following operation:
    u[(startU+j):(startU+numRows)] /= A
    were u and A are a complex
    static double
    extractColumnAndMax(ZMatrixRMaj A, int row0, int row1, int col, double[] u, int offsetU)
    Extracts the column of A and copies it into u while computing the magnitude of the largest element and returning it.
    static void
    extractHouseholderColumn(ZMatrixRMaj A, int row0, int row1, int col, double[] u, int offsetU)
    Extracts a house holder vector from the column of A and stores it in u
    static void
    extractHouseholderRow(ZMatrixRMaj A, int row, int col0, int col1, double[] u, int offsetU)
    Extracts a house holder vector from the rows of A and stores it in u
    static double
    findMax(double[] u, int startU, int length)
    Returns the maximum magnitude of the complex numbers
    static void
    rank1UpdateMultL(ZMatrixRMaj A, double[] u, int offsetU, double gammaR, int colA0, int w0, int w1)
    Performs a rank-1 update operation on the submatrix specified by w with the multiply on the left.

    A = A(I - γ*u*uH)
    static void
    rank1UpdateMultR(ZMatrixRMaj A, double[] u, int offsetU, double gamma, int colA0, int w0, int w1, double[] _temp)
    Performs a rank-1 update operation on the submatrix specified by w with the multiply on the right.

    A = (I - γ*u*uH)*A

    Methods inherited from class java.lang.Object

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

    • QrHelperFunctions_ZDRM

      public QrHelperFunctions_ZDRM()
  • Method Details

    • findMax

      public static double findMax(double[] u, int startU, int length)
      Returns the maximum magnitude of the complex numbers
      Parameters:
      u - Array of complex numbers
      startU - first index to consider in u
      length - Number of complex numebrs to consider
      Returns:
      magnitude
    • divideElements

      public static void divideElements(int j, int numRows, double[] u, int startU, double realA, double imagA)
      Performs the following operation:
      u[(startU+j):(startU+numRows)] /= A
      were u and A are a complex
    • computeTauGammaAndDivide

      public static double computeTauGammaAndDivide(int start, int stop, double[] x, double max, Complex_F64 tau)
      Performs the following operations:
       x = x / max
       tau = x0*|x|/|xo|   adjust sign to avoid cancellation
       u = x; u0 = x0 + tau; u = u/u0  (x is not divided by x0)
       gamma = 2/|u|^2
       
      Note that u is not explicitly computed here.
      Parameters:
      start - Element in 'u' that it starts at.
      stop - Element in 'u' that it stops at.
      x - Array
      max - Max value in 'u' that is used to normalize it.
      tau - Storage for tau
      Returns:
      Returns gamma
    • rank1UpdateMultR

      public static void rank1UpdateMultR(ZMatrixRMaj A, double[] u, int offsetU, double gamma, int colA0, int w0, int w1, double[] _temp)

      Performs a rank-1 update operation on the submatrix specified by w with the multiply on the right.

      A = (I - γ*u*uH)*A

      Parameters:
      A - matrix
      u - vector
      offsetU - offset added to w0 when indexing u. Multiplied by 2 since complex.
      gamma - real component of gamma
      colA0 - first column in A sub-matrix.
      w0 - first index in sub-array in u and row sub-matrix in A
      w1 - last index + 1 in sub-array in u and row sub-matrix in A
      _temp - temporary storage. Same size as u.
    • rank1UpdateMultL

      public static void rank1UpdateMultL(ZMatrixRMaj A, double[] u, int offsetU, double gammaR, int colA0, int w0, int w1)

      Performs a rank-1 update operation on the submatrix specified by w with the multiply on the left.

      A = A(I - γ*u*uH)

      The order that matrix multiplies are performed has been carefully selected to minimize the number of operations.

      Before this can become a truly generic operation the submatrix specification needs to be made more generic.

    • extractHouseholderColumn

      public static void extractHouseholderColumn(ZMatrixRMaj A, int row0, int row1, int col, double[] u, int offsetU)
      Extracts a house holder vector from the column of A and stores it in u
      Parameters:
      A - Complex matrix with householder vectors stored in the lower left triangle
      row0 - first row in A (implicitly assumed to be r + i0)
      row1 - last row + 1 in A
      col - Column in A
      u - Output array storage
      offsetU - first index in U
    • extractHouseholderRow

      public static void extractHouseholderRow(ZMatrixRMaj A, int row, int col0, int col1, double[] u, int offsetU)
      Extracts a house holder vector from the rows of A and stores it in u
      Parameters:
      A - Complex matrix with householder vectors stored in the upper right triangle
      row - Row in A
      col0 - first row in A (implicitly assumed to be r + i0)
      col1 - last row +1 in A
      u - Output array storage
      offsetU - first index in U
    • extractColumnAndMax

      public static double extractColumnAndMax(ZMatrixRMaj A, int row0, int row1, int col, double[] u, int offsetU)
      Extracts the column of A and copies it into u while computing the magnitude of the largest element and returning it.
       u[ (offsetU+row0+i)*2    ] = A.getReal(row0+i,col)
       u[ (offsetU+row0+i)*2 + 1] = A.getImag(row0+i,col)
       
      Parameters:
      A - Complex matrix
      row0 - First row in A to be copied
      row1 - Last row in A + 1 to be copied
      col - Column in A
      u - Output array storage
      offsetU - first index in U
      Returns:
      magnitude of largest element
    • computeRowMax

      public static double computeRowMax(ZMatrixRMaj A, int row, int col0, int col1)
      Finds the magnitude of the largest element in the row
      Parameters:
      A - Complex matrix
      row - Row in A
      col0 - First column in A to be copied
      col1 - Last column in A + 1 to be copied
      Returns:
      magnitude of largest element