Skip to content

Commit eb8df92

Browse files
Fix getindex of Fill with Trues in N-D (#151)
* 150 v1 * clean * Update src/trues.jl Co-authored-by: Sheehan Olver <solver@mac.com> * Update src/trues.jl Co-authored-by: Sheehan Olver <solver@mac.com> Co-authored-by: Sheehan Olver <solver@mac.com>
1 parent 5279a5d commit eb8df92

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
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.8"
3+
version = "0.11.9"
44

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

src/trues.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ function Base.getindex(x::AbstractArray{T,N}, mask::Trues{N, NTuple{N,Base.OneTo
4444
return x[trues(size(x))] # else revert to usual getindex method
4545
end
4646

47-
# https://github.com/JuliaArrays/FillArrays.jl/issues/148
47+
# https://github.com/JuliaArrays/FillArrays.jl/issues/148 and 150
4848
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))
49+
a::AbstractFill{T, N, Tuple{Vararg{Base.OneTo{Int}, N}}},
50+
b::Trues{N, Tuple{Vararg{Base.OneTo{Int}, N}}},
51+
) where {T, N}
52+
@boundscheck size(a) == size(b) || throw(BoundsError(a, b))
5253
return Fill(getindex_value(a), length(a))
5354
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,9 @@ end
12061206
@test_throws DimensionMismatch setindex!(ones(2), zeros(3), Trues(2))
12071207
@test Ones(3)[Trues(3)] == Ones(3)
12081208
@test_throws BoundsError Ones(3)[Trues(2)]
1209+
@test Ones(2,3)[Trues(2,3)] == Ones(6)
1210+
@test Ones(2,3)[Trues(6)] == Ones(6)
1211+
@test_throws BoundsError Ones(2,3)[Trues(3,2)]
12091212
end
12101213

12111214
@testset "FillArray interface" begin

0 commit comments

Comments
 (0)