Sampling algorithms for D
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Thu Apr 12 09:18:35 PDT 2012
Hi Dmitry,
Thanks for your thoughts and for pointing me at some aspects of D I'd not come
across before.
> I think that if you like function pointer thing, you'd love D's delegates and
> lambdas. If templates are too pervasive it might be better just use little bit
> of dynamic stuff.
I was not talking about function pointers. In GSL there is a struct type,
gsl_rng, which contains the RNG data; it's this that you pass around.
So e.g. in a C implementation I might have a function like
size_t sampler_select(sampler *s, gsl_rng *r) {
x = gsl_rng_uniform(r);
// do something with x ...
}
What I would like is for the sampler classes to be able to take an arbitrary
generator as input, or to use rndGen if one is not provided, analogous to what
the uniform() function in D's std.random does.
The current implementation of my classes seems imperfect to me (it ties the
class to using only one type of RNG, it means the whole class has to become
templated to the RNG type, ...).
> Use structs? They are cheap throwway value types allocated on stack (by default).
It's not a matter of cheap/expensive, just a matter of good design style (I seem
to recall seeing somewhere that init() functions were frowned upon). But if
there's no objection, I'll add an init function.
> It's OK. there are no implicit conversions of FP--> integer in the language I
> think.
Fine, then. :-)
>> (5) ... any general stylistic comments? :-)
>>
>
> Looks fine ;)
:-)
More information about the Digitalmars-d-learn
mailing list