[
https://issues.apache.org/jira/browse/RNG-142?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17357836#comment-17357836
]
Gilles Sadowski edited comment on RNG-142 at 6/5/21, 11:12 AM:
---------------------------------------------------------------
{quote}Many could be changed to return the type of the implementing class.
{quote}
Indeed, that was my observation. From a caller's POV,
{{withUniformRandomProvider}} substitutes the {{uniformRandomProvider}}
instance while leaving the rest unchanged; hence the cleanest is to return the
same class.
{quote}However some use a delegate of a different class to perform the sampling
{quote}
How do such "internal details" change the user's POV (API usage)? I mean,
substituting the provider should not reduce the API (in this case:
{{NormalizedGaussianSampler}}).
Isn't it the purpose of a declaration such as:
{code:java}
public static <S extends NormalizedGaussianSampler &
SharedStateContinuousSampler> S of(UniformRandomProvider rng) {
return (S) new ZigguratNormalizedGaussianSampler(rng);
}
{code}
?
{quote}[...] change requires adding a type
{quote}
Is your proposal intended to avoid the above cast and annotation?
Or could we just just change to a return-type declaration of
{{withUniformRandomProvider}} mentioning all the API? AFACT, this problem
exists only for the {{NormalizedGaussianSampler}} implementations.
was (Author: erans):
bq. Many could be changed to return the type of the implementing class.
Indeed, that was my observation. From a caller's POV,
{{withUniformRandomProvider}} substitutes the {{uniformRandomProvider}}
instance while leaving the rest unchanged; hence the cleanest is to return the
same class.
bq. However some use a delegate of a different class to perform the sampling
How do such "internal details" change the user's POV (API usage)? I mean,
substituting the provider should not reduce the API (in this case:
{{NormalizedGaussianSampler}}).
Isn't it the purpose of a declaration such as:
{code}
public static <S extends NormalizedGaussianSampler &
SharedStateContinuousSampler> S of(UniformRandomProvider rng) {
return (S) new ZigguratNormalizedGaussianSampler(rng);
}
{code}
?
bq. [...] change requires adding a type
Is your proposal intended to avoid the above cast and annotation?
Or could we just just change to a return-type declaration of
{{withUniformRandomProvider}} mentioning all the API? [AFACT, this problem
exists only for the {{NormalizedGaussianSampler}} implementations.]
> 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)