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

Docs: Mutation examples incorrect/misleading #110

Closed
judober opened this issue Jun 16, 2024 · 1 comment · Fixed by #111
Closed

Docs: Mutation examples incorrect/misleading #110

judober opened this issue Jun 16, 2024 · 1 comment · Fixed by #111

Comments

@judober
Copy link

judober commented Jun 16, 2024

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
  1. 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
  1. 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.

@carstenbauer
Copy link
Member

@judober Hey, thanks for opening an issue. You're absolutely right and I agree with your proposed changes. Mind making a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants