-
Notifications
You must be signed in to change notification settings - Fork 244
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.h
template (note that it's in the same file asobjects.cpp
contains the definition of theRandomGenerator
class, which is wrapping the standard library function and adds therand
,randn
, andseed
functionality - The
generate_rand_code
function in thebrian2/devices/cpp_standalone/codeobject.py
generates the actualrand
/randn
function 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 oneRandomGenerator
object per thread. - The
cpp_generator.py
file adds an implementation for thepoisson
function (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.