Skip to content

Structured broadcasting for UpperHessenberg #1325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Apr 30, 2025

This adds a custom structured broadcasting style for an UpperHessenberg, which now retains structure on some broadcasting operations.

julia> UH = UpperHessenberg(ones(4,4))
4×4 UpperHessenberg{Float64, Matrix{Float64}}:
 1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0
     1.0  1.0  1.0
         1.0  1.0

julia> UH .+ UH
4×4 UpperHessenberg{Float64, Matrix{Float64}}:
 2.0  2.0  2.0  2.0
 2.0  2.0  2.0  2.0
     2.0  2.0  2.0
         2.0  2.0

julia> B = Bidiagonal(1:4, 1:3, :L);

julia> UH .+ B
4×4 UpperHessenberg{Float64, Matrix{Float64}}:
 2.0  1.0  1.0  1.0
 2.0  3.0  1.0  1.0
     3.0  4.0  1.0
         4.0  5.0

Unlike an UpperTriangular, an UpperHessenberg can retain its structure in broadcasting operations involving other banded matrices such an Tridiagonal. We may also, in the future, make ::UpperTriangular .+ ::Bidiagonal produce an UpperHessenberg.

Copy link

codecov bot commented Apr 30, 2025

Codecov Report

Attention: Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.76%. Comparing base (c9b6456) to head (b17c415).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/structuredbroadcast.jl 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1325      +/-   ##
==========================================
+ Coverage   93.74%   93.76%   +0.02%     
==========================================
  Files          34       34              
  Lines       15752    15769      +17     
==========================================
+ Hits        14766    14786      +20     
+ Misses        986      983       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jishnub jishnub force-pushed the jishnub/hessenberg_bcast branch from 43b3963 to 499c286 Compare May 4, 2025 06:24
Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome how "little" work needs to be done to make it work.

@@ -27,28 +31,46 @@ Broadcast.BroadcastStyle(::StructuredMatrixStyle{Diagonal}, ::StructuredMatrixSt
StructuredMatrixStyle{LowerTriangular}()
Broadcast.BroadcastStyle(::StructuredMatrixStyle{Diagonal}, ::StructuredMatrixStyle{<:Union{UpperTriangular,UnitUpperTriangular}}) =
StructuredMatrixStyle{UpperTriangular}()
Broadcast.BroadcastStyle(::StructuredMatrixStyle{Diagonal}, ::StructuredMatrixStyle{UpperHessenberg}) =
StructuredMatrixStyle{UpperHessenberg}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, where do you handle the case Broadcast.BroadcastStyle(::StructuredMatrixStyle{UpperHessenberg}, ::StructuredMatrixStyle{UpperHessenberg})? Like in UH .+ UH. Is there some fallback?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handled by the fallback method

Broadcast.result_style(s1::S, s2::S) where S<:BroadcastStyle

The BroadcastStyle methods are only required when promotion is needed.

@@ -388,4 +393,11 @@ end
@test ind == CartesianIndex(1,1)
end

@testset "Rectangular UpperHessenberg" begin
UH = UpperHessenberg(ones(4,3))
UH2 = UH .+ UH .- UH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that even work with

Suggested change
UH2 = UH .+ UH .- UH
UH2 = UH + UH - UH

?

@jishnub jishnub added the feature Indicates new feature / enhancement requests label May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants