JuliaLinearAlgebra / BandedMatrices.jl

A Julia package for representing banded matrices
http://julialinearalgebra.github.io/BandedMatrices.jl/
Other
129 stars 38 forks source link

Colon-integer indexing bug #452

Closed max-vassili3v closed 1 month ago

max-vassili3v commented 1 month ago

I noticed that the following doesn't work:

julia> b = BandedMatrix(Ones(3, 9), (0, 0))
3×9 BandedMatrix{Float64} with bandwidths (0, 0):
 1.0   ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅
  ⋅   1.0   ⋅    ⋅    ⋅    ⋅    ⋅    ⋅    ⋅
  ⋅    ⋅   1.0   ⋅    ⋅    ⋅    ⋅    ⋅    ⋅

julia> b[:,6]
ERROR: BoundsError: attempt to access 3-element Vector{Float64} at index [1:5]
Stacktrace:
 [1] throw_boundserror(A::Vector{Float64}, I::Tuple{UnitRange{Int64}})
   @ Base .\abstractarray.jl:737
 [2] checkbounds
   @ .\abstractarray.jl:702 [inlined]
 [3] view
   @ .\subarray.jl:179 [inlined]
 [4] maybeview
   @ .\views.jl:148 [inlined]
 [5] dotview
   @ .\broadcast.jl:1244 [inlined]
 [6] getindex(A::BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}, ::Colon, j::Int64)
   @ BandedMatrices d:\Documents\Github\BandedMatrices.jl\src\banded\BandedMatrix.jl:423
 [7] top-level scope
   @ REPL[29]:1

I added a fix and updated the unit tests to cover it

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 89.84%. Comparing base (47c15ab) to head (67d5f3f). Report is 5 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #452 +/- ## ========================================== + Coverage 89.61% 89.84% +0.23% ========================================== Files 25 25 Lines 3571 3643 +72 ========================================== + Hits 3200 3273 +73 + Misses 371 370 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

dlfivefifty commented 1 month ago

Thanks!

dlfivefifty commented 1 month ago

PS It's a good idea to bump the version number (in this case a patch version, i.e. increase y in 1.x.y) as then I can just tag a new release right away with the fix