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

Error with reduce #151

Open
xiaodaigh opened this issue Aug 20, 2020 · 0 comments
Open

Error with reduce #151

xiaodaigh opened this issue Aug 20, 2020 · 0 comments

Comments

@xiaodaigh
Copy link

I implemented a function with reduce and ThreadsX.reduce. The threads version failed.

using ThreadsX

feature = rand(Int, 1_000_000)
target = rand(Bool, 1_000_000)

function reduce_groupreduce(feature, target)
    zft = zip(feature, target)

    f_fold, t_fold = reduce((u, x) -> begin
        last_f = last(u[1])
        target_sum = last(u[2])

        f = x[1]
        t = x[2]

        if isequal(f, last_f)
            u[2][end] += t
        else
            push!(u[1], f)
            push!(u[2], t)
        end
        u
    end, zft;
    init = (feature[1:1], Int[0]))
end

@time reduce_groupreduce(feature, target) # this works


function reduce_groupreduce(feature, target)
    zft = zip(feature, target)

    f_fold, t_fold = ThreadsX.reduce((u, x) -> begin
        last_f = last(u[1])
        target_sum = last(u[2])

        f = x[1]
        t = x[2]

        if isequal(f, last_f)
            u[2][end] += t
        else
            push!(u[1], f)
            push!(u[2], t)
        end
        u
    end, zft;
    init = (feature[1:1], Int[0]))
end

@time reduce_groupreduce(feature, target) # this doesn't
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

1 participant