Why is Diagonal Sign Convention in QR Factorization Not Enforced?

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