Skip to content

Commit

Permalink
Merge pull request #378 from bashtage/remove-cimport-all
Browse files Browse the repository at this point in the history
Remove cimport all
  • Loading branch information
bashtage authored Sep 30, 2024
2 parents ab8661a + a8517fb commit 578219d
Show file tree
Hide file tree
Showing 54 changed files with 235 additions and 126 deletions.
15 changes: 14 additions & 1 deletion randomgen/aes.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# cython: binding=True, language_level=3
from randomgen.common cimport *

cimport numpy as np
from libc.stdint cimport uint8_t, uint32_t, uint64_t

from randomgen.common cimport (
BitGenerator,
PyArray_calloc_aligned,
PyArray_free_aligned,
fully_qualified_name,
int_to_array,
object_to_int,
uint64_to_double,
wrap_int,
)


cdef extern from "src/aesctr/aesctr.h":
Expand Down
1 change: 0 additions & 1 deletion randomgen/aes.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!python
import numpy as np

from randomgen.common cimport *
from randomgen._deprecated_value import _DeprecatedValue

__all__ = ["AESCounter"]
Expand Down
3 changes: 0 additions & 3 deletions randomgen/bounded_integers.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

import numpy as np

cimport numpy as np

from randomgen.distributions cimport *
from randomgen cimport api

__all__ = []
Expand Down
13 changes: 12 additions & 1 deletion randomgen/chacha.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# cython: binding=True, language_level=3

from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport (
BitGenerator,
PyArray_free_aligned,
PyArray_malloc_aligned,
fully_qualified_name,
int_to_array,
object_to_int,
view_little_endian,
)


cdef extern from "src/chacha/chacha.h":
Expand Down
2 changes: 0 additions & 2 deletions randomgen/chacha.pyx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!python
import numpy as np

from randomgen.common cimport *

from randomgen._deprecated_value import _DeprecatedValue

__all__ = ["ChaCha"]
Expand Down
2 changes: 1 addition & 1 deletion randomgen/common.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from cpython cimport PyFloat_AsDouble
from numpy.random.bit_generator cimport BitGenerator as _BitGenerator

from randomgen cimport api
from randomgen.common cimport *


from randomgen._deprecated_value import _DeprecatedValue
from randomgen.seed_sequence import ISeedSequence
Expand Down
12 changes: 11 additions & 1 deletion randomgen/dsfmt.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# cython: binding=True, language_level=3
from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport (
BitGenerator,
PyArray_calloc_aligned,
PyArray_free_aligned,
PyArray_malloc_aligned,
check_state_array,
fully_qualified_name,
)

DEF DSFMT_MEXP = 19937
DEF DSFMT_N = 191 # ((DSFMT_MEXP - 128) / 104 + 1)
Expand Down
3 changes: 1 addition & 2 deletions randomgen/dsfmt.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import operator

import numpy as np
cimport numpy as np

from randomgen._deprecated_value import _DeprecatedValue
from randomgen.common cimport *

__all__ = ["DSFMT"]

Expand Down
10 changes: 9 additions & 1 deletion randomgen/efiix64.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# cython: binding=True, language_level=3

from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport (
BitGenerator,
check_state_array,
fully_qualified_name,
uint64_to_double,
)

DEF INDIRECTION_SIZE = 16
DEF ITERATION_SIZE = 32
Expand Down
3 changes: 0 additions & 3 deletions randomgen/efiix64.pyx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!python
import numpy as np
cimport numpy as np

from randomgen.common cimport *

DEF INDIRECTION_SIZE = 16
DEF ITERATION_SIZE = 32
Expand Down
12 changes: 11 additions & 1 deletion randomgen/hc128.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# cython: binding=True, language_level=3
# coding=utf-8
from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport (
BitGenerator,
check_state_array,
fully_qualified_name,
int_to_array,
object_to_int,
view_little_endian,
)


cdef extern from "src/hc-128/hc-128.h":
Expand Down
2 changes: 0 additions & 2 deletions randomgen/hc128.pyx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!python
# coding=utf-8
import numpy as np
cimport numpy as np

from randomgen.common cimport *
from randomgen._deprecated_value import _DeprecatedValue

__all__ = ["HC128"]
Expand Down
5 changes: 4 additions & 1 deletion randomgen/jsf.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# cython: binding=True, language_level=3

from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport BitGenerator, fully_qualified_name, uint64_to_double


cdef extern from "src/jsf/jsf.h":
Expand Down
3 changes: 1 addition & 2 deletions randomgen/jsf.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


import numpy as np
cimport numpy as np

from randomgen._deprecated_value import _DeprecatedValue
from randomgen.common cimport *

__all__ = ["JSF"]

Expand Down
2 changes: 0 additions & 2 deletions randomgen/legacy/bounded_integers.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import numpy as np

cimport numpy as np

from randomgen.legacy.distributions cimport *

np.import_array()

