Unnecessary limitation in QR code?

Lowell Johnson ldjohn@usgs.gov
Wed Dec 19 13:20:00 GMT 2001


I think there is an unnecessary limitation in the QR solution code
(linalg/qr.c).  The functions gsl_linalg_QR_svx() and gsl_linalg_QR_solve()
only support square matrices.  Shouldn't the input matrix be allowed to be M x
N, M >= N ?  I've applied the following changes, which seem to work:

Index: linalg/qr.c
===================================================================
RCS file: /cvs/gsl/gsl/linalg/qr.c,v
retrieving revision 1.22
diff -r1.22 qr.c
144a145,146
>   gsl_matrix RR = gsl_matrix_submatrix(QR, 0, 0, QR->size2, QR->size2);
>   gsl_vector qb = gsl_vector_subvector(x, 0, QR->size2);
146,150c148
<   if (QR->size1 != QR->size2)
<     {
<       GSL_ERROR ("QR matrix must be square", GSL_ENOTSQR);
<     }
<   else if (QR->size1 != x->size)
---
>   if (QR->size1 != x->size)
162c160
<       gsl_blas_dtrsv (CblasUpper, CblasNoTrans, CblasNonUnit, QR, x);
---
>       gsl_blas_dtrsv (CblasUpper, CblasNoTrans, CblasNonUnit, &RR, &qb);

These changes only apply to gsl_linalg_QR_svx().  Similar changes would be
needed for gsl_linalg_QR_solve(), if this is an acceptable correction.


-- Lowell



More information about the Gsl-discuss mailing list