Skip to content

WIP: Adding the ability to pass a rng engine to armadillo

I noticed this issue initially when I was actually working on this patch for armadillo. Now that we have that behind and I can work with STL random on macOS, I thought I make a WIP merge request for it and explain what I want to achieve and why, and ask your opinion before I go any further.

In short, I'm trying to add a feature to Armadillo that allows the user to pass its own custom STL-like RNG engine to every rand, fill and generate function.

I think I grasped how you implemented the arma_rng and after studying the architecture of the arma_rng, arma_rng_cxx98 and arma_rng_cxx11, I patched as many rand and fill-related functions across several classes, Col, Row, Mat, Cube. I'm sure I've missed some detailed here and there and I deliberately left some stuffs behind, e.g., Gen class and fn_rand* until I know how you feel about this.

I've tried to not break the ABI and only extended the API. Basically, now most rand, fill, and generate function accepts a new template argument. For instance,

template<class URNG>
arma_inline
int
arma_rng_cxx11::randi_val(URNG& g)
{
    return i_distr(g);
}

For more complicated functions, or methods, I traced back everything and I think I managed to get most rand and fill methods working as well as gmm_*.generate() methods. For the fill::fill_type groups I introduced new types and wrapper to distinguish them from what’s already there but they can be simplified. After all this, if someone pass a rng engine to, for instance, gmm_full::generate(engine), the reference to the engine propagate to all underlying functions and be used instead of the arma_rng_cxx11::engine at the lowest level.

Btw, I'm aware of the imbue function but if I'm right it's not technically the same specially since armadillo internals' run on different rng chain, e.g., arma::gmm_full/diag. So, I thought this is a nice addition and it should seamlessly allows for integration of more advanced RNG engines if needed. I personally came across this since I wanted to use the same engine in my library and armadillo's gmm_full.generate() but it was not possible.

I am pretty sure I've not considered a lot of things and there are lot more works to be done for this to be finished but if you think this is a good idea, I can continue adapting more functions and methods to get it right. Or maybe you have a much better idea for achieving what I'm trying to achieve.

P.S. I think I rebase everything to the latest commit of the 9.800.x, let's hope I did that correctly.

Merge request reports