Skip to content

Commit

Permalink
Generalize indexing a BandSlice (#337)
Browse files Browse the repository at this point in the history
* Reindex for BandSlice

* generalize BandSlice indexing

* version bump to v0.17.16

* specialize only for AbstractRange indices

It's ok to be conservative here
  • Loading branch information
jishnub authored Feb 22, 2023
1 parent aac8d7e commit e107e86
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BandedMatrices"
uuid = "aae01518-5342-5314-be14-df237901396f"
version = "0.17.15"
version = "0.17.16"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
2 changes: 1 addition & 1 deletion src/generic/Band.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ for f in (:indices, :unsafe_indices, :axes1, :first, :last, :size, :length,
@eval $f(S::BandSlice) = $f(S.indices)
end

getindex(S::BandSlice, i::Int) = getindex(S.indices, i)
getindex(S::BandSlice, i::Union{Int, AbstractRange}) = getindex(S.indices, i)
show(io::IO, r::BandSlice) = print(io, "BandSlice(", r.band, ", ", r.indices, ")")

to_index(::Band) = throw(ArgumentError("Block must be converted by to_indices(...)"))
Expand Down
8 changes: 8 additions & 0 deletions test/test_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,14 @@ import BandedMatrices: rowstart, rowstop, colstart, colstop,
end
end

@testset "views of band views" begin
A = BandedMatrix(0=>1:4, 1=>(1:3) .+ 5, -1=>(1:3) .+ 10)
v = @view A[band(1)]
w = view(v, 2:3)
@test w == [7,8]
@test parentindices(w) isa Tuple{AbstractRange}
end

@testset "other special indexing" begin
@testset "all elements" begin
a = BandedMatrix(Ones(3, 3), (1, 1))
Expand Down

2 comments on commit e107e86

@jishnub
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/78232

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.17.16 -m "<description of version>" e107e863d1fdc37f9e798f46d0e2680ee91e7cab
git push origin v0.17.16

Please sign in to comment.