# Implementation of householder/reflection matrices with efficient multiplication?

**URL:** <https://discourse.julialang.org/t/implementation-of-householder-reflection-matrices-with-efficient-multiplication/81257>\
**Category:** Numerics\
**Tags:** question, linearalgebra\
**Created:** [May 18, 2022, 12:42pm UTC](https://discourse.julialang.org/t/implementation-of-householder-reflection-matrices-with-efficient-multiplication/81257 "2022-05-18T12:42:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptonner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptonner/32/36369_2.png) [@ptonner](https://discourse.julialang.org/u/ptonner)\
**Post date:** [May 18, 2022, 12:42pm UTC](https://discourse.julialang.org/t/implementation-of-householder-reflection-matrices-with-efficient-multiplication/81257/1 "2022-05-18T12:42:05Z")

</div>

Is there a standard implementation of reflector/householder matrices and their efficient multiplication with vectors (e.g. O(n) cost)?

I don’t think this would be hard to implement for my specific purposes, but for that same reason I’m suspecting it exists somewhere already. But I haven’t been able to find it anywhere.

Thanks!

---

<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 18, 2022, 12:52pm UTC](https://discourse.julialang.org/t/implementation-of-householder-reflection-matrices-with-efficient-multiplication/81257/2 "2022-05-18T12:52:14Z")

</div>

I think you want `LinearAlgebra.reflectorApply!`. Unfortunately no documentation…

```julia
help?> LinearAlgebra.reflectorApply!
  No documentation found.

  LinearAlgebra.reflectorApply! is a Function.

  # 1 method for generic function "reflectorApply!":
  [1] reflectorApply!(x::AbstractVector, τ::Number, A::AbstractMatrix) in LinearAlgebra at /Users/sheehanolver/Projects/julia-1.7/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/generic.jl:1518

```

---

<div class="post-metadata">

**Author:** ![ptonner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptonner/32/36369_2.png) [@ptonner](https://discourse.julialang.org/u/ptonner)\
**Post date:** [May 18, 2022, 1:00pm UTC](https://discourse.julialang.org/t/implementation-of-householder-reflection-matrices-with-efficient-multiplication/81257/3 "2022-05-18T13:00:22Z")

</div>

Thanks! I’ll take a look at the implementation to see if it’s doing what I need

But I was more wondering if there was some generic type that used this functionality through an implementation of the array interface. Then I could just plug in its representation where I need it. I guess this doesn’t exist?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [May 18, 2022, 1:06pm UTC](https://discourse.julialang.org/t/implementation-of-householder-reflection-matrices-with-efficient-multiplication/81257/4 "2022-05-18T13:06:54Z")

</div>

Even more “low level” is the LAPACK interface with `LinearAlgebra.LAPACK.larfg!` and `LinearAlgebra.LAPACK.larf!`, and my knowledge ends about here; cf. [?larf](https://www.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-fortran/top/lapack-routines/lapack-auxiliary-routines/larf.html)

(Also, let’s appreciate the name 🙂 )

> <https://github.com/JuliaLang/julia/blob/e84b06c67393ee10799535781144de3c2d8860b7/stdlib/LinearAlgebra/src/lapack.jl#L787>

---

<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 18, 2022, 1:35pm UTC](https://discourse.julialang.org/t/implementation-of-householder-reflection-matrices-with-efficient-multiplication/81257/5 "2022-05-18T13:35:32Z")

</div>

Not for a single reflection. There is `LinearAlgebra.QRPackedQ` which is the LAPack format for a sequence of Householder reflections. (Also `LinearAlgebra.QRCompactWYQ` for the blocked storage )

---

<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:** [May 18, 2022, 3:09pm UTC](https://discourse.julialang.org/t/implementation-of-householder-reflection-matrices-with-efficient-multiplication/81257/6 "2022-05-18T15:09:02Z")

</div>

> [@ptonner](#):
>
> Is there a standard implementation of reflector/householder matrices and their efficient multiplication with vectors (e.g. O(n) cost)?

There’s not much need for a library routine for a _single_ reflector, since applying a single (unit-normalized) reflector `v` to a vector `x` is such a simple operation:

```julia
x .- v .* (2(v'x))

```
