Low-level primitives for collapsed Gibbs sampling in python and C++