Skip to content

dataview to forward row and col views #477

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Apr 17, 2025

This adds methods to dataview to forward row and column views of BandedMatrices to the underlying data.

julia> B = BandedMatrix(0=>2:4, 1=>1:2)
3×3 BandedMatrix{Int64} with bandwidths (0, 1):
 2  1  
   3  2
     4

julia> v = view(B, 1:2, 2)
2-element view(::BandedMatrix{Int64, Matrix{Int64}, Base.OneTo{Int64}}, 1:2, 2) with eltype Int64:
 1
 3

julia> BandedMatrices.dataview(v)
2-element view(::Vector{Int64}, 3:4) with eltype Int64:
 1
 3

Such methods would improve performance when indexing into the view, especially in loops.

Copy link

codecov bot commented Apr 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.83%. Comparing base (c4e85f4) to head (fde3a83).
Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #477      +/-   ##
==========================================
+ Coverage   89.71%   89.83%   +0.12%     
==========================================
  Files          25       27       +2     
  Lines        3685     3729      +44     
==========================================
+ Hits         3306     3350      +44     
  Misses        379      379              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dlfivefifty
Copy link
Member

Isn't this the same thing as bandeddata?

@jishnub
Copy link
Member Author

jishnub commented Apr 17, 2025

Indeed, I had forgotten that the functionality already exists. This currently doesn't seem to work, though, but perhaps may be made to work:

julia> B = brand(4, 4, -1, 2)
4×4 BandedMatrix{Float64} with bandwidths (-1, 2):
     0.326354  0.155544    
              0.856614  0.63237
                       0.483055
                         

julia> v = view(B, 1:2, 3)
2-element view(::BandedMatrix{Float64, Matrix{Float64}, Base.OneTo{Int64}}, 1:2, 3) with eltype Float64:
 0.1555437647782112
 0.8566140453180642

julia> BandedMatrices.bandeddata(v)
ERROR: MethodError: no method matching bandshift(::UnitRange{Int64}, ::Int64)
The function `bandshift` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  bandshift(::Any)
   @ BandedMatrices ~/Dropbox/JuliaPackages/BandedMatrices.jl/src/banded/BandedMatrix.jl:880
  bandshift(::AbstractRange, ::Base.Slice{Base.OneTo{Int64}})
   @ BandedMatrices ~/Dropbox/JuliaPackages/BandedMatrices.jl/src/banded/BandedMatrix.jl:878
  bandshift(::AbstractRange, ::AbstractRange)
   @ BandedMatrices ~/Dropbox/JuliaPackages/BandedMatrices.jl/src/banded/BandedMatrix.jl:876
  ...

Stacktrace:
 [1] bandshift(S::SubArray{Float64, 1, BandedMatrix{Float64, Matrix{…}, Base.OneTo{…}}, Tuple{UnitRange{…}, Int64}, false})
   @ BandedMatrices ~/Dropbox/JuliaPackages/BandedMatrices.jl/src/banded/BandedMatrix.jl:880
 [2] bandeddata(V::SubArray{Float64, 1, BandedMatrix{Float64, Matrix{…}, Base.OneTo{…}}, Tuple{UnitRange{…}, Int64}, false})
   @ BandedMatrices ~/Dropbox/JuliaPackages/BandedMatrices.jl/src/banded/BandedMatrix.jl:917
 [3] top-level scope
   @ REPL[7]:1
Some type information was truncated. Use `show(err)` to see complete types.

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