You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I played with some examples of the tranlation guide. The ones under Mutation seem incorrect.
Here the code in question:
# OhMyThreads
using OhMyThreads: @tasks
data = rand(10)
@tasks for i in 1:10
data[i] = calc(i)
end
# or
using OhMyThreads: tforeach
tforeach(data) do i
data[i] = calc(i)
end
# or
using OhMyThreads: tmap!
tmap!(data, data) do i # this kind of aliasing is fine
calc(i)
end
tforeach does not work. It errors as i (comming from data) cannot be used to index data. The only working case would be to have data = collect(1:10). I guess it would be best to change the example to be more similar to the @tasks case:
using OhMyThreads: tforeach
tforeach(1:10) do i
data[i] = calc(i)
end
the example with tmap works but is misleading as a novice use (like I) would assume i to be identical between the examples. But here it is the data and not the index. Also, the output would in general be different (depending on calc).
I propose to change it to
using OhMyThreads: tmap!
tmap!(data, 1:10) do i # this kind of aliasing is fine
calc(i)
end
It might be wiser to replace 1:10 with eachindex(data) but this applies to @tasks and @threads as well.
The text was updated successfully, but these errors were encountered:
I played with some examples of the tranlation guide. The ones under
Mutation
seem incorrect.Here the code in question:
tforeach
does not work. It errors asi
(comming fromdata
) cannot be used to indexdata
. The only working case would be to havedata = collect(1:10)
. I guess it would be best to change the example to be more similar to the@tasks
case:tmap
works but is misleading as a novice use (like I) would assumei
to be identical between the examples. But here it is the data and not the index. Also, the output would in general be different (depending oncalc
).I propose to change it to
It might be wiser to replace
1:10
witheachindex(data)
but this applies to@tasks
and@threads
as well.The text was updated successfully, but these errors were encountered: