star-sp

Random number generators and distributions
git clone git://git.meso-star.fr/star-sp.git
Log | Files | Refs | README | LICENSE

commit ce70dd08d668a9765e3d401055714eb4cbffecaf
parent 81387afd63319f66c55c3563640a497de14b954f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 29 Nov 2017 10:25:10 +0100

Rename the proxy 'block' attributes in 'sequence'

Diffstat:
Msrc/ssp.h | 8++++----
Msrc/ssp_rng_proxy.c | 43+++++++++++++++++++++++--------------------
2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/src/ssp.h b/src/ssp.h @@ -239,10 +239,10 @@ SSP_API res_T ssp_rng_proxy_create2 (struct mem_allocator* mem_allocator, const struct ssp_rng_type* type, - const size_t block_offset, /* #RNs before the 1st valid block */ - const size_t block_size, /* #RNs in a block */ - const size_t block_pitch, /* #RNs between 2 consecutive blocks */ - const size_t nbuckets, /* #buckets in a block */ + const size_t sequence_offset, /* #RNs before the 1st valid sequence */ + const size_t sequence_size, /* #RNs in a sequence */ + const size_t sequence_pitch, /* #RNs between 2 consecutive sequence */ + const size_t nbuckets, /* #buckets in sequence */ struct ssp_rng_proxy** out_proxy); SSP_API res_T diff --git a/src/ssp_rng_proxy.c b/src/ssp_rng_proxy.c @@ -75,7 +75,7 @@ struct ssp_rng_proxy { /* The following arrays have the same size */ ATOMIC* buckets; /* Flag that defines which bucket RNGs are created */ - size_t block_bias; /* #RNs to discard between 2 consecutive pools */ + size_t sequence_bias; /* #RNs to discard between 2 consecutive sequence */ size_t bucket_size; /* #random numbers per bucket */ struct ssp_rng** pools; /* `type' RNGs wrapped by bucket RNGs */ struct rng_state_cache* states; /* Cache of `type' RNG states */ @@ -92,15 +92,16 @@ struct ssp_rng_proxy { * call, i.e. calling this function X times with the same bucket_id will * provide X different random pools. * - * bucket_size block_bias - * / \ / \ - * +-----+------------+- -+------------+----+------------+- - * |#####| Bucket 0 | ... | Bucket N-1 |####| Bucket 0 | ... - * |#####| 1st pool | | 1st pool |####| 2nd pool | - * +-----+------------+- -+------------+----+------------+- - * \ / \____________block_size_______/ - * block \___________block_pitch___________/ - * offset */ + * bucket_size sequence_bias + * / \ / \ + * +------+------------+- -+------------+----+------------+- + * |######| Bucket 0 | ... | Bucket N-1 |####| Bucket 0 | ... + * |######| 1st pool | | 1st pool |####| 2nd pool | + * +------+------------+- -+------------+----+------------+- + * \ / \_________sequence_size_______/ / + * sequence \________sequence_pitch__________/ + * offset + */ static struct ssp_rng* rng_proxy_next_ran_pool (struct ssp_rng_proxy* proxy, @@ -308,7 +309,8 @@ rng_proxy_next_ran_pool if(res != RES_OK) FATAL("RNG proxy: cannot write to state cache\n"); ssp_rng_discard(proxy->rng, proxy->bucket_size); } - ssp_rng_discard(proxy->rng, proxy->block_bias); + /* Discard RNs to reach the next sequence */ + ssp_rng_discard(proxy->rng, proxy->sequence_bias); } /* Read the RNG pool state of `bucket_name' */ @@ -400,10 +402,10 @@ res_T ssp_rng_proxy_create2 (struct mem_allocator* mem_allocator, const struct ssp_rng_type* type, - const size_t block_offset, /* #RNs before the 1st valid block */ - const size_t block_size, /* #RNs in a block */ - const size_t block_pitch, /* #RNs between 2 consecutive blocks */ - const size_t nbuckets, /* #buckets in a block */ + const size_t sequence_offset, /* #RNs before the 1st valid sequence */ + const size_t sequence_size, /* #RNs in a sequence */ + const size_t sequence_pitch, /* #RNs between 2 consecutive sequences */ + const size_t nbuckets, /* #buckets in a sequence */ struct ssp_rng_proxy** out_proxy) { struct mem_allocator* allocator = NULL; @@ -411,7 +413,8 @@ ssp_rng_proxy_create2 size_t i; res_T res = RES_OK; - if(!type || !out_proxy || !nbuckets) { + if(!type || !out_proxy || !sequence_size || sequence_pitch < sequence_size + || !nbuckets || sequence_size < nbuckets) { res = RES_BAD_ARG; goto error; } @@ -425,14 +428,14 @@ ssp_rng_proxy_create2 } proxy->allocator = allocator; ref_init(&proxy->ref); - proxy->bucket_size = block_size / nbuckets; - proxy->block_bias = block_pitch - (proxy->bucket_size * nbuckets); + proxy->bucket_size = sequence_size / nbuckets; + proxy->sequence_bias = sequence_pitch - (proxy->bucket_size * nbuckets); res = ssp_rng_create(allocator, type, &proxy->rng); if(res != RES_OK) goto error; proxy->type = *type; - res = ssp_rng_discard(proxy->rng, block_offset); + res = ssp_rng_discard(proxy->rng, sequence_offset); if(res != RES_OK) goto error; proxy->mutex = mutex_create(); @@ -488,7 +491,7 @@ ssp_rng_proxy_create_from_rng proxy->allocator = allocator; ref_init(&proxy->ref); proxy->bucket_size = BUCKET_SIZE_DEFAULT; - proxy->block_bias = 0; + proxy->sequence_bias = 1; res = ssp_rng_get_type(rng, &type); if(res != RES_OK) goto error;