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

Question : Finding the bandwidth of a matrix #247

Open
338rajesh opened this issue Dec 9, 2021 · 7 comments
Open

Question : Finding the bandwidth of a matrix #247

338rajesh opened this issue Dec 9, 2021 · 7 comments

Comments

@338rajesh
Copy link
Contributor

I am trying to get the bandwidth of a matrix using BandedMatrices.jl in the following manner.

julia> using BandedMatrices

julia> A =  [
           2.0 5.0 5.0 0.0 0.0 0.0
           2.0 5.0 5.0 0.0 0.0 0.0
           2.0 5.0 5.0 0.0 0.0 0.0
           0.0 0.0 0.0 8.0 0.0 0.0
           0.0 0.0 0.0 0.0 8.0 0.0
           0.0 0.0 0.0 0.0 0.0 8.0];

julia> println(bandwidths(A))
(5, 5)

It is giving (5,5) while I am expecting (3,3).

Please let me know the right procedure for getting the bandwidth of a given matrix.

Thanks in advance.

@jishnub
Copy link
Member

jishnub commented Jul 8, 2022

julia> using SparseArrays

julia> sparse(A)
6×6 SparseMatrixCSC{Float64, Int64} with 12 stored entries:
 2.0  5.0  5.0            
 2.0  5.0  5.0            
 2.0  5.0  5.0            
             8.0        
                 8.0    
                     8.0

julia> sparse(A) |> bandwidths
(2, 2)

Why are you expecting (3,3) btw?

@338rajesh
Copy link
Contributor Author

yeah, I agree it must be (2, 2) not (3,3).

It is working for SparseArray type but not with dense matrices as I have mentioned in the question.
I am not sure, if it is intentionally designed to work in that way for any advantage.

I confirm the same behavior with the new version of the package.

@dlfivefifty
Copy link
Member

bandwidths should be “fast”. Checking every entry is an O(n^2) operation

@MikaelSlevinsky
Copy link
Member

MikaelSlevinsky commented Jul 8, 2022

How can you get the bandwidths of a dense matrix without checking for the zeros?

@dlfivefifty
Copy link
Member

bandwidths is about structural zeros not actual zeros. So you just assume it’s full

@MikaelSlevinsky
Copy link
Member

Maybe it needs info in the docs because, for example, rank of a dense matrix is slow, based on svdvals, but it could have been "generically" full. Contrast that to rank of a LowRankMatrix which is fast and structural by the type.

@dlfivefifty
Copy link
Member

If you make a PR to the docs I’ll merge it

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

4 participants