Implement Fisher Yates algorithm#172
Conversation
402f667 to
7eaf4e7
Compare
|
Thanks for submitting a PR! I'll have a good look at it later but if you're open to it, you could look at a one-time test for randomness here: https://cnut1648.github.io/files/posts/Test_for_rand.pdf Basically, take the indices that are output by shuffleVec and take a look at the distribution. But that's might be overkill. |
| where | ||
| shuffleVec :: (RandomGen g) => g -> VU.Vector Int -> VU.Vector Int | ||
| shuffleVec g v = runST $ do | ||
| vm <- VU.thaw v |
There was a problem hiding this comment.
Instead of declaring the vector from list just to thaw it we can just create a new one in the shuffle vec function.
fc6f38a to
cc83918
Compare
Issue 170, implement PR comments and clean up build warnings
cc83918 to
3e69bd5
Compare
|
@kayvank this looks good. Rustin on some simple tests. Mostly that indices aren't dropped or duplicated and that it doesn't fail on empty. |
| shuffledIndices :: (RandomGen g) => g -> Int -> VU.Vector Int | ||
| shuffledIndices pureGen k = VU.fromList (shuffle' [0 .. (k - 1)] k pureGen) | ||
| shuffledIndices pureGen k | ||
| | k <= 0 = VU.empty |
There was a problem hiding this comment.
We return empty vector even when k is a negative number, which does not seen correct.
Should we error inf the rare event that k < 0? @mchav
There was a problem hiding this comment.
I think that's fine since the number is derived from the size of the dataframe. And the shuffle of an empty dataframe is an empty dataframe.
ff07a4e to
0b00734
Compare
Added two new unit tests. |
No description provided.