[
https://issues.apache.org/jira/browse/RNG-102?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Alex D Herbert resolved RNG-102.
--------------------------------
Resolution: Implemented
Assignee: Alex D Herbert
Fix Version/s: 1.3
In master.
> SharedStateSampler interface
> ----------------------------
>
> Key: RNG-102
> URL: https://issues.apache.org/jira/browse/RNG-102
> Project: Commons RNG
> Issue Type: New Feature
> Components: sampling
> Affects Versions: 1.3
> Reporter: Alex D Herbert
> Assignee: Alex D Herbert
> Priority: Minor
> Fix For: 1.3
>
> Time Spent: 40m
> Remaining Estimate: 0h
>
> Nearly all the samplers in the library compute data during construction that
> is immutable. In most cases the data is small in size but could be large
> (e.g. a discrete probability sampler with a stored cumulative probability
> table). To build another sampler with the same parameters will have to
> re-compute this state. The only difference between the two samplers is the
> random generator.
> Reusing this state to create a duplicate generator is an advantage for lower
> construction cost and will save memory. This can be done using a generic
> interface:
> {code:java}
> public interface SharedStateSampler<R> {
> R withUniformRandomProvider(UniformRandomProvider rng);
> }
> {code}
> R is expected to be a sampler of some type, e.g.
> {code:java}
> public class CollectionSampler<T>
> implements SharedStateSampler<CollectionSampler<T>> {
> // ...
> public CollectionSampler<T>
> withUniformRandomProvider(UniformRandomProvider rng) {
> return /* new instance that shares the immutable state */;
> }
> }
> {code}
> An example application would be to create a single sampler to be duplicated
> across threads for parallel computation using a unique RNG per thread.
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)