Replace convert_slice_{32,64} with read_u{32,64}_into - #77
Conversation
And a little cleanup around the init functions
| /// Reads unsigned 32 bit integers from `src` into `dst`. | ||
| /// Borrowed from the `byteorder` crate. | ||
| #[inline] | ||
| pub fn read_u32_into(src: &[u8], dst: &mut [u32]) { |
There was a problem hiding this comment.
Code looks fine. Oh, you copied the name from byteorder? I guess it'll do.
| unsafe { | ||
| let ptr = seed.as_mut_ptr() as *mut u8; | ||
| let slice = slice::from_raw_parts_mut(ptr, SEED_WORDS * 4); | ||
| other.try_fill(slice)?; |
There was a problem hiding this comment.
You're converting from bytes to u32 here. I think this will produce different results on BE CPUs? We went to all that trouble to make sure fill_bytes is portable, so I think this should be too. Maybe the best option is to use from_seed here :/
| unsafe { | ||
| let ptr = seed.as_mut_ptr() as *mut u8; | ||
| let slice = slice::from_raw_parts_mut(ptr, 8 * 4); | ||
| let slice = slice::from_raw_parts_mut(ptr, SEED_WORDS * 4); |
| let mut seed = [w(0); RAND_SIZE]; | ||
| unsafe { | ||
| let ptr = key.as_mut_ptr() as *mut u8; | ||
| let ptr = seed.as_mut_ptr() as *mut u8; |
| let mut seed = [w(0); RAND_SIZE]; | ||
| unsafe { | ||
| let ptr = key.as_mut_ptr() as *mut u8; | ||
| let ptr = seed.as_mut_ptr() as *mut u8; |
There was a problem hiding this comment.
All four are now share the same code 😄
|
I am not sure what you mean with feature creep.
I would argue that we should be able to rely on But making I played with |
|
I suppose we can just document that Of course both |
|
Thinking some more about it, a function that just works without pitfalls is worth more than a bit simpler implementation, or optimization on uncommon architectures (which are probably unmeasurable small for I will update the What did you mean with feature creep? |
|
My comments about requiring If we make Currently PRNGs implement |
|
But I agree this are minor advantages. I leave the call to you. Shall I leave |
|
No, your arguments make sense. Aside from one thing: surely the seed buffer passed to By portable I mean produces the same results everywhere, including in future versions. |
But is LLVM able to figure that out? If the functions are not inlined it has no choice but use slower unaligned copy functions. But that is something to try and play with, probably we can figure something out. Or just measure the impact, which may be tiny. |
|
I have added a commit that folds With some extra bounds on In Xorshift In |
|
Hang on, weren't you just arguing that |
|
I though you were thinking in the opposite direction, and I saw these advantages only as 'minor' 😄. How do you think it turned out? We do not seem to lose much, because it is possible to override the default implementation. |
|
The most significant change is that With specialisation we should be able to do a default implementation of |
|
Yes, true. I don't think it will cause big problems though. There is good documentation, requiring deterministic numbers is (I think) not that common, and the fix is to just import the right RNG. And now we have one less trait for users of |
|
In that case, is there even much point in having This brings up another point, the rationale for Note: almost all of this still needs merging into upstream, and needs some rationale. |
And I think we can say I am not sure if this is the right way to think about it, but to me the available methods in an API tell me how it is supposed to be used.
Not checked yet, but |
|
Good point about the error handling. All the distributions and Adding Ok, so we do want |
And a little cleanup around the init functions