# Efficient QR factorization

**URL:** <https://discourse.julialang.org/t/efficient-qr-factorization/24767>\
**Category:** Numerics\
**Tags:** linearalgebra\
**Created:** [May 30, 2019, 1:53pm UTC](https://discourse.julialang.org/t/efficient-qr-factorization/24767 "2019-05-30T13:53:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raphaelsaavedra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raphaelsaavedra/32/27631_2.png) [@raphaelsaavedra](https://discourse.julialang.org/u/raphaelsaavedra)\
**Post date:** [May 30, 2019, 1:53pm UTC](https://discourse.julialang.org/t/efficient-qr-factorization/24767/1 "2019-05-30T13:53:38Z")

</div>

Hello,

I’m having some issues with QR factorization in Julia 1.0. I want to efficiently compute the QR factorization of the transpose of a matrix and save only Q. Back in 0.6, there were LAPACK functions that did this efficiently and in-place. Now, it looks like I’m stuck with `qr(A').Q`.

`qr!` does not accept transposes or adjoints, and the seemingly efficient LAPACK functions require a `tau` argument which I’m confused about.

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [May 30, 2019, 2:03pm UTC](https://discourse.julialang.org/t/efficient-qr-factorization/24767/2 "2019-05-30T14:03:13Z")

</div>

Back in 0.6 `A'` made a copy, is that the issue? LAPACK doesn’t support QR on transposes directly it looks like, see [`dgeqrf`](http://www.netlib.org/lapack/explore-html/df/dc5/group__variants_g_ecomputational_ga3766ea903391b5cf9008132f7440ec7b.html). Though I believe it can be recovered from the LQ decomposition, see [`dgelqf`](http://www.netlib.org/lapack/explore-html/dc/da4/dgelqf_8f.html). This would never have been used in previous versions of Julia.

If you wish to wrap this, [MatrixFactorizations.jl](https://github.com/JuliaMatrices/MatrixFactorizations.jl) would be a natural place to make a PR. It already supports QL.

---

<div class="post-metadata">

**Author:** ![raphaelsaavedra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raphaelsaavedra/32/27631_2.png) [@raphaelsaavedra](https://discourse.julialang.org/u/raphaelsaavedra)\
**Post date:** [May 30, 2019, 2:08pm UTC](https://discourse.julialang.org/t/efficient-qr-factorization/24767/3 "2019-05-30T14:08:36Z")

</div>

Back in 0.6 I could use `qrfact!(A')[:Q]`, which wasn’t ideal but seemed better than what I’m doing at the moment since it was in place.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [May 30, 2019, 2:49pm UTC](https://discourse.julialang.org/t/efficient-qr-factorization/24767/4 "2019-05-30T14:49:52Z")

</div>

I suggest you benchmark your code to see if “inplace” operations really give any speedup here. Allocating memory should be really fast compared to actually performing the QR-decomposition. `A'` in Julia 0.6 is `copy(A')` in Julia 1.0, so it’s not really “fully” inplace since it does the copying first. But even that copying should be much faster than actually performing the QR decomposition.
