Why is Diagonal Sign Convention in QR Factorization Not Enforced?

When performing the QR factorization of a m x n matrix A with full column rank (i.e. rank(A)=n), the (reduced or “skinny”) QR factorization is unique only if we enforce the sign of the diagonal entries of R. The convention is that these entries are chosen to be positive. Otherwise, there is ambiguity in the signs of the columns of Q and rows of R - see this post. A simple test:

A = randn(5,2)
qr(A).R

gives a 2x2 R matrix with a negative diagonal entry (more often than not). Is there a reason why this uniqueness requirement isn’t enforced in qr? Isn’t this possibly problematic for algorithms (like the block Lanczos iteration) which rely on the sign convention of the QR factorization?

Any deterministic algorithm makes a unique choice for the QR factors. Different algorithms result in different choices.

The QR factorization in Julia uses the Householder algorithm — this is not unique to Julia, it comes from LAPACK and is the most common algorithm for a variety of reasons. In this algorithm, the Q factors are not stored explicitly, but as a linear operator (a sequence of reflections), and it is not so natural or efficient to choose the signs of the R diagonals to be positive.

PS. In the rare cases where you need positive real diagonal elements of R, you can simply multiply Q by an additional diagonal scaling factor Diagonal(sign.(diag(R)). e.g. this is employed by Mezzadri (2007) to generate uniformly distributed orthogonal matrices by QR-factorizing Gaussian random matrices.

2 Likes