Skip to content

Commit e527e71

Browse files
committed
API: rearrange the cython files in numpy.random
1 parent 007b323 commit e527e71

20 files changed

+282
-259
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ include tox.ini
1515
include .coveragerc
1616
include test_requirements.txt
1717
recursive-include numpy/random *.pyx *.pxd *.pyx.in *.pxd.in
18+
include numpy/random/include/*
1819
include numpy/__init__.pxd
1920
# Add build support that should go in sdist, but not go in bdist/be installed
2021
# Note that sub-directories that don't have __init__ are apparently not

numpy/random/bit_generator.pxd

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
2-
from .common cimport bitgen_t, uint32_t
31
cimport numpy as np
2+
from libc.stdint cimport uint32_t, uint64_t
3+
4+
cdef extern from "include/bitgen.h":
5+
struct bitgen:
6+
void *state
7+
uint64_t (*next_uint64)(void *st) nogil
8+
uint32_t (*next_uint32)(void *st) nogil
9+
double (*next_double)(void *st) nogil
10+
uint64_t (*next_raw)(void *st) nogil
11+
12+
ctypedef bitgen bitgen_t
413

514
cdef class BitGenerator():
615
cdef readonly object _seed_seq

numpy/random/bit_generator.pyx

-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ from cpython.pycapsule cimport PyCapsule_New
5353
import numpy as np
5454
cimport numpy as np
5555

56-
from libc.stdint cimport uint32_t
5756
from .common cimport (random_raw, benchmark, prepare_ctypes, prepare_cffi)
58-
from .distributions cimport bitgen_t
5957

6058
__all__ = ['SeedSequence', 'BitGenerator']
6159

numpy/random/bounded_integers.pyx.in

+44-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,54 @@
44
import numpy as np
55
cimport numpy as np
66

7-
from .distributions cimport *
8-
97
__all__ = []
108

119
np.import_array()
1210

11+
cdef extern from "include/distributions.h":
12+
# Generate random numbers in closed interval [off, off + rng].
13+
uint64_t random_bounded_uint64(bitgen_t *bitgen_state,
14+
uint64_t off, uint64_t rng,
15+
uint64_t mask, bint use_masked) nogil
16+
uint32_t random_buffered_bounded_uint32(bitgen_t *bitgen_state,
17+
uint32_t off, uint32_t rng,
18+
uint32_t mask, bint use_masked,
19+
int *bcnt, uint32_t *buf) nogil
20+
uint16_t random_buffered_bounded_uint16(bitgen_t *bitgen_state,
21+
uint16_t off, uint16_t rng,
22+
uint16_t mask, bint use_masked,
23+
int *bcnt, uint32_t *buf) nogil
24+
uint8_t random_buffered_bounded_uint8(bitgen_t *bitgen_state,
25+
uint8_t off, uint8_t rng,
26+
uint8_t mask, bint use_masked,
27+
int *bcnt, uint32_t *buf) nogil
28+
np.npy_bool random_buffered_bounded_bool(bitgen_t *bitgen_state,
29+
np.npy_bool off, np.npy_bool rng,
30+
np.npy_bool mask, bint use_masked,
31+
int *bcnt, uint32_t *buf) nogil
32+
void random_bounded_uint64_fill(bitgen_t *bitgen_state,
33+
uint64_t off, uint64_t rng, np.npy_intp cnt,
34+
bint use_masked,
35+
uint64_t *out) nogil
36+
void random_bounded_uint32_fill(bitgen_t *bitgen_state,
37+
uint32_t off, uint32_t rng, np.npy_intp cnt,
38+
bint use_masked,
39+
uint32_t *out) nogil
40+
void random_bounded_uint16_fill(bitgen_t *bitgen_state,
41+
uint16_t off, uint16_t rng, np.npy_intp cnt,
42+
bint use_masked,
43+
uint16_t *out) nogil
44+
void random_bounded_uint8_fill(bitgen_t *bitgen_state,
45+
uint8_t off, uint8_t rng, np.npy_intp cnt,
46+
bint use_masked,
47+
uint8_t *out) nogil
48+
void random_bounded_bool_fill(bitgen_t *bitgen_state,
49+
np.npy_bool off, np.npy_bool rng, np.npy_intp cnt,
50+
bint use_masked,
51+
np.npy_bool *out) nogil
52+
53+
54+
1355
_integers_types = {'bool': (0, 2),
1456
'int8': (-2**7, 2**7),
1557
'int16': (-2**15, 2**15),

numpy/random/common.pxd

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
#cython: language_level=3
22

3-
from libc.stdint cimport (uint8_t, uint16_t, uint32_t, uint64_t,
4-
int8_t, int16_t, int32_t, int64_t, intptr_t,
5-
uintptr_t)
6-
from libc.math cimport sqrt
7-
8-
cdef extern from "src/bitgen.h":
9-
struct bitgen:
10-
void *state
11-
uint64_t (*next_uint64)(void *st) nogil
12-
uint32_t (*next_uint32)(void *st) nogil
13-
double (*next_double)(void *st) nogil
14-
uint64_t (*next_raw)(void *st) nogil
15-
16-
ctypedef bitgen bitgen_t
3+
from libc.stdint cimport uint32_t, uint64_t, int32_t, int64_t
174

185
import numpy as np
196
cimport numpy as np
207

8+
from .bit_generator cimport bitgen_t
9+
2110
cdef double POISSON_LAM_MAX
2211
cdef double LEGACY_POISSON_LAM_MAX
2312
cdef uint64_t MAXSIZE
@@ -44,7 +33,7 @@ cdef object prepare_ctypes(bitgen_t *bitgen)
4433
cdef int check_constraint(double val, object name, constraint_type cons) except -1
4534
cdef int check_array_constraint(np.ndarray val, object name, constraint_type cons) except -1
4635

47-
cdef extern from "src/aligned_malloc/aligned_malloc.h":
36+
cdef extern from "include/aligned_malloc.h":
4837
cdef void *PyArray_realloc_aligned(void *p, size_t n)
4938
cdef void *PyArray_malloc_aligned(size_t n)
5039
cdef void *PyArray_calloc_aligned(size_t n, size_t s)

numpy/random/common.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import sys
66
import numpy as np
77
cimport numpy as np
88

9-
from .common cimport *
9+
from libc.stdint cimport uintptr_t
1010

1111
__all__ = ['interface']
1212

numpy/random/distributions.pxd

-140
This file was deleted.

0 commit comments

Comments
 (0)