_integers_types = {"bool": (0, 2),
Expand Down
10 changes: 9 additions & 1 deletion randomgen/lxm.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# cython: binding=True, language_level=3

from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport (
BitGenerator,
check_state_array,
fully_qualified_name,
uint64_to_double,
)


cdef extern from "src/lxm/lxm.h":
Expand Down
3 changes: 0 additions & 3 deletions randomgen/lxm.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

# coding=utf-8
import numpy as np
cimport numpy as np

from randomgen.common cimport *

__all__ = ["LXM"]

Expand Down
5 changes: 4 additions & 1 deletion randomgen/mt19937.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport BitGenerator, check_state_array, fully_qualified_name


cdef extern from "src/mt19937/mt19937.h":
Expand Down
3 changes: 1 addition & 2 deletions randomgen/mt19937.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import operator

import numpy as np
cimport numpy as np

from randomgen._deprecated_value import _DeprecatedValue
from randomgen.common cimport *

__all__ = ["MT19937"]

Expand Down
10 changes: 9 additions & 1 deletion randomgen/mt64.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# cython: binding=True, language_level=3

from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport (
BitGenerator,
check_state_array,
fully_qualified_name,
uint64_to_double,
)


cdef extern from "src/mt64/mt64.h":
Expand Down
2 changes: 0 additions & 2 deletions randomgen/mt64.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import operator

import numpy as np
cimport numpy as np

from randomgen.common cimport *
from randomgen._deprecated_value import _DeprecatedValue

__all__ = ["MT64"]
Expand Down
33 changes: 0 additions & 33 deletions randomgen/mtrand.pyx
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
#!python
#cython: wraparound=False, nonecheck=False, boundscheck=False, cdivision=True, language_level=3
import operator
from typing import MutableSequence
import warnings

import numpy as np

from randomgen.bounded_integers import _integers_types
from randomgen.mt19937 import MT19937 as _MT19937

cimport cython
from cpython cimport Py_INCREF, PyFloat_AsDouble
from cpython.pycapsule cimport PyCapsule_GetPointer, PyCapsule_IsValid
from libc cimport string

from randomgen cimport api
from randomgen.common cimport *
from randomgen.distributions cimport *
from randomgen.legacy.bounded_integers cimport *
from randomgen.legacy.distributions cimport *

from typing import Any, Callable

np.import_array()

cdef object int64_to_long(object x):
"""
Convert int64 to long for legacy compatibility, which used long for integer
distributions
"""
cdef int64_t x64

if np.isscalar(x):
x64 = x
return <long>x64
return x.astype("l", casting="unsafe")


cdef class RandomState:
"""
Expand Down
5 changes: 4 additions & 1 deletion randomgen/pcg32.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport BitGenerator, fully_qualified_name, wrap_int


cdef extern from "src/pcg32/pcg32.h":
Expand Down
2 changes: 0 additions & 2 deletions randomgen/pcg32.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#cython: binding=True

import numpy as np
cimport numpy as np

from randomgen.common cimport *
from randomgen._deprecated_value import _DeprecatedValue

__all__ = ["PCG32"]
Expand Down
12 changes: 11 additions & 1 deletion randomgen/pcg64.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport (
BitGenerator,
PyArray_free_aligned,
PyArray_malloc_aligned,
fully_qualified_name,
uint64_to_double,
wrap_int,
)


cdef extern from "src/pcg64/pcg64-common.h":
Expand Down
2 changes: 0 additions & 2 deletions randomgen/pcg64.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#cython: binding=True

import numpy as np
cimport numpy as np

from randomgen.common cimport *
from randomgen._deprecated_value import _DeprecatedValue

__all__ = ["PCG64", "LCG128Mix", "PCG64DXSM"]
Expand Down
12 changes: 12 additions & 0 deletions randomgen/philox.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport (
BitGenerator,
check_state_array,
fully_qualified_name,
int_to_array,
object_to_int,
uint64_to_double,
view_little_endian,
wrap_int,
)


cdef extern from "src/philox/philox.h":
struct s_r123array1x32:
Expand Down
12 changes: 12 additions & 0 deletions randomgen/philox.pxd.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport (
BitGenerator,
check_state_array,
fully_qualified_name,
int_to_array,
object_to_int,
uint64_to_double,
view_little_endian,
wrap_int,
)

{{
py:
N = (1, 2, 4)
Expand Down
1 change: 0 additions & 1 deletion randomgen/philox.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import numpy as np

from randomgen.common cimport *
from randomgen._deprecated_value import _DeprecatedValue

__all__ = ["Philox"]
Expand Down
5 changes: 4 additions & 1 deletion randomgen/rdrand.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from randomgen.common cimport *
cimport numpy as np
from libc.stdint cimport uint32_t, uint64_t

from randomgen.common cimport BitGenerator, fully_qualified_name, uint64_to_double

DEF BUFFER_SIZE = 256

Expand Down
Loading

0 comments on commit 578219d

Please sign in to comment.