Class QrHelperFunctions_CDRM
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic float
computeRowMax
(CMatrixRMaj A, int row, int col0, int col1) Finds the magnitude of the largest element in the rowstatic float
computeTauGammaAndDivide
(int start, int stop, float[] x, float max, Complex_F32 tau) Performs the following operations:static void
divideElements
(int j, int numRows, float[] u, int startU, float realA, float imagA) Performs the following operation:
u[(startU+j):(startU+numRows)] /= A
were u and A are a complexstatic float
extractColumnAndMax
(CMatrixRMaj A, int row0, int row1, int col, float[] 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
(CMatrixRMaj A, int row0, int row1, int col, float[] u, int offsetU) Extracts a house holder vector from the column of A and stores it in ustatic void
extractHouseholderRow
(CMatrixRMaj A, int row, int col0, int col1, float[] u, int offsetU) Extracts a house holder vector from the rows of A and stores it in ustatic float
findMax
(float[] u, int startU, int length) Returns the maximum magnitude of the complex numbersstatic void
rank1UpdateMultL
(CMatrixRMaj A, float[] u, int offsetU, float 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
(CMatrixRMaj A, float[] u, int offsetU, float gamma, int colA0, int w0, int w1, float[] _temp) Performs a rank-1 update operation on the submatrix specified by w with the multiply on the right.
A = (I - γ*u*uH)*A
-
Constructor Details
-
QrHelperFunctions_CDRM
public QrHelperFunctions_CDRM()
-
-
Method Details
-
findMax
public static float findMax(float[] u, int startU, int length) Returns the maximum magnitude of the complex numbers- Parameters:
u
- Array of complex numbersstartU
- first index to consider in ulength
- Number of complex numebrs to consider- Returns:
- magnitude
-
divideElements
public static void divideElements(int j, int numRows, float[] u, int startU, float realA, float imagA) Performs the following operation:
u[(startU+j):(startU+numRows)] /= A
were u and A are a complex -
computeTauGammaAndDivide
public static float computeTauGammaAndDivide(int start, int stop, float[] x, float max, Complex_F32 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
- Arraymax
- Max value in 'u' that is used to normalize it.tau
- Storage for tau- Returns:
- Returns gamma
-
rank1UpdateMultR
public static void rank1UpdateMultR(CMatrixRMaj A, float[] u, int offsetU, float gamma, int colA0, int w0, int w1, float[] _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
- matrixu
- vectoroffsetU
- offset added to w0 when indexing u. Multiplied by 2 since complex.gamma
- real component of gammacolA0
- first column in A sub-matrix.w0
- first index in sub-array in u and row sub-matrix in Aw1
- 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(CMatrixRMaj A, float[] u, int offsetU, float 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(CMatrixRMaj A, int row0, int row1, int col, float[] 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 trianglerow0
- first row in A (implicitly assumed to be r + i0)row1
- last row + 1 in Acol
- Column in Au
- Output array storageoffsetU
- first index in U
-
extractHouseholderRow
public static void extractHouseholderRow(CMatrixRMaj A, int row, int col0, int col1, float[] 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 trianglerow
- Row in Acol0
- first row in A (implicitly assumed to be r + i0)col1
- last row +1 in Au
- Output array storageoffsetU
- first index in U
-
extractColumnAndMax
public static float extractColumnAndMax(CMatrixRMaj A, int row0, int row1, int col, float[] 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 matrixrow0
- First row in A to be copiedrow1
- Last row in A + 1 to be copiedcol
- Column in Au
- Output array storageoffsetU
- first index in U- Returns:
- magnitude of largest element
-
computeRowMax
Finds the magnitude of the largest element in the row- Parameters:
A
- Complex matrixrow
- Row in Acol0
- First column in A to be copiedcol1
- Last column in A + 1 to be copied- Returns:
- magnitude of largest element
-