# QR decomposition of a Matrix

riscv_status riscv_mat_qr_f16(const riscv_matrix_instance_f16 *pSrc, const float16_t threshold, riscv_matrix_instance_f16 *pOutR, riscv_matrix_instance_f16 *pOutQ, float16_t *pOutTau, float16_t *pTmpA, float16_t *pTmpB)
riscv_status riscv_mat_qr_f32(const riscv_matrix_instance_f32 *pSrc, const float32_t threshold, riscv_matrix_instance_f32 *pOutR, riscv_matrix_instance_f32 *pOutQ, float32_t *pOutTau, float32_t *pTmpA, float32_t *pTmpB)
riscv_status riscv_mat_qr_f64(const riscv_matrix_instance_f64 *pSrc, const float64_t threshold, riscv_matrix_instance_f64 *pOutR, riscv_matrix_instance_f64 *pOutQ, float64_t *pOutTau, float64_t *pTmpA, float64_t *pTmpB)
group MatrixQR

Computes the QR decomposition of a matrix M using Householder algorithm.

$M = Q R$

where Q is an orthogonal matrix and R is upper triangular. No pivoting strategy is used.

The returned value for R is using a format a bit similar to LAPACK : it is not just containing the matrix R but also the Householder reflectors.

The function is also returning a vector $$\tau$$ that is containing the scaling factor for the reflectors.

Returned value R has the structure:

$\begin{split} \begin{pmatrix} r_{11} & r_{12} & \dots & r_{1n} \\ v_{12} & r_{22} & \dots & r_{2n} \\ v_{13} & v_{22} & \dots & r_{3n} \\ \vdots & \vdots & \ddots & \vdots \\ v_{1m} & v_{2(m-1)} & \dots & r_{mn} \\ \end{pmatrix} \end{split}$

where

$\begin{split} v_1 = \begin{pmatrix} 1 \\ v_{12} \\ \vdots \\ v_{1m} \\ \end{pmatrix} \end{split}$

is the first householder reflector.

The Householder Matrix is given by $$H_1$$

$H_1 = I - \tau_1 v_1 v_1^T$

The Matrix Q is the product of the Householder matrices:

$Q = H_1 H_2 \dots H_n$

The computation of the matrix Q by this function is optional.

And the matrix R, would be the returned value R without the householder reflectors:

$\begin{split} \begin{pmatrix} r_{11} & r_{12} & \dots & r_{1n} \\ 0 & r_{22} & \dots & r_{2n} \\ 0 & 0 & \dots & r_{3n} \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \dots & r_{mn} \\ \end{pmatrix} \end{split}$

Functions

riscv_status riscv_mat_qr_f16(const riscv_matrix_instance_f16 *pSrc, const float16_t threshold, riscv_matrix_instance_f16 *pOutR, riscv_matrix_instance_f16 *pOutQ, float16_t *pOutTau, float16_t *pTmpA, float16_t *pTmpB)

QR decomposition of a m x n half floating point matrix with m >= n.

QR decomposition of a m x n floating point matrix with m >= n.

pOutQ is optional:

pOutQ can be a NULL pointer. In this case, the argument will be ignored and the output Q matrix won’t be computed.

f16 implementation

The f16 implementation is not very accurate.

Norm2 threshold

For the meaning of this argument please refer to the Householder transform of a vector documentation

Parameters
• pSrc[in] points to input matrix structure. The source matrix is modified by the function.

• threshold[in] norm2 threshold.

• pOutR[out] points to output R matrix structure of dimension m x n

• pOutQ[out] points to output Q matrix structure of dimension m x m (can be NULL)

• pOutTau[out] points to Householder scaling factors of dimension n

• pTmpA[inout] points to a temporary vector of dimension m.

• pTmpB[inout] points to a temporary vector of dimension m.

Returns

execution status

• RISCV_MATH_SUCCESS : Operation successful

• RISCV_MATH_SIZE_MISMATCH : Matrix size check failed

riscv_status riscv_mat_qr_f32(const riscv_matrix_instance_f32 *pSrc, const float32_t threshold, riscv_matrix_instance_f32 *pOutR, riscv_matrix_instance_f32 *pOutQ, float32_t *pOutTau, float32_t *pTmpA, float32_t *pTmpB)

QR decomposition of a m x n floating point matrix with m >= n.

pOutQ is optional:

pOutQ can be a NULL pointer. In this case, the argument will be ignored and the output Q matrix won’t be computed.

Norm2 threshold

For the meaning of this argument please refer to the Householder transform of a vector documentation

Parameters
• pSrc[in] points to input matrix structure. The source matrix is modified by the function.

• threshold[in] norm2 threshold.

• pOutR[out] points to output R matrix structure of dimension m x n

• pOutQ[out] points to output Q matrix structure of dimension m x m (can be NULL)

• pOutTau[out] points to Householder scaling factors of dimension n

• pTmpA[inout] points to a temporary vector of dimension m.

• pTmpB[inout] points to a temporary vector of dimension m.

Returns

execution status

• RISCV_MATH_SUCCESS : Operation successful

• RISCV_MATH_SIZE_MISMATCH : Matrix size check failed

riscv_status riscv_mat_qr_f64(const riscv_matrix_instance_f64 *pSrc, const float64_t threshold, riscv_matrix_instance_f64 *pOutR, riscv_matrix_instance_f64 *pOutQ, float64_t *pOutTau, float64_t *pTmpA, float64_t *pTmpB)

QR decomposition of a m x n double floating point matrix with m >= n.

QR decomposition of a m x n floating point matrix with m >= n.

pOutQ is optional:

pOutQ can be a NULL pointer. In this case, the argument will be ignored and the output Q matrix won’t be computed.

Norm2 threshold

For the meaning of this argument please refer to the Householder transform of a vector documentation

Parameters
• pSrc[in] points to input matrix structure. The source matrix is modified by the function.

• threshold[in] norm2 threshold.

• pOutR[out] points to output R matrix structure of dimension m x n

• pOutQ[out] points to output Q matrix structure of dimension m x m (can be NULL)

• pOutTau[out] points to Householder scaling factors of dimension n

• pTmpA[inout] points to a temporary vector of dimension m.

• pTmpB[inout] points to a temporary vector of dimension m.

Returns

execution status

• RISCV_MATH_SUCCESS : Operation successful

• RISCV_MATH_SIZE_MISMATCH : Matrix size check failed