-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
DOC: Clean up examples of low-level random access #14951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
r""" | ||
On *nix, execute in randomgen/src/distributions | ||
Building the required library in this example requires a source distribution | ||
of NumPy or clone of the NumPy git repository since distributions.c is not | ||
included in binary distributions. | ||
|
||
On *nix, execute in numpy/random/src/distributions | ||
|
||
export ${PYTHON_VERSION}=3.8 # Python version | ||
export PYTHON_INCLUDE=#path to Python's include folder, usually \ | ||
${PYTHON_HOME}/include/python${PYTHON_VERSION}m | ||
export NUMPY_INCLUDE=#path to numpy's include folder, usually \ | ||
${PYTHON_HOME}/lib/python${PYTHON_VERSION}/site-packages/numpy/core/include | ||
gcc -shared -o libdistributions.so -fPIC distributions.c \ | ||
-I${NUMPY_INCLUDE} -I${PYTHON_INCLUDE} | ||
mv libdistributions.so ../../examples/numba/ | ||
mv libdistributions.so ../../_examples/numba/ | ||
|
||
On Windows | ||
|
||
rem PYTHON_HOME is setup dependent, this is an example | ||
rem PYTHON_HOME and PYTHON_VERSION are setup dependent, this is an example | ||
set PYTHON_HOME=c:\Anaconda | ||
set PYTHON_VERSION=38 | ||
cl.exe /LD .\distributions.c -DDLL_EXPORT \ | ||
-I%PYTHON_HOME%\lib\site-packages\numpy\core\include \ | ||
-I%PYTHON_HOME%\include %PYTHON_HOME%\libs\python36.lib | ||
move distributions.dll ../../examples/numba/ | ||
-I%PYTHON_HOME%\include %PYTHON_HOME%\libs\python%PYTHON_VERSION%.lib | ||
move distributions.dll ../../_examples/numba/ | ||
""" | ||
import os | ||
|
||
|
@@ -35,19 +41,19 @@ | |
raise RuntimeError('Required DLL/so file was not found.') | ||
|
||
ffi.cdef(""" | ||
double random_gauss_zig(void *bitgen_state); | ||
double random_standard_normal(void *bitgen_state); | ||
""") | ||
x = PCG64() | ||
xffi = x.cffi | ||
bit_generator = xffi.bit_generator | ||
|
||
random_gauss_zig = lib.random_gauss_zig | ||
random_standard_normal = lib.random_standard_normal | ||
|
||
|
||
def normals(n, bit_generator): | ||
out = np.empty(n) | ||
for i in range(n): | ||
out[i] = random_gauss_zig(bit_generator) | ||
out[i] = random_standard_normal(bit_generator) | ||
return out | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we could run this as part of the tests, like we run the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depends on numba or at least CFFI, so probably not worth it. But definitely a risk that examples get stale, so ideally these things get run somewhere. |
||
|
Uh oh!
There was an error while loading. Please reload this page.