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

re-evaluate/remove Random.UnsafeView #36718

Open
JeffBezanson opened this issue Jul 17, 2020 · 6 comments
Open

re-evaluate/remove Random.UnsafeView #36718

JeffBezanson opened this issue Jul 17, 2020 · 6 comments
Labels
domain:randomness Random number generation and the Random stdlib kind:good first issue Indicates a good issue for first-time contributors to Julia status:help wanted Indicates that a maintainer wants help on an issue or pull request stdlib Julia's standard library

Comments

@JeffBezanson
Copy link
Sponsor Member

I just noticed the Random stdlib has an UnsafeView type for filling arrays. With the new layout optimizations, this should no longer be necessary. We should try using the normal SubArray type for this. If it's still too slow/complex, then at least the type can be made safe by holding the underlying array directly instead of a Ptr.

@JeffBezanson JeffBezanson added status:help wanted Indicates that a maintainer wants help on an issue or pull request domain:randomness Random number generation and the Random stdlib kind:good first issue Indicates a good issue for first-time contributors to Julia stdlib Julia's standard library labels Jul 17, 2020
@kimikage

This comment has been minimized.

@DebadityaPal
Copy link
Contributor

I would like to work on this issue.

@DebadityaPal
Copy link
Contributor

In the file stdlib/Random/src/RNGs.jl, there exists a line of code(Line 524)

GC.@preserve r unsafe_copyto!(A.ptr, pointer(r.vals, r.idxF+1), m)

it looks like some values are being copied into A which is an UnsafeView, however the source of the values are r.idfX+1 which is one element after the r.vals vector ends. I am a bit confused as to why values are being copied from a memory location after the end of the vector. Could you please guide me a bit?

@rfourquet
Copy link
Member

the source of the values are r.idfX+1 which is one element after the r.vals vector ends.

Why do you think so? r.idxF acts as a pointer into r.vals and indicates how many values in r.vals have been consumed. So here r.idxF + 1 points at the first non-consumed values, and m is the number of non-consumed values.

@DebadityaPal
Copy link
Contributor

oh okay, thanks for the explanation, now it makes sense.

@DebadityaPal
Copy link
Contributor

DebadityaPal commented Nov 6, 2020

A lot of the times the Structure of UnsafeView is being used to typecast the data in the memory for example by putting a Array{bool} into an UnsafeView{Int128} like in Line 697 of stdlib/Random/src/RNGs.jl. Are there any such explicit typecasting functions for SubArrays? My reading of the docs were inconclusive. I have tried using the Base.convert function but it fails to do these kinds of SubArray conversions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:randomness Random number generation and the Random stdlib kind:good first issue Indicates a good issue for first-time contributors to Julia status:help wanted Indicates that a maintainer wants help on an issue or pull request stdlib Julia's standard library
Projects
None yet
Development

No branches or pull requests

4 participants