Polyester.jl
Polyester.jl copied to clipboard
at-batch iterating over more general iterators
I got another edge case for @batch:
julia> using Pkg; Pkg.status("CheapThreads")
Status `/tmp/jl_es2knB/Project.toml`
[b630d9fa] CheapThreads v0.2.0
julia> Threads.nthreads()
2
julia> using CheapThreads, Test
julia> function issue18!(dest)
@assert length(dest) == 3
@assert dest[1] == 1
@batch for i in 2:3
dest[i] = i
end
@test dest ≈ 1:3
end
issue18! (generic function with 1 method)
julia> dest = ones(3)
3-element Vector{Float64}:
1.0
1.0
1.0
julia> issue18!(dest)
Test Failed at REPL[7]:7
Expression: dest ≈ 1:3
Evaluated: [1.0, 1.0, 1.0] ≈ 1:3
ERROR: There was an error during testing
I would have expected the same output as from
julia> function issue18!(dest)
@assert length(dest) == 3
@assert dest[1] == 1
Threads.@threads for i in 2:3
dest[i] = i
end
@test dest ≈ 1:3
end
issue18! (generic function with 1 method)
julia> issue18!(dest)
Test Passed
Another related issue: I noticed that @batch requires the iterator to be an OrdinalRange (or something similar implementing step). That's of course a good way for performance optimizations and therefore a reasonable restriction. Some syntactic sugar might be to also allow iterating over v::Vectors (or v::AbstractArrays, maybe restricted to ones using linear indexing) by reducing that to an iteration over eachindex(v). But that's also something I can easily work around in my applications.
Fixed the example issue and added it to the tests.
But that's also something I can easily work around in my applications.
Or make a PR here.
Great, thanks :+1: