From 6518f6e4a9db0a2810636a2afa3306486b91937f Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Mon, 30 Sep 2024 15:28:45 +0100 Subject: [PATCH 1/2] MAINT: Start removing * imports --- randomgen/_pickle.py | 1 + randomgen/xoroshiro128.pxd | 10 +++++++++- randomgen/xoroshiro128.pyx | 2 -- randomgen/xorshift1024.pxd | 10 +++++++++- randomgen/xorshift1024.pyx | 2 -- randomgen/xoshiro256.pxd | 10 +++++++++- randomgen/xoshiro256.pyx | 2 -- randomgen/xoshiro512.pxd | 10 +++++++++- randomgen/xoshiro512.pyx | 2 -- setup.cfg | 4 ++-- 10 files changed, 39 insertions(+), 14 deletions(-) diff --git a/randomgen/_pickle.py b/randomgen/_pickle.py index 8a5c3ffb2..e2aea0729 100644 --- a/randomgen/_pickle.py +++ b/randomgen/_pickle.py @@ -21,6 +21,7 @@ from randomgen.sfc import SFC64 from randomgen.sfmt import SFMT from randomgen.speck128 import SPECK128 + from randomgen.threefry import ThreeFry from randomgen.tyche import Tyche from randomgen.xoroshiro128 import Xoroshiro128 diff --git a/randomgen/xoroshiro128.pxd b/randomgen/xoroshiro128.pxd index 3a087c032..eeb770f26 100644 --- a/randomgen/xoroshiro128.pxd +++ b/randomgen/xoroshiro128.pxd @@ -1,4 +1,12 @@ -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/xoroshiro128/xoroshiro128.h": diff --git a/randomgen/xoroshiro128.pyx b/randomgen/xoroshiro128.pyx index 3c03c0c70..9e438f875 100644 --- a/randomgen/xoroshiro128.pyx +++ b/randomgen/xoroshiro128.pyx @@ -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__ = ["Xoroshiro128"] diff --git a/randomgen/xorshift1024.pxd b/randomgen/xorshift1024.pxd index 05a01d4d4..654277ae1 100644 --- a/randomgen/xorshift1024.pxd +++ b/randomgen/xorshift1024.pxd @@ -1,4 +1,12 @@ -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/xorshift1024/xorshift1024.h": diff --git a/randomgen/xorshift1024.pyx b/randomgen/xorshift1024.pyx index cfdddff6b..af17078a0 100644 --- a/randomgen/xorshift1024.pyx +++ b/randomgen/xorshift1024.pyx @@ -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__ = ["Xorshift1024"] diff --git a/randomgen/xoshiro256.pxd b/randomgen/xoshiro256.pxd index fa8d52c7b..1e8d6c06c 100644 --- a/randomgen/xoshiro256.pxd +++ b/randomgen/xoshiro256.pxd @@ -1,4 +1,12 @@ -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/xoshiro256/xoshiro256.h": diff --git a/randomgen/xoshiro256.pyx b/randomgen/xoshiro256.pyx index d42f07c63..efb12816f 100644 --- a/randomgen/xoshiro256.pyx +++ b/randomgen/xoshiro256.pyx @@ -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__ = ["Xoshiro256"] diff --git a/randomgen/xoshiro512.pxd b/randomgen/xoshiro512.pxd index 940eedd4e..49fe67ade 100644 --- a/randomgen/xoshiro512.pxd +++ b/randomgen/xoshiro512.pxd @@ -1,4 +1,12 @@ -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/xoshiro512/xoshiro512.h": diff --git a/randomgen/xoshiro512.pyx b/randomgen/xoshiro512.pyx index 6173212f2..4f8a6b92c 100644 --- a/randomgen/xoshiro512.pyx +++ b/randomgen/xoshiro512.pyx @@ -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__ = ["Xoshiro512"] diff --git a/setup.cfg b/setup.cfg index 7fa61291c..514395920 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,12 +4,12 @@ license_files = LICENSE.md [pycodestyle] -max-line-length = 88 +max-line-length = 97 statistics = True ignore = E203, E301, E302, E305, E501, E701, W503 [flake8] -max-line-length = 88 +max-line-length = 97 extend-ignore = E203, E301, E302, E305 per-file-ignores = */randomgen/tests/data/stable_hashes.py: E501 From a8517fba5743172c9978f95f48b7d07c71224613 Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Mon, 30 Sep 2024 16:07:35 +0100 Subject: [PATCH 2/2] FInish removing * imports --- randomgen/_pickle.py | 1 - randomgen/aes.pxd | 15 ++++++++++- randomgen/aes.pyx | 1 - randomgen/bounded_integers.pyx.in | 3 --- randomgen/chacha.pxd | 13 +++++++++- randomgen/chacha.pyx | 2 -- randomgen/common.pyx | 2 +- randomgen/dsfmt.pxd | 12 ++++++++- randomgen/dsfmt.pyx | 3 +-- randomgen/efiix64.pxd | 10 ++++++- randomgen/efiix64.pyx | 3 --- randomgen/hc128.pxd | 12 ++++++++- randomgen/hc128.pyx | 2 -- randomgen/jsf.pxd | 5 +++- randomgen/jsf.pyx | 3 +-- randomgen/legacy/bounded_integers.pyx.in | 2 -- randomgen/lxm.pxd | 10 ++++++- randomgen/lxm.pyx | 3 --- randomgen/mt19937.pxd | 5 +++- randomgen/mt19937.pyx | 3 +-- randomgen/mt64.pxd | 10 ++++++- randomgen/mt64.pyx | 2 -- randomgen/mtrand.pyx | 33 ------------------------ randomgen/pcg32.pxd | 5 +++- randomgen/pcg32.pyx | 2 -- randomgen/pcg64.pxd | 12 ++++++++- randomgen/pcg64.pyx | 2 -- randomgen/philox.pxd | 12 +++++++++ randomgen/philox.pxd.in | 12 +++++++++ randomgen/philox.pyx | 1 - randomgen/rdrand.pxd | 5 +++- randomgen/rdrand.pyx | 11 +------- randomgen/romu.pxd | 5 +++- randomgen/romu.pyx | 7 ----- randomgen/sfc.pxd | 5 +++- randomgen/sfc.pyx | 2 -- randomgen/sfmt.pxd | 13 +++++++++- randomgen/sfmt.pyx | 6 +---- randomgen/speck128.pxd | 15 ++++++++++- randomgen/speck128.pyx | 1 - randomgen/threefry.pxd | 12 +++++++++ randomgen/threefry.pxd.in | 12 +++++++++ randomgen/threefry.pyx | 1 - randomgen/tyche.pxd | 5 +++- randomgen/tyche.pyx | 5 ---- randomgen/wrapper.pyx | 4 ++- 46 files changed, 197 insertions(+), 113 deletions(-) diff --git a/randomgen/_pickle.py b/randomgen/_pickle.py index e2aea0729..8a5c3ffb2 100644 --- a/randomgen/_pickle.py +++ b/randomgen/_pickle.py @@ -21,7 +21,6 @@ from randomgen.sfc import SFC64 from randomgen.sfmt import SFMT from randomgen.speck128 import SPECK128 - from randomgen.threefry import ThreeFry from randomgen.tyche import Tyche from randomgen.xoroshiro128 import Xoroshiro128 diff --git a/randomgen/aes.pxd b/randomgen/aes.pxd index 0dc85c394..ac68f758f 100644 --- a/randomgen/aes.pxd +++ b/randomgen/aes.pxd @@ -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": diff --git a/randomgen/aes.pyx b/randomgen/aes.pyx index 78c99d360..91adaff32 100644 --- a/randomgen/aes.pyx +++ b/randomgen/aes.pyx @@ -1,7 +1,6 @@ #!python import numpy as np -from randomgen.common cimport * from randomgen._deprecated_value import _DeprecatedValue __all__ = ["AESCounter"] diff --git a/randomgen/bounded_integers.pyx.in b/randomgen/bounded_integers.pyx.in index 0177546da..983087759 100644 --- a/randomgen/bounded_integers.pyx.in +++ b/randomgen/bounded_integers.pyx.in @@ -3,9 +3,6 @@ import numpy as np -cimport numpy as np - -from randomgen.distributions cimport * from randomgen cimport api __all__ = [] diff --git a/randomgen/chacha.pxd b/randomgen/chacha.pxd index 92fc2f5fb..74c81bfde 100644 --- a/randomgen/chacha.pxd +++ b/randomgen/chacha.pxd @@ -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": diff --git a/randomgen/chacha.pyx b/randomgen/chacha.pyx index 079cb0920..91d471ac7 100644 --- a/randomgen/chacha.pyx +++ b/randomgen/chacha.pyx @@ -1,8 +1,6 @@ #!python import numpy as np -from randomgen.common cimport * - from randomgen._deprecated_value import _DeprecatedValue __all__ = ["ChaCha"] diff --git a/randomgen/common.pyx b/randomgen/common.pyx index 148f3d524..3845b5373 100644 --- a/randomgen/common.pyx +++ b/randomgen/common.pyx @@ -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 diff --git a/randomgen/dsfmt.pxd b/randomgen/dsfmt.pxd index 9290d7666..24d1bf47c 100644 --- a/randomgen/dsfmt.pxd +++ b/randomgen/dsfmt.pxd @@ -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) diff --git a/randomgen/dsfmt.pyx b/randomgen/dsfmt.pyx index fe72c93f4..ff443ebc4 100644 --- a/randomgen/dsfmt.pyx +++ b/randomgen/dsfmt.pyx @@ -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"] diff --git a/randomgen/efiix64.pxd b/randomgen/efiix64.pxd index 863e1282f..b9e968098 100644 --- a/randomgen/efiix64.pxd +++ b/randomgen/efiix64.pxd @@ -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 diff --git a/randomgen/efiix64.pyx b/randomgen/efiix64.pyx index 9c3b561cc..0cf6f1adc 100644 --- a/randomgen/efiix64.pyx +++ b/randomgen/efiix64.pyx @@ -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 diff --git a/randomgen/hc128.pxd b/randomgen/hc128.pxd index f615b7ed5..dd0bf72e4 100644 --- a/randomgen/hc128.pxd +++ b/randomgen/hc128.pxd @@ -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": diff --git a/randomgen/hc128.pyx b/randomgen/hc128.pyx index ce4a41c12..f5c115a5c 100644 --- a/randomgen/hc128.pyx +++ b/randomgen/hc128.pyx @@ -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"] diff --git a/randomgen/jsf.pxd b/randomgen/jsf.pxd index 9dbf887b0..79417a333 100644 --- a/randomgen/jsf.pxd +++ b/randomgen/jsf.pxd @@ -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": diff --git a/randomgen/jsf.pyx b/randomgen/jsf.pyx index 24f6c5ff7..f1dbd1ab9 100644 --- a/randomgen/jsf.pyx +++ b/randomgen/jsf.pyx @@ -2,9 +2,8 @@ import numpy as np -cimport numpy as np + from randomgen._deprecated_value import _DeprecatedValue -from randomgen.common cimport * __all__ = ["JSF"] diff --git a/randomgen/legacy/bounded_integers.pyx.in b/randomgen/legacy/bounded_integers.pyx.in index fc2223e29..1286a11c4 100644 --- a/randomgen/legacy/bounded_integers.pyx.in +++ b/randomgen/legacy/bounded_integers.pyx.in @@ -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), diff --git a/randomgen/lxm.pxd b/randomgen/lxm.pxd index 10bba7716..4a4a7d1cd 100644 --- a/randomgen/lxm.pxd +++ b/randomgen/lxm.pxd @@ -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": diff --git a/randomgen/lxm.pyx b/randomgen/lxm.pyx index a7fdd232b..178f340dc 100644 --- a/randomgen/lxm.pyx +++ b/randomgen/lxm.pyx @@ -2,9 +2,6 @@ # coding=utf-8 import numpy as np -cimport numpy as np - -from randomgen.common cimport * __all__ = ["LXM"] diff --git a/randomgen/mt19937.pxd b/randomgen/mt19937.pxd index 9e3df34a2..54515d781 100644 --- a/randomgen/mt19937.pxd +++ b/randomgen/mt19937.pxd @@ -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": diff --git a/randomgen/mt19937.pyx b/randomgen/mt19937.pyx index d8688069a..bb2a866d5 100644 --- a/randomgen/mt19937.pyx +++ b/randomgen/mt19937.pyx @@ -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"] diff --git a/randomgen/mt64.pxd b/randomgen/mt64.pxd index ce4c92086..791b7bd38 100644 --- a/randomgen/mt64.pxd +++ b/randomgen/mt64.pxd @@ -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": diff --git a/randomgen/mt64.pyx b/randomgen/mt64.pyx index 6321f3e46..20dc85439 100644 --- a/randomgen/mt64.pyx +++ b/randomgen/mt64.pyx @@ -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"] diff --git a/randomgen/mtrand.pyx b/randomgen/mtrand.pyx index 61c9792d3..96a927331 100644 --- a/randomgen/mtrand.pyx +++ b/randomgen/mtrand.pyx @@ -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 x64 - return x.astype("l", casting="unsafe") - cdef class RandomState: """ diff --git a/randomgen/pcg32.pxd b/randomgen/pcg32.pxd index 538901657..1706cc664 100644 --- a/randomgen/pcg32.pxd +++ b/randomgen/pcg32.pxd @@ -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": diff --git a/randomgen/pcg32.pyx b/randomgen/pcg32.pyx index f9cb1290c..884f38f51 100644 --- a/randomgen/pcg32.pyx +++ b/randomgen/pcg32.pyx @@ -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"] diff --git a/randomgen/pcg64.pxd b/randomgen/pcg64.pxd index f0dc4a987..42407c92b 100644 --- a/randomgen/pcg64.pxd +++ b/randomgen/pcg64.pxd @@ -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": diff --git a/randomgen/pcg64.pyx b/randomgen/pcg64.pyx index cbf17cb9c..d75cc1f90 100644 --- a/randomgen/pcg64.pyx +++ b/randomgen/pcg64.pyx @@ -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"] diff --git a/randomgen/philox.pxd b/randomgen/philox.pxd index e15764e71..c1805f633 100644 --- a/randomgen/philox.pxd +++ b/randomgen/philox.pxd @@ -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: diff --git a/randomgen/philox.pxd.in b/randomgen/philox.pxd.in index d832ce6b5..97e527d14 100644 --- a/randomgen/philox.pxd.in +++ b/randomgen/philox.pxd.in @@ -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) diff --git a/randomgen/philox.pyx b/randomgen/philox.pyx index 75e2ad65b..60b3cad8d 100644 --- a/randomgen/philox.pyx +++ b/randomgen/philox.pyx @@ -3,7 +3,6 @@ import numpy as np -from randomgen.common cimport * from randomgen._deprecated_value import _DeprecatedValue __all__ = ["Philox"] diff --git a/randomgen/rdrand.pxd b/randomgen/rdrand.pxd index ec565f561..6137c7143 100644 --- a/randomgen/rdrand.pxd +++ b/randomgen/rdrand.pxd @@ -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 diff --git a/randomgen/rdrand.pyx b/randomgen/rdrand.pyx index cf62541b2..9fd602471 100644 --- a/randomgen/rdrand.pyx +++ b/randomgen/rdrand.pyx @@ -9,16 +9,7 @@ from threading import Lock cimport libc.stdint from cpython cimport PyObject -from cpython.exc cimport ( - PyErr_Clear, - PyErr_Fetch, - PyErr_Occurred, - PyErr_Print, - PyErr_SetObject, - PyErr_SetString, -) - -from randomgen.common cimport * +from cpython.exc cimport PyErr_Clear, PyErr_Occurred, PyErr_SetString np.import_array() diff --git a/randomgen/romu.pxd b/randomgen/romu.pxd index dd429c299..845685ad4 100644 --- a/randomgen/romu.pxd +++ b/randomgen/romu.pxd @@ -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 cdef extern from "src/romu/romu.h": diff --git a/randomgen/romu.pyx b/randomgen/romu.pyx index 07a37516a..2e02dc078 100644 --- a/randomgen/romu.pyx +++ b/randomgen/romu.pyx @@ -1,15 +1,8 @@ #!python #cython: binding=True -import warnings - import numpy as np -cimport cython -cimport numpy as np - -from randomgen.common cimport * - __all__ = ["Romu"] cdef uint64_t romuquad_uint64(void* st) noexcept nogil: diff --git a/randomgen/sfc.pxd b/randomgen/sfc.pxd index f6a22b722..c8ca0e5fe 100644 --- a/randomgen/sfc.pxd +++ b/randomgen/sfc.pxd @@ -1,4 +1,7 @@ -from randomgen.common cimport * +cimport numpy as np +from libc.stdint cimport int8_t, uint8_t, uint32_t, uint64_t + +from randomgen.common cimport BitGenerator, fully_qualified_name, uint64_to_double cdef extern from "src/sfc/sfc.h": diff --git a/randomgen/sfc.pyx b/randomgen/sfc.pyx index 55227f3a0..00baf3340 100644 --- a/randomgen/sfc.pyx +++ b/randomgen/sfc.pyx @@ -6,9 +6,7 @@ import warnings import numpy as np cimport cython -cimport numpy as np -from randomgen.common cimport * from randomgen._deprecated_value import _DeprecatedValue diff --git a/randomgen/sfmt.pxd b/randomgen/sfmt.pxd index 3457285e7..246fd6e4d 100644 --- a/randomgen/sfmt.pxd +++ b/randomgen/sfmt.pxd @@ -1,4 +1,15 @@ -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, + uint64_to_double, +) DEF SFMT_MEXP = 19937 DEF SFMT_N = 156 # SFMT_MEXP / 128 + 1 diff --git a/randomgen/sfmt.pyx b/randomgen/sfmt.pyx index 9d39ee78e..cd78b07c7 100644 --- a/randomgen/sfmt.pyx +++ b/randomgen/sfmt.pyx @@ -1,13 +1,9 @@ #!python #cython: binding=True -import operator - import numpy as np -cimport numpy as np -from randomgen._deprecated_value import _DeprecatedValue -from randomgen.common cimport * +from randomgen._deprecated_value import _DeprecatedValue __all__ = ["SFMT"] diff --git a/randomgen/speck128.pxd b/randomgen/speck128.pxd index 0fb139701..ba2b46ecc 100644 --- a/randomgen/speck128.pxd +++ b/randomgen/speck128.pxd @@ -1,4 +1,17 @@ -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, + check_state_array, + fully_qualified_name, + int_to_array, + object_to_int, + uint64_to_double, + wrap_int, +) DEF SPECK_UNROLL = 12 DEF SPECK_ROUNDS = 34 diff --git a/randomgen/speck128.pyx b/randomgen/speck128.pyx index a5149d229..a773f1fee 100644 --- a/randomgen/speck128.pyx +++ b/randomgen/speck128.pyx @@ -3,7 +3,6 @@ import numpy as np -from randomgen.common cimport * from randomgen._deprecated_value import _DeprecatedValue __all__ = ["SPECK128"] diff --git a/randomgen/threefry.pxd b/randomgen/threefry.pxd index 0f5e57ffc..d25031d95 100644 --- a/randomgen/threefry.pxd +++ b/randomgen/threefry.pxd @@ -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/threefry/threefry.h": struct s_r123array1x32: diff --git a/randomgen/threefry.pxd.in b/randomgen/threefry.pxd.in index 244c1c4e1..96d462f8b 100644 --- a/randomgen/threefry.pxd.in +++ b/randomgen/threefry.pxd.in @@ -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) diff --git a/randomgen/threefry.pyx b/randomgen/threefry.pyx index 72e7e029a..43bf609ec 100644 --- a/randomgen/threefry.pyx +++ b/randomgen/threefry.pyx @@ -3,7 +3,6 @@ import numpy as np -from randomgen.common cimport * from randomgen._deprecated_value import _DeprecatedValue __all__ = ["ThreeFry"] diff --git a/randomgen/tyche.pxd b/randomgen/tyche.pxd index 8c889835f..b5c220898 100644 --- a/randomgen/tyche.pxd +++ b/randomgen/tyche.pxd @@ -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, check_state_array, fully_qualified_name cdef extern from "src/tyche/tyche.h": diff --git a/randomgen/tyche.pyx b/randomgen/tyche.pyx index af715347a..fdbb76abe 100644 --- a/randomgen/tyche.pyx +++ b/randomgen/tyche.pyx @@ -1,10 +1,5 @@ #!python -from multiprocessing.managers import Value - import numpy as np -cimport numpy as np - -from randomgen.common cimport * DEF INDIRECTION_SIZE = 16 DEF ITERATION_SIZE = 32 diff --git a/randomgen/wrapper.pyx b/randomgen/wrapper.pyx index 69366058c..936fa9157 100644 --- a/randomgen/wrapper.pyx +++ b/randomgen/wrapper.pyx @@ -1,7 +1,9 @@ #!python #cython: binding=True -from randomgen.common cimport * +from libc.stdint cimport uint32_t, uint64_t + +from randomgen.common cimport BitGenerator from randomgen.distributions cimport next_double_t, next_uint32_t, next_uint64_t import ctypes