Skip to content

Commit fbcbbf3

Browse files
dkarraschdlfivefifty
authored andcommitted
Allow vectors in reflectorApply! (JuliaLang#42874)
Co-authored-by: Sheehan Olver <solver@mac.com>
1 parent 380b891 commit fbcbbf3

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

stdlib/LinearAlgebra/src/generic.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,9 +1516,9 @@ end
15161516
end
15171517

15181518
# apply reflector from left
1519-
@inline function reflectorApply!(x::AbstractVector, τ::Number, A::AbstractMatrix)
1519+
@inline function reflectorApply!(x::AbstractVector, τ::Number, A::AbstractVecOrMat)
15201520
require_one_based_indexing(x)
1521-
m, n = size(A)
1521+
m, n = size(A, 1), size(A, 2)
15221522
if length(x) != m
15231523
throw(DimensionMismatch("reflector has length $(length(x)), which must match the first dimension of matrix A, $m"))
15241524
end

stdlib/LinearAlgebra/src/qr.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ function qrfactPivotedUnblocked!(A::AbstractMatrix)
270270

271271
# Compute reflector of columns j
272272
x = view(A, j:m, j)
273-
τj = LinearAlgebra.reflector!(x)
273+
τj = reflector!(x)
274274
τ[j] = τj
275275

276276
# Update trailing submatrix with reflector
277-
LinearAlgebra.reflectorApply!(x, τj, view(A, j:m, j+1:n))
277+
reflectorApply!(x, τj, view(A, j:m, j+1:n))
278278
end
279-
return LinearAlgebra.QRPivoted{eltype(A), typeof(A)}(A, τ, piv)
279+
return QRPivoted{eltype(A), typeof(A)}(A, τ, piv)
280280
end
281281

282282
# LAPACK version

stdlib/LinearAlgebra/test/generic.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ end
256256
@test_throws DimensionMismatch reflect!([x; x], y, c, s)
257257
end
258258

259+
@testset "LinearAlgebra.reflectorApply!" begin
260+
for T in (Float64, ComplexF64)
261+
x = rand(T, 6)
262+
τ = rand(T)
263+
A = rand(T, 6)
264+
B = LinearAlgebra.reflectorApply!(x, τ, copy(A))
265+
C = LinearAlgebra.reflectorApply!(x, τ, reshape(copy(A), (length(A), 1)))
266+
@test B[1] C[1] A[1] - conj(τ)*(A[1] + dot(x[2:end], A[2:end]))
267+
@test B[2:end] C[2:end] A[2:end] - conj(τ)*(A[1] + dot(x[2:end], A[2:end]))*x[2:end]
268+
end
269+
end
270+
259271
@testset "LinearAlgebra.axp(b)y! for element type without commutative multiplication" begin
260272
α = [1 2; 3 4]
261273
β = [5 6; 7 8]

0 commit comments

Comments
 (0)