Skip to content
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

Cached BandedMatrices give wrong entries and break bandedness #247

Closed
TSGut opened this issue Apr 21, 2023 · 4 comments
Closed

Cached BandedMatrices give wrong entries and break bandedness #247

TSGut opened this issue Apr 21, 2023 · 4 comments

Comments

@TSGut
Copy link
Contributor

TSGut commented Apr 21, 2023

@dlfivefifty I was looking for a minimum working example of the fill-in bug mentioned in this PR but I came across something else in the process:

julia> A = BandedMatrix(0=>ones(10),1 => zeros(9))
10×10 BandedMatrix{Float64} with bandwidths (0, 1):
 1.0  0.0                                
     1.0  0.0                            
         1.0  0.0                        
             1.0  0.0                    
                 1.0  0.0                
                     1.0  0.0            
                         1.0  0.0        
                             1.0  0.0    
                                 1.0  0.0
                                     1.0

julia> B = cache(A) # huh?
10×10 CachedArray{Float64, 2, BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}, BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}}:
 1.0  0.0                                
     1.0  0.0                            
         0.0  0.0                        
             0.0  0.0                    
                 0.0  0.0                
                     0.0  0.0            
                         0.0  0.0        
                             0.0  0.0    
                                 0.0  0.0
                                     1.0

julia> B[1:10,1:10] # still wrong.. and broke bandedness
10×10 Matrix{Float64}:
 1.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  1.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.0

blocking the output I get what is expected (minus the breaking bandedness):

julia> A = BandedMatrix(0=>ones(10),1 => zeros(9))
10×10 BandedMatrix{Float64} with bandwidths (0, 1):
 1.0  0.0                                
     1.0  0.0                            
         1.0  0.0                        
             1.0  0.0                    
                 1.0  0.0                
                     1.0  0.0            
                         1.0  0.0        
                             1.0  0.0    
                                 1.0  0.0
                                     1.0

julia> B = cache(A);

julia> B[1:10,1:10]
10×10 Matrix{Float64}:
 1.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  1.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  1.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  1.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  1.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  1.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  1.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.0

This is probably entirely unrelated but I would still like to know what's happening here

@TSGut
Copy link
Contributor Author

TSGut commented Apr 22, 2023

While I don't know why this interaction happens when display() is called, it seems that this bug is not present when LazyBandedMatrices.jl is also in use, which is the intended way of interfacing BandedMatrices with LazyArrays.

This is still strange behavior so I will leave it open for now I guess?

@dlfivefifty
Copy link
Member

We can change LazyBandedMatrices.jl into a Julia v1.9 extension in the future

@dlfivefifty dlfivefifty mentioned this issue Apr 25, 2024
6 tasks
@dlfivefifty
Copy link
Member

This is fixed in v2.0

@dlfivefifty
Copy link
Member

julia> using LazyArrays, BandedMatrices

julia> A = BandedMatrix(0=>ones(10),1 => zeros(9))
10×10 BandedMatrix{Float64} with bandwidths (0, 1):
 1.0  0.0                                
     1.0  0.0                            
         1.0  0.0                        
             1.0  0.0                    
                 1.0  0.0                
                     1.0  0.0            
                         1.0  0.0        
                             1.0  0.0    
                                 1.0  0.0
                                     1.0

julia> B = cache(A) # huh?
10×10 LazyArrays.CachedArray{Float64, 2, BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}, BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}}:
 1.0  0.0                                
     1.0  0.0                            
         1.0  0.0                        
             1.0  0.0                    
                 1.0  0.0                
                     1.0  0.0            
                         1.0  0.0        
                             1.0  0.0    
                                 1.0  0.0
                                     1.0

julia> B[1:10,1:10]
10×10 BandedMatrix{Float64} with bandwidths (0, 1):
 1.0  0.0                                
     1.0  0.0                            
         1.0  0.0                        
             1.0  0.0                    
                 1.0  0.0                
                     1.0  0.0            
                         1.0  0.0        
                             1.0  0.0    
                                 1.0  0.0
                                     1.0

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

No branches or pull requests

2 participants