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

data_rowrange bug #453

Merged

Conversation

max-vassili3v
Copy link
Contributor

I found a bug with indexing rows of a BandedMatrix whose data matrix is one row:

julia> a = BandedMatrix(ones(2,5), (0,0))
2×5 BandedMatrix{Float64} with bandwidths (0, 0):
 1.0   ⋅    ⋅    ⋅    ⋅
  ⋅   1.0   ⋅    ⋅    ⋅

julia> a[1,:]
ERROR: ArgumentError: step cannot be zero
Stacktrace:
 [1] steprange_last
   @ .\range.jl:338 [inlined]
 [2] StepRange
   @ .\range.jl:325 [inlined]
 [3] range_start_step_length(a::Int64, step::Int64, len::Int64)
   @ Base .\range.jl:216
 [4] _range
   @ .\range.jl:168 [inlined]
 [5] range
   @ .\range.jl:147 [inlined]
 [6] data_rowrange
   @ d:\Documents\Github\BandedMatrices.jl\src\banded\BandedMatrix.jl:575 [inlined]
 [7] getindex(A::BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}, k::Int64, ::Colon)
   @ BandedMatrices d:\Documents\Github\BandedMatrices.jl\src\banded\BandedMatrix.jl:443
 [8] top-level scope
   @ REPL[23]:1

I added a fix and unit tests to go with it.

Copy link

codecov bot commented Aug 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.84%. Comparing base (47c15ab) to head (80947a5).
Report is 6 commits behind head on master.

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

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

@dlfivefifty
Copy link
Member

A simpler fix might be to use StepRangeLen that allows zero steps:

julia> StepRangeLen(2,0,3)
StepRangeLen(2, 0, 3)

julia> collect(StepRangeLen(2,0,3))
3-element Vector{Int64}:
 2
 2
 2
```

@dlfivefifty dlfivefifty merged commit 57a70a5 into JuliaLinearAlgebra:master Aug 30, 2024
16 checks passed
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

Successfully merging this pull request may close these issues.

2 participants