Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I replaced the inherently sequential
seed_arrof complexity O(k) with an embarrassingly parallel algorithm of O(k log k) complexity. We should create a seed array of length p (or a small multiple) if we have p processors, so the parallel runtimeO(log(p)) will always be smaller than the sequential time O(p).
I also changed the
seed_arrAPI to take any shape, rather than a number as argument. This way we can hide the ugly reshape workaround in Stdlib.The function
seed_arr(seed)computes[seed, seed + 1 * J, seed + 2 * J, ..., seed + k * J], where J is some large number. We can computeseed + Kin constant time, if we have precomputed a magic number for that K. The idea is to compute a table of length 32, that has the magic numbers for 2^(j) * J, j = 0, ..., 31. We can then advance the state k * J times in log_2(k) steps by decomposing k into b_0 * 2^0 + b_1 * 2^1 + ... + b_(log_2(k)) 2^(log_2(k)).I also push the sage code for computing the magic numbers, with references. This can be used to support other GF(2)-based PRNG's as well. The only math necessary to adjust this code, is the matrix form of the generator, all the ring-theory does not differ between generators.