JuliaSIMD / JuliaSIMD/Polyester.jl

at-batch iterating over more general iterators

Open
#18 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
285
Forks
20
PR merge metrics
No merged PRs in 30d

Description

I got another edge case for `@batch`:
```julia
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
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::Vector`s (or `v::AbstractArray`s, 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.