[
https://issues.apache.org/jira/browse/RNG-142?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17357866#comment-17357866
]
Alex Herbert commented on RNG-142:
----------------------------------
bq. Isn't it the purpose of a declaration such as ...
Yes. That type declaration allows the factory method constructor to be used as
a NormalizedGaussianSampler.
I tried to change the method to use a type to specify what is returned so you
can use it as a Gaussian sampler. This did not work:
{code:java}
public <S extends NormalizedGaussianSampler & SharedStateContinuousSampler> S
withUniformRandomProvider(UniformRandomProvider rng) {
return new ZigguratNormalizedGaussianSampler(rng);
}
{code}
Looking at the commit history the withUniformRandomProvider originally did
return ZigguratNormalizedGaussianSampler. It was then changed to return
SharedStateContinuousSampler when the class was changed to implement
SharedStateContinuousSampler as part of [RNG-110]. The ticket for that does not
have a reason. The SharedStateSampler and SharedStateContinuousSampler were
released together in v1.3. So this change happened during development. I cannot
remember the reason. It may have been to have a clean API always returning the
same type.
bq. could we just just change to a return-type declaration of
withUniformRandomProvider mentioning all the API?
With the new samplers in the shape package I return an instance of the same
class from the factory constructor and the withUniformRandomProvider method.
Perhaps we should update the entire API to return the most specific version of
the SharedStateSampler interface? I think this only effects the distribution
package. Is this what you mean?
> 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)