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

Gilles Sadowski edited comment on RNG-142 at 6/5/21, 11:33 PM:
---------------------------------------------------------------

bq. This did not work [...]

:-(

bq. Perhaps we should update the entire API to return the most specific version 
of the SharedStateSampler interface?

You mean the actual class (not just the interface)?
It's the most flexible approach.  And if the implementations are in the public 
API anyways, there is no loss encapsulation.

This
{code}
    @Override
    public ZigguratNormalizedGaussianSampler
        withUniformRandomProvider(UniformRandomProvider rng) {
        return new ZigguratNormalizedGaussianSampler(rng);
    }

    public static ZigguratNormalizedGaussianSampler of(UniformRandomProvider 
rng) {
        return new ZigguratNormalizedGaussianSampler(rng);
    }
{code}
compiles (without generating a warning).


was (Author: erans):
bq. This did not work [...]

:-(

bq. Perhaps we should update the entire API to return the most specific version 
of the SharedStateSampler interface?

You mean the actual class (not just the interface)?
It's the most flexible approach.  And if the implementations are in the public 
API anyways, there is no loss encapsulation.

This
{code}
    /**                                                                         
                                                                                
               
     * {@inheritDoc}                                                            
                                                                                
               
     *                                                                          
                                                                                
               
     * @since 1.3                                                               
                                                                                
               
     */
    @Override
    public ZigguratNormalizedGaussianSampler
        withUniformRandomProvider(UniformRandomProvider rng) {
        return new ZigguratNormalizedGaussianSampler(rng);
    }

    /**                                                                         
                                                                                
               
     * Create a new normalised Gaussian sampler.                                
                                                                                
               
     *                                                                          
                                                                                
               
     * @param rng Generator of uniformly distributed random numbers.            
                                                                                
               
     * @return the sampler                                                      
                                                                                
               
     * @since 1.3                                                               
                                                                                
               
     */
    public static ZigguratNormalizedGaussianSampler of(UniformRandomProvider 
rng) {
        return new ZigguratNormalizedGaussianSampler(rng);
    }
{code}
compiles (without generating a warning).

> 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