Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@denius
Created October 29, 2017 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denius/ffa555b7e2f0c01c876e88d82f9fa0ee to your computer and use it in GitHub Desktop.
Save denius/ffa555b7e2f0c01c876e88d82f9fa0ee to your computer and use it in GitHub Desktop.
Application of Householder reflector from right
# apply reflector from right
# derived from base/linalg/generic.jl
@inline function reflectorApplyRight!(x::AbstractVector, τ::Number, A::AbstractMatrix)
m, n = size(A)
if length(x) != n
throw(DimensionMismatch("reflector has length $(length(x)), which must match the first dimension of matrix A, $n"))
end
@inbounds begin
for i = 1:m
# note: ommited x[1] == 1
# dot
Aiv = A[i, 1]
for j = 2:n
Aiv += A[i, j]*x[j]
end
Aiv = τ*Aiv
# ger
A[i, 1] -= Aiv
for j = 2:n
A[i, j] -= Aiv*x[j]'
end
end
end
return A
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment