Skip to content

Commit

Permalink
fix getindex of Fill with Trues (#149)
Browse files Browse the repository at this point in the history
* fix getindex

hopefully addresses #148

* test

* refine

* restrict to OneTo
  • Loading branch information
JeffFessler authored Jun 30, 2021
1 parent a7ce2f8 commit 5279a5d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FillArrays"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.11.7"
version = "0.11.8"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
8 changes: 8 additions & 0 deletions src/trues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ function Base.getindex(x::AbstractArray{T,N}, mask::Trues{N, NTuple{N,Base.OneTo
end
return x[trues(size(x))] # else revert to usual getindex method
end

# https://github.com/JuliaArrays/FillArrays.jl/issues/148
function Base.getindex(
a::AbstractFill{T, 1, Tuple{Base.OneTo{Int}}},
b::Trues{1, Tuple{Base.OneTo{Int}}}) where T
@boundscheck length(a) == length(b) || throw(BoundsError(a, b))
return Fill(getindex_value(a), length(a))
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,8 @@ end
@test_throws BoundsError ones(3)[Trues(2)]
@test_throws BoundsError setindex!(ones(3), zeros(3), Trues(2))
@test_throws DimensionMismatch setindex!(ones(2), zeros(3), Trues(2))
@test Ones(3)[Trues(3)] == Ones(3)
@test_throws BoundsError Ones(3)[Trues(2)]
end

@testset "FillArray interface" begin
Expand Down

2 comments on commit 5279a5d

@dlfivefifty
Copy link
Member

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/39917

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.11.8 -m "<description of version>" 5279a5d3f52fb92d9836f9abbb652f1ae4542e59
git push origin v0.11.8

Please sign in to comment.