Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/hessenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,29 @@
UpperHessenberg(HH)
end

function (\)(H::Union{UpperHessenberg,AdjOrTrans{<:Any,<:UpperHessenberg}}, B::AbstractVecOrMat)
TFB = typeof(oneunit(eltype(H)) \ oneunit(eltype(B)))
return ldiv!(H, copy_similar(B, TFB))
end

function (/)(B::AbstractMatrix, H::Union{UpperHessenberg,AdjOrTrans{<:Any,<:UpperHessenberg}})
TFB = typeof(oneunit(eltype(B)) / oneunit(eltype(H)))
return rdiv!(copy_similar(B, TFB), H)
end

ldiv!(H::AdjOrTrans{<:Any,<:UpperHessenberg}, B::AbstractVecOrMat) =
(rdiv!(wrapperop(H)(B), parent(H)); B)
rdiv!(B::AbstractVecOrMat, H::AdjOrTrans{<:Any,<:UpperHessenberg}) =
(ldiv!(parent(H), wrapperop(H)(B)); B)

# fix method ambiguities for right division, from adjtrans.jl:
/(u::AdjointAbsVec, A::UpperHessenberg) = adjoint(adjoint(A) \ u.parent)
/(u::TransposeAbsVec, A::UpperHessenberg) = transpose(transpose(A) \ u.parent)

Check warning on line 197 in src/hessenberg.jl

View check run for this annotation

Codecov / codecov/patch

src/hessenberg.jl#L197

Added line #L197 was not covered by tests
/(u::AdjointAbsVec, A::Adjoint{<:Any,<:UpperHessenberg}) = adjoint(adjoint(A) \ u.parent)
/(u::TransposeAbsVec, A::Transpose{<:Any,<:UpperHessenberg}) = transpose(transpose(A) \ u.parent)

Check warning on line 199 in src/hessenberg.jl

View check run for this annotation

Codecov / codecov/patch

src/hessenberg.jl#L199

Added line #L199 was not covered by tests
/(u::AdjointAbsVec, A::Transpose{<:Any,<:UpperHessenberg}) = adjoint(conj(A.parent) \ u.parent) # technically should be adjoint(copy(adjoint(copy(A))) \ u.parent)
/(u::TransposeAbsVec, A::Adjoint{<:Any,<:UpperHessenberg}) = transpose(conj(A.parent) \ u.parent)

Check warning on line 201 in src/hessenberg.jl

View check run for this annotation

Codecov / codecov/patch

src/hessenberg.jl#L201

Added line #L201 was not covered by tests

# Solving (H+µI)x = b: we can do this in O(m²) time and O(m) memory
# (in-place in x) by the RQ algorithm from:
#
Expand Down
6 changes: 6 additions & 0 deletions test/hessenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ let n = 10
H = UpperHessenberg(Areal)
@test Array(Hc + H) == Array(Hc) + Array(H)
@test Array(Hc - H) == Array(Hc) - Array(H)
@testset "ldiv and rdiv" begin
for b in (b_, B_), H in (H, Hc, H', Hc', transpose(Hc))
@test H * (H \ b) ≈ b
@test (b' / H) * H ≈ (Matrix(b') / H) * H ≈ b'
end
end
@testset "Preserve UpperHessenberg shape (issue #39388)" begin
H = UpperHessenberg(Areal)
A = rand(n,n)
Expand Down