public class QrHelperFunctions_CDRM
extends java.lang.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 and Description |
---|
QrHelperFunctions_CDRM() |
Modifier and Type | Method and Description |
---|---|
static float |
computeRowMax(org.ejml.data.CMatrixRMaj A,
int row,
int col0,
int col1)
Finds the magnitude of the largest element in the row
|
static float |
computeTauGammaAndDivide(int start,
int stop,
float[] x,
float max,
org.ejml.data.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 complex |
static float |
extractColumnAndMax(org.ejml.data.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(org.ejml.data.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
|
static void |
extractHouseholderRow(org.ejml.data.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
|
static float |
findMax(float[] u,
int startU,
int length)
Returns the maximum magnitude of the complex numbers
|
static void |
rank1UpdateMultL(org.ejml.data.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(org.ejml.data.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 |
public static float findMax(float[] u, int startU, int length)
u
- Array of complex numbersstartU
- first index to consider in ulength
- Number of complex numebrs to considerpublic static void divideElements(int j, int numRows, float[] u, int startU, float realA, float imagA)
public static float computeTauGammaAndDivide(int start, int stop, float[] x, float max, org.ejml.data.Complex_F32 tau)
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|^2Note that u is not explicitly computed here.
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 taupublic static void rank1UpdateMultR(org.ejml.data.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
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.public static void rank1UpdateMultL(org.ejml.data.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.
public static void extractHouseholderColumn(org.ejml.data.CMatrixRMaj A, int row0, int row1, int col, float[] u, int offsetU)
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 Upublic static void extractHouseholderRow(org.ejml.data.CMatrixRMaj A, int row, int col0, int col1, float[] u, int offsetU)
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 Upublic static float extractColumnAndMax(org.ejml.data.CMatrixRMaj A, int row0, int row1, int col, float[] u, int offsetU)
u[ (offsetU+row0+i)*2 ] = A.getReal(row0+i,col) u[ (offsetU+row0+i)*2 + 1] = A.getImag(row0+i,col)
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 Upublic static float computeRowMax(org.ejml.data.CMatrixRMaj A, int row, int col0, int col1)
A
- Complex matrixrow
- Row in Acol0
- First column in A to be copiedcol1
- Last column in A + 1 to be copied