Skip to content

Conversation

@jishnub
Copy link
Member

@jishnub jishnub commented Feb 19, 2025

After this, the following work:

julia> M = diagm(0=>1:4, -1=>1:3)
4×4 Matrix{Int64}:
 1  0  0  0
 1  2  0  0
 0  2  3  0
 0  0  3  4

julia> convert(Bidiagonal, M)
4×4 Bidiagonal{Int64, Vector{Int64}}:
 1      
 1  2    
   2  3  
     3  4

julia> convert(Tridiagonal, M)
4×4 Tridiagonal{Int64, Vector{Int64}}:
 1  0    
 1  2  0  
   2  3  0
     3  4

julia> M = diagm(0=>1:4, -1=>1:3, 1=>1:3)
4×4 Matrix{Int64}:
 1  1  0  0
 1  2  2  0
 0  2  3  3
 0  0  3  4

julia> convert(SymTridiagonal, M)
4×4 SymTridiagonal{Int64, Vector{Int64}}:
 1  1    
 1  2  2  
   2  3  3
     3  4

These parallel the analogous convert method for Diagonal that already exists. The method for Bidiagonal detects the zero band and automatically chooses the uplo accordingly. This fixes the currently broken behavior, where the uplo was not provided to the constructor:

julia> convert(Bidiagonal, M)
ERROR: MethodError: no method matching Bidiagonal(::Matrix{Int64})

@dkarrasch
Copy link
Member

Does this work (in all cases) when the converted-to type has a different eltype? Like implicit eltype promotion?

@jishnub
Copy link
Member Author

jishnub commented Feb 19, 2025

Should work now after generalizing the constructor.

julia> M = diagm(0=>fill(3,4), 1=>fill(3,3))
4×4 Matrix{Int64}:
 3  3  0  0
 0  3  3  0
 0  0  3  3
 0  0  0  3

julia> using FillArrays

julia> f = Fill(Int8(4), 3);

julia> convert(Bidiagonal{eltype(f)}, M)
4×4 Bidiagonal{Int8, Vector{Int8}}:
 3  3    
   3  3  
     3  3
       3

julia> convert(Bidiagonal{eltype(f), typeof(f)}, M)
4×4 Bidiagonal{Int8, Fill{Int8, 1, Tuple{Base.OneTo{Int64}}}}:
 3  3    
   3  3  
     3  3
       3

@codecov
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.90%. Comparing base (b464203) to head (6f4b663).
Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1212      +/-   ##
==========================================
+ Coverage   91.88%   91.90%   +0.01%     
==========================================
  Files          34       34              
  Lines       15374    15386      +12     
==========================================
+ Hits        14127    14141      +14     
+ Misses       1247     1245       -2     

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

@jishnub
Copy link
Member Author

jishnub commented Feb 27, 2025

Gentle bump

@jishnub jishnub added enhancement New feature or request arrays [a, r, r, a, y, s] labels Feb 27, 2025
@dkarrasch dkarrasch merged commit 62c8100 into master Feb 28, 2025
4 checks passed
@dkarrasch dkarrasch deleted the jishnub/banded_convert branch February 28, 2025 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrays [a, r, r, a, y, s] enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants