Skip to content

Adjoint/transpose for tridiagonal matrices preserve structure #1370

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 1 commit into
base: master
Choose a base branch
from

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Jun 2, 2025

After this, adjoint and transpose for Tridiagonal/SymTridiagonal would preserve the structure. This was already the case for matrices of numbers, and this PR extends this to the general case.

julia> m = [1 2; 3 4]
2×2 Matrix{Int64}:
 1  2
 3  4

julia> T = Tridiagonal(fill(m,3), fill(m,4), fill(m,3))
4×4 Tridiagonal{Matrix{Int64}, Vector{Matrix{Int64}}}:
 [1 2; 3 4]  [1 2; 3 4]                      
 [1 2; 3 4]  [1 2; 3 4]  [1 2; 3 4]           
            [1 2; 3 4]  [1 2; 3 4]  [1 2; 3 4]
                       [1 2; 3 4]  [1 2; 3 4]

julia> T'
4×4 Tridiagonal{Adjoint{Int64, Matrix{Int64}}, Base.ReshapedArray{Adjoint{Int64, Matrix{Int64}}, 1, Adjoint{Adjoint{Int64, Matrix{Int64}}, Vector{Matrix{Int64}}}, Tuple{}}}:
 [1 3; 2 4]  [1 3; 2 4]                      
 [1 3; 2 4]  [1 3; 2 4]  [1 3; 2 4]           
            [1 3; 2 4]  [1 3; 2 4]  [1 3; 2 4]
                       [1 3; 2 4]  [1 3; 2 4]

julia> S = SymTridiagonal(fill(m, 4), fill(m, 3))
4×4 SymTridiagonal{Matrix{Int64}, Vector{Matrix{Int64}}}:
 [1 2; 2 4]  [1 2; 3 4]                      
 [1 3; 2 4]  [1 2; 2 4]  [1 2; 3 4]           
            [1 3; 2 4]  [1 2; 2 4]  [1 2; 3 4]
                       [1 3; 2 4]  [1 2; 2 4]

julia> S' isa SymTridiagonal
true

julia> S'' === S
true

Copy link

codecov bot commented Jun 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.83%. Comparing base (39ee3af) to head (1a486bb).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1370      +/-   ##
==========================================
+ Coverage   93.81%   93.83%   +0.02%     
==========================================
  Files          34       34              
  Lines       15715    15709       -6     
==========================================
- Hits        14743    14741       -2     
+ Misses        972      968       -4     

☔ 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.

adjoint(S::SymTridiagonal{<:Number}) = SymTridiagonal(vec(adjoint(S.dv)), vec(adjoint(S.ev)))
adjoint(S::SymTridiagonal{<:Number, <:Base.ReshapedArray{<:Number,1,<:Adjoint}}) =
SymTridiagonal(adjoint(parent(S.dv)), adjoint(parent(S.ev)))
adjoint(S::SymTridiagonal) = SymTridiagonal(_vecadjoint(S.dv), _vecadjoint(S.ev))
Copy link
Member

@stevengj stevengj Jun 2, 2025

Choose a reason for hiding this comment

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

I think this is only correct for SymTridiagonal{<:Number}.

In particular, the off-diagonal elements should be adjoint.(transpose.(S.ev)) or equivalently conj(S.ev). The reason is that S.ev stores the upper diagonal, but when you take the adjoint, the new upper diagonal comes from the adjoint of the lower diagonal, but the lower diagonal of S is transpose.(S.ev).

(Why we allow SymTridiagonal for non-Number elements is beyond me.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants