Skip to content

Document our restrictions on the init kwarg #144

@christiangnrd

Description

@christiangnrd

Also reported at JuliaGPU/AcceleratedKernels.jl#28.

Examples:

julia> using OhMyThreads

julia> scheduler = StaticScheduler(; chunksize = 2, split = :batch)
StaticScheduler
├ Chunking: fixed size (2), split :consecutive
└ Threadpool: default

julia> sumvec = [1, 1, 1, 1, 1];

julia> treduce(+, sumvec; scheduler, init=0.0) # Correct
5.0

julia> reduce(+, sumvec; init=0.0) # Correct
5.0

julia> treduce(+, sumvec; scheduler, init=1.0) # Incorrect
8.0

julia> reduce(+, sumvec; init=1.0)
6.0

julia> vcatvec = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0], [7.0, 8.0]];

julia> treduce(vcat, vcatvec; scheduler, init=Float64[]) # Correct
8-element Vector{Float64}:
 1.0
 2.0
 3.0
 4.0
 5.0
 6.0
 7.0
 8.0

julia> reduce(vcat, vcatvec; init=Float64[]) # Correct
8-element Vector{Float64}:
 1.0
 2.0
 3.0
 4.0
 5.0
 6.0
 7.0
 8.0

julia> treduce(vcat, vcatvec; scheduler, init=Float64[0.0]) # Incorrect
10-element Vector{Float64}:
 0.0
 1.0
 2.0
 3.0
 4.0
 0.0 <- WRONG
 5.0
 6.0
 7.0
 8.0

julia> reduce(vcat, vcatvec; init=Float64[0.0]) # Correct
9-element Vector{Float64}:
 0.0
 1.0
 2.0
 3.0
 4.0
 5.0
 6.0
 7.0
 8.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions