ranranrunforit's picture
download
raw
884 Bytes
"""
Use cffi to access any of the underlying C functions from distributions.h
"""
import os
import cffi
import numpy as np
from .parse import parse_distributions_h
ffi = cffi.FFI()
inc_dir = os.path.join(np.get_include(), 'numpy')
# Basic numpy types
ffi.cdef('''
typedef intptr_t npy_intp;
typedef unsigned char npy_bool;
''')
parse_distributions_h(ffi, inc_dir)
lib = ffi.dlopen(np.random._generator.__file__)
# Compare the distributions.h random_standard_normal_fill to
# Generator.standard_random
bit_gen = np.random.PCG64()
rng = np.random.Generator(bit_gen)
state = bit_gen.state
interface = rng.bit_generator.cffi
n = 100
vals_cffi = ffi.new('double[%d]' % n)
lib.random_standard_normal_fill(interface.bit_generator, n, vals_cffi)
# reset the state
bit_gen.state = state
vals = rng.standard_normal(n)
for i in range(n):
assert vals[i] == vals_cffi[i]

Xet Storage Details

Size:
884 Bytes
·
Xet hash:
7c97e323265835bcfece5bc4874225650de3a5c73cc56eca54e4bceccb23cee6

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.