I am trying to use uniform_real_distribution
from this C++ library in my cython script to generate a real random number from the uniform distribution between zero
and one
. This is my piece of code:
# Wrapper classes for random number generation
cdef extern from "boost/random/mersenne_twister.hpp" namespace "boost::random" nogil:
# random number generator
cdef cppclass mt19937:
#init
mt19937() nogil
#attributes
#methods
mt19937(unsigned int seed)
void seed(unsigned int seed)
cdef extern from "boost/random/uniform_real_distributio.hpp" namespace "boost::random" nogil:
cdef cppclass uniform_real_distribution[T]:
uniform_real_distribution()
uniform_real_distribution(T a, T b)
T operator()(mt19937 gen)
cdef mt19937 rng = mt19937(1)
cdef uniform_real_distribution[double] UnifDist = uniform_real_distribution[double](0.0,1.0)
u2 = UnifDist(rng)
My setup.py
script looks like this:
from distutils.core import setup
from distutils.extension import Extension
import numpy
from Cython.Distutils import build_ext
extra_compile_args = ['-fPIC']
extra_link_args = ['-Wall']
setup(
cmdclass = {'build_ext': build_ext},
ext_modules=[
Extension("test",
sources=["test.pyx"],
include_dirs=[numpy.get_include()],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)
],
gdb_debug=True)
The error message is
5: fatal error: boost/random/mersenne_twister.hpp: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status
What is the best way to generate a random number from a uniform distribution in cython? Plus, how can I import this library into my cython
script?
Aucun commentaire:
Enregistrer un commentaire