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

Why so picky with length of diagonals? #160

Open
baggepinnen opened this issue Mar 6, 2020 · 2 comments
Open

Why so picky with length of diagonals? #160

baggepinnen opened this issue Mar 6, 2020 · 2 comments

Comments

@baggepinnen
Copy link

I found it strangely difficult to construct banded matrices. If I use the constructor

BandedMatrix((0=>Fill(1,n), ...), (m,n))

why do I have to specify both the size of the matrix, and the length of the diagonals?
Why not provide a constructor that takes numbers instead of vectors, e.g.,

BandedMatrix((0=>1, 1=>-1), (m,n))

where all sizes etc. are given by the diagonal indices and the size of the matrix?

If I provide a Fill(1,n) that is too long, there is a bounds error.

@dlfivefifty
Copy link
Member

I'm slightly hesitant due to inconsistency with the vector version.

We could change it to not produce the error when the vectors are the wrong length? That is, truncate or pad by zeros.

@baggepinnen
Copy link
Author

We could change it to not produce the error when the vectors are the wrong length? That is, truncate or pad by zeros.

That would certainly be helpful. The reason I got so confused was error messages like this

julia> BandedMatrix((-1=> 1:5, 2=>1:3), (3,3))
ERROR: BoundsError: attempt to access 4×3 Array{Int64,2} at index [4, 1:5]
Stacktrace:
 [1] throw_boundserror(::Array{Int64,2}, ::Tuple{Int64,UnitRange{Int64}}) at ./abstractarray.jl:537
 [2] checkbounds at ./abstractarray.jl:502 [inlined]

I couldn't easily see the relation between the dimensions of the inputs and those in the message. If I got a matrix printed in the terminal, I could inspect the result and see what dimension I got wrong.

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