Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong results with reduce #152

Open
xiaodaigh opened this issue Aug 29, 2020 · 1 comment
Open

Wrong results with reduce #152

xiaodaigh opened this issue Aug 29, 2020 · 1 comment

Comments

@xiaodaigh
Copy link

I am trying to count the number of unique in sorted array. The Base.reduce works as expected but ThreadsX.reduce gives the wrong result.

See

function unique_count_reduce_inner((cnt, last_a), new_a)
    cnt += (last_a != new_a)
    cnt, new_a
end

reduce_nunique(a) = reduce(unique_count_reduce_inner, a; init = (1, a[1]))[1]

using ThreadsX
treduce_nunique(a) = ThreadsX.reduce(unique_count_reduce_inner, a; init = (1, a[1]))[1]

a = rand(1_000_000)
sort!(a)
@time reduce_nunique(a) # 0.5
@time treduce_nunique(a) # 0.3
@jishnub
Copy link

jishnub commented Jul 12, 2021

Looks like init as a keyword argument is not supported.

julia> mapreduce(identity, +, 1:10, init = 100)
155

julia> ThreadsX.mapreduce(identity, +, 1:10, init = 100)
1055

init is used on each thread instead of only once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants