Skip to content

dataview to forward row and col views#477

Open
jishnub wants to merge 2 commits into
masterfrom
jishnub/dataview
Open

dataview to forward row and col views#477
jishnub wants to merge 2 commits into
masterfrom
jishnub/dataview

Conversation

@jishnub

@jishnub jishnub commented Apr 17, 2025

Copy link
Copy Markdown
Member

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.

@codecov

codecov Bot commented Apr 17, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.84%. Comparing base (25a2f14) to head (4bf9765).
⚠️ Report is 21 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #477      +/-   ##
==========================================
+ Coverage   89.79%   89.84%   +0.05%     
==========================================
  Files          27       27              
  Lines        3713     3733      +20     
==========================================
+ Hits         3334     3354      +20     
  Misses        379      379              

☔ View full report in Codecov by Harness.
📢 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
Copy Markdown
Member

Isn't this the same thing as bandeddata?

@jishnub

jishnub commented Apr 17, 2025

Copy link
Copy Markdown
Member Author

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