Sampling algorithms for D

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Thu Apr 12 15:34:38 PDT 2012


On 12/04/12 21:54, bearophile wrote:
>>      sampling_test_simple!(VitterA!Random,Random)(100,5,urng);
>
> Currently your code doesn't work if you want to use a Xorshift generator.

Ahhh, I see what you mean now -- the sampler classes are fine, but the way the 
main() function is written means you can't just tweak the RNG.

The original code I tried writing was something like,

     sampling_test_simple!(VitterA, Random)(100, 5, urng);

... with the sampler object being created in the function with,

     auto s = new SamplerType!UniformRNG(records, samples, urng);

... but the compiler objected to that with the error,

     sampled.d:216: Error: template instance
     sampling_test_simple!(VitterA,XorshiftEngine!(uint,128,11,8,19))
     does not match template declaration
     sampling_test_simple(SamplerType,UniformRNG)

Here's the complete (wrong) function:

void sampling_test_simple(SamplerType, UniformRNG)
                          (size_t records, size_t samples, ref UniformRNG urng)
{
       auto s = new SamplerType!UniformRNG(records,samples,urng);
       while(s.sampleRemaining > 0) {
             write("\trecord selected: ", s.select(urng), ".");
             write("\trecords remaining: ", s.recordsRemaining, ".");
             writeln("\tstill to sample: ", s.sampleRemaining, ".");
       }
}

It's not clear to me why this fails or what I can do that would equate to this.


More information about the Digitalmars-d-learn mailing list