# Why is Diagonal Sign Convention in QR Factorization Not Enforced?

**URL:** https://discourse.julialang.org/t/why-is-diagonal-sign-convention-in-qr-factorization-not-enforced/122283
**Category:** General Usage
**Created:** [November 5, 2024, 12:54pm UTC](https://discourse.julialang.org/t/why-is-diagonal-sign-convention-in-qr-factorization-not-enforced/122283 "2024-11-05T12:54:03Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [November 5, 2024, 1:05pm UTC](https://discourse.julialang.org/t/why-is-diagonal-sign-convention-in-qr-factorization-not-enforced/122283/2 "2024-11-05T13:05:59Z")

</div>

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](https://github.com/mitmath/18335/blob/spring21/notes/lec6handout6pp.pdf) — 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)](https://arxiv.org/abs/math-ph/0609050) to generate uniformly distributed orthogonal matrices by QR-factorizing Gaussian random matrices.

---

_[View the full topic](https://discourse.julialang.org/t/why-is-diagonal-sign-convention-in-qr-factorization-not-enforced/122283)._
