Don't use _mapreduce for countnz#13860
Conversation
|
Shouldn't we change function count1(pred, A::AbstractArray)
n = 0
@inbounds for a in A
n += pred(a)
end
return n
end
function countnz1(a)
n = 0
@inbounds for i in eachindex(a)
ai = a[i]
n = ifelse(ai == zero(ai), n, n + 1)
end
return n
endwith only the latter getting vectorized. (EDIT: with |
|
Ah, that's interesting: we only vectorize for i in eachindex(A)
@inbounds a = A[i]
...
endand not for a in A
...
endSeems like that should be fixable? CC @ArchRobison. |
|
Shouldn't the goal be to remove all functor object hacks? |
Isn't that what Jeff's doing in #13412? The |
|
We don't vectorize |
984188a to
6c66602
Compare
|
Ah, but I see in that case there is actually an |
|
I think the problem is that |
|
Really good find @simonster . |
|
I've just tried the change proposed by @timholy with the fix of @simonster and it is as fast as the version here so when the tests pass locally, I'll push @timholy's version. Is it necessary to have both the iterator and array version of |
6c66602 to
b2f0c6d
Compare
I'm not certain I see why, but I haven't looked at the code. |
|
Should this be |
b2f0c6d to
66df1af
Compare
|
Maybe even |
|
Is it necessary to have |
|
I thought it was for something like julia> count(t -> t == 3, rand(1:3, 10))
3 |
|
Does that differ from |
|
Ha. I didn't know about the map version of |
|
...but |
|
I tried to remove |
Don't use _mapreduce for countnz
This was a surprising bottleneck in some of my code. Before I got
and with this change