Skip to content

Commit e107e86

Browse files
authored
Generalize indexing a BandSlice (#337)
* Reindex for BandSlice * generalize BandSlice indexing * version bump to v0.17.16 * specialize only for AbstractRange indices It's ok to be conservative here
1 parent aac8d7e commit e107e86

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BandedMatrices"
22
uuid = "aae01518-5342-5314-be14-df237901396f"
3-
version = "0.17.15"
3+
version = "0.17.16"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/generic/Band.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ for f in (:indices, :unsafe_indices, :axes1, :first, :last, :size, :length,
211211
@eval $f(S::BandSlice) = $f(S.indices)
212212
end
213213

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

217217
to_index(::Band) = throw(ArgumentError("Block must be converted by to_indices(...)"))

test/test_indexing.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,14 @@ import BandedMatrices: rowstart, rowstop, colstart, colstop,
670670
end
671671
end
672672

673+
@testset "views of band views" begin
674+
A = BandedMatrix(0=>1:4, 1=>(1:3) .+ 5, -1=>(1:3) .+ 10)
675+
v = @view A[band(1)]
676+
w = view(v, 2:3)
677+
@test w == [7,8]
678+
@test parentindices(w) isa Tuple{AbstractRange}
679+
end
680+
673681
@testset "other special indexing" begin
674682
@testset "all elements" begin
675683
a = BandedMatrix(Ones(3, 3), (1, 1))

0 commit comments

Comments
 (0)