[ 
https://issues.apache.org/jira/browse/RNG-142?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17358105#comment-17358105
 ] 

Alex Herbert commented on RNG-142:
----------------------------------

Running {{clirr:check}} with the same change also reports binary 
incompatibility.

Can we solve this using javadoc? E.g. Add a note that the call to 
withUniformRandomProvider returns a SharedStateContinuousSampler but it can be 
cast to the original Gaussian sampler type. This applies to:

* BoxMullerNormalizedGaussianSampler

* MarsagliaNormalizedGaussianSampler

* ZigguratNormalizedGaussianSampler

It appears to that this mainly applies to the normalized Gaussian samplers as 
these must be handed to the GaussianSampler class as a 
NormalizedGaussianSampler and not a SharedStateContinuousSampler.

Also note that this is functionally equivalent to your original example where 
you have a normalized Gaussian sampler and you wish to switch the underlying 
RNG for use in a Gaussian sampler:
{code:java}
// This could be any normalized Gaussian sampler
NormalizedGaussianSampler algorithm =
    new ZigguratNormalizedGaussianSampler(null);

// Switch the RNG
SharedStateContinuousSampler g =
    GaussianSampler.of(algorithm, 0.43, 2.1)
    .withUniformRandomProvider(RandomSource.create(RandomSource.JSF_64));

{code}
Here the choice of normalized Gaussian sampler can be made by code somewhere 
else. Note that in this case if the 'algorithm' passed to the GaussianSampler 
does not also implement SharedStateContinuousSampler then an 
UnsupportedOperationException will occur when calling 
withUniformRandomProvider. This is documented in the GaussianSampler javadoc.

 

> Return type of method "withUniformRandomProvider"
> -------------------------------------------------
>
>                 Key: RNG-142
>                 URL: https://issues.apache.org/jira/browse/RNG-142
>             Project: Commons RNG
>          Issue Type: Improvement
>          Components: sampling
>            Reporter: Gilles Sadowski
>            Priority: Major
>
> Expected usage:
> {code:java}
> NormalizedGaussianSampler n01 = 
> ZigguratNormalizedGaussianSampler.of(RandomSource.create(RandomSource.KISS));
> GaussianSampler g = 
> GaussianSampler.of(n01.withUniformRandomProvider(RandomSource.create(RandomSource.JSF_64)),
>  0.43, 2.1);
> {code}
> Code doesn't compile: Method {{withUniformRandomProvider}} returns a 
> {{SharedStateContinuousSampler}} whereas a {{NormalizedGaussianSampler}} is 
> required.
> Am I missing something?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to