lballabio / QuantLib-SWIG

QuantLib wrappers to other languages
Other
338 stars 282 forks source link

Added `ZigguratGaussianRng` #651

Closed ralfkonrad closed 2 months ago

ralfkonrad commented 2 months ago

Not sure if we can add it elsewhere?!

lballabio commented 2 months ago

I guess we could also export RandomSequenceGenerator<ZigguratGaussianRng<Xoshiro256StarStarUniformRng>>?

ralfkonrad commented 2 months ago

Okay, I'll give it a try.

ralfkonrad commented 2 months ago

Hm, it doesn't work out-of-the-box: template<class RNG> class RandomSequenceGenerator expects

RandomSequenceGenerator(Size dimensionality,
                        BigNatural seed = 0);

which translate into a missing constructor

explicit ZigguratGaussianRng<RNG>(BigNatural seed = 0);

We could add in SWIG something like

{%
template <class RNG>
class ZigguratGaussianRngExtension
    : public QuantLib::ZigguratGaussianRng<RNG> {
  public:
    ZigguratGaussianRngExtension(BigNatural seed = 0)
        : QuantLib::ZigguratGaussianRng<RNG>(RNG(seed)) {}
  };
%}

%template(ZigguratXoshiro256StarStarGaussianRsg)
    RandomSequenceGenerator<
        ZigguratGaussianRngExtension<Xoshiro256StarStarUniformRng>>;

which works but creates e.g. these artificial java classes like SWIGTYPE_p_ZigguratGaussianRngExtensionT_Xoshiro256StarStarUniformRng_t.

We could add the constructor explicit ZigguratGaussianRng<RNG>(BigNatural seed = 0); in QuantLib directly but that's also a bit dirty.

Any better idea?

lballabio commented 2 months ago

Added — I hid it behind a typedef and exported the available interface only.

ralfkonrad commented 2 months ago

Fine, thanks!