Skip to content

Commit 5279a5d

Browse files
authored
fix getindex of Fill with Trues (#149)
* fix getindex hopefully addresses #148 * test * refine * restrict to OneTo
1 parent a7ce2f8 commit 5279a5d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FillArrays"
22
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
3-
version = "0.11.7"
3+
version = "0.11.8"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/trues.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,11 @@ function Base.getindex(x::AbstractArray{T,N}, mask::Trues{N, NTuple{N,Base.OneTo
4343
end
4444
return x[trues(size(x))] # else revert to usual getindex method
4545
end
46+
47+
# https://github.com/JuliaArrays/FillArrays.jl/issues/148
48+
function Base.getindex(
49+
a::AbstractFill{T, 1, Tuple{Base.OneTo{Int}}},
50+
b::Trues{1, Tuple{Base.OneTo{Int}}}) where T
51+
@boundscheck length(a) == length(b) || throw(BoundsError(a, b))
52+
return Fill(getindex_value(a), length(a))
53+
end

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,8 @@ end
12041204
@test_throws BoundsError ones(3)[Trues(2)]
12051205
@test_throws BoundsError setindex!(ones(3), zeros(3), Trues(2))
12061206
@test_throws DimensionMismatch setindex!(ones(2), zeros(3), Trues(2))
1207+
@test Ones(3)[Trues(3)] == Ones(3)
1208+
@test_throws BoundsError Ones(3)[Trues(2)]
12071209
end
12081210

12091211
@testset "FillArray interface" begin

0 commit comments

Comments
 (0)