Skip to content

Commit

Permalink
more consistent findall output (#45538)
Browse files Browse the repository at this point in the history
fix #45495
  • Loading branch information
aplavin authored Mar 10, 2023
1 parent 407dbdb commit 162b9e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,11 @@ julia> findall(x -> x >= 0, d)
```
"""
findall(testf::Function, A) = collect(first(p) for p in pairs(A) if testf(last(p)))
function findall(testf::Function, A)
T = eltype(keys(A))
gen = (first(p) for p in pairs(A) if testf(last(p)))
isconcretetype(T) ? collect(T, gen) : collect(gen)
end

# Broadcasting is much faster for small testf, and computing
# integer indices from logical index using findall has a negligible cost
Expand Down
7 changes: 7 additions & 0 deletions test/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ end
@test findall(!iszero, x^2 for x in -1:0.5:1) == [1, 2, 4, 5]
@test argmin(x^2 for x in -1:0.5:1) == 3

# findall return type, see #45495
let gen = (i for i in 1:3);
@test @inferred(findall(x -> true, gen))::Vector{Int} == [1, 2, 3]
@test @inferred(findall(x -> false, gen))::Vector{Int} == Int[]
@test @inferred(findall(x -> x < 0, gen))::Vector{Int} == Int[]
end

# inference on vararg generator of a type (see #22907 comments)
let f(x) = collect(Base.Generator(=>, x, x))
@test @inferred(f((1,2))) == [1=>1, 2=>2]
Expand Down

2 comments on commit 162b9e9

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.

Please sign in to comment.