typedef enum _vsip_qrd_qopt { VSIP_QRD_NOSAVEQ = 0, // Do not save Q VSIP_QRD_SAVEQ = 1, // Save full Q VSIP_QRD_SAVEQ1 = 2 // Save skinny Q } vsip_qrd_qopt; vsip_qr_f* vsip_qrd_create_f(vsip_length m, vsip_length n, vsip_qrd_qopt qopt); vsip_cqr_f* vsip_cqrd_create_f(vsip_length m, vsip_length n, vsip_qrd_qopt qopt);
This function creates a QR decomposition object that can be used to compute the QR factorization of an
matrix. The QR
decomposition expresses a matrix
as the product of an orthogonal matrix
and an upper triangular matrix
, such that
.
The vsip_qrd_qopt parameter allows you to specify how the orthogonal matrix
should be stored.
vsip_length m: Number of rows in the matrix to be decomposed.
vsip_length n: Number of columns in the matrix to be decomposed.
vsip_qrd_qopt qopt: Option specifying how the
matrix should be saved:
VSIP_QRD_NOSAVEQ: Don’t save
(only compute
)
VSIP_QRD_SAVEQ1: Save essential parts of
(more memory efficient)
VSIP_QRD_SAVEQ: Save full
matrix
On success, returns a pointer to the newly created QR decomposition object.
On error (e.g., if memory allocation fails), returns NULL.
vsip_qr_f *qrd; vsip_length m = 100, n = 50; // Create a QR decomposition object // Using SAVEQ2 as a good compromise between memory and functionality qrd = vsip_qrd_create_f(m, n, VSIP_QRD_SAVEQ2); if (qrd == NULL) { fprintf(stderr, "Failed to create QR decomposition object\n"); return; }
The QR decomposition object must be destroyed with vsip_dqrd_destroy_p when no longer needed.
The choice of qopt affects both memory usage and the operations that can be performed with the decomposition:
VSIP_QRD_SAVEQ allows full access to
but uses more memory
VSIP_QRD_SAVEQ1 is a good compromise for most applications
VSIP_QRD_NOSAVEQ is most memory efficient but only allows operations with 
For square matrices (
), the QR decomposition can be used to compute determinants and inverses.
For tall matrices (
), the decomposition is useful for least squares problems.
This function allocates internal storage for the decomposition, which is freed when the QR object is destroyed.
For repeated decompositions of matrices with the same dimensions, you can reuse the QR object by calling vsip_dqrd_p multiple times with the same object.