-
Notifications
You must be signed in to change notification settings - Fork 256
Description
In C++ standalone mode, we use the random generator mechanism from the C++ standard library, wrapped around in our own functions to get rand, randn, and poisson implementations. See #1559 for the PR that introduced this for C++ standalone mode. Note that the reason for using our own functions for rand and so on is that this way, we are generating exactly the same random numbers as before. In Cython, we are instead calling out to the numpy library (which under the hood does the same thing that we are doing in C++ standalone). It always asks for 20000 numbers at a time, to avoid going through numpy for every single number. It would be good to avoid this and use the same approach as C++ standalone mode. The C++ standalone code is distributed over a few files:
- the
objects.htemplate (note that it's in the same file asobjects.cppcontains the definition of theRandomGeneratorclass, which is wrapping the standard library function and adds therand,randn, andseedfunctionality - The
generate_rand_codefunction in thebrian2/devices/cpp_standalone/codeobject.pygenerates the actualrand/randnfunction definition – this is a bit more complicated than necessary for Cython, because in C++ mode we can run things in multiple threads and in that case we have more oneRandomGeneratorobject per thread. - The
cpp_generator.pyfile adds an implementation for thepoissonfunction (which calls out torand).
In principle, we should be able to reuse all this from the Cython code. The main obstacle is that we don't have the objects.h file, so we should move the RandomGenerator definition out of it and into an independent file that we can then use both from Cython and from C++ standalone mode.