Add check for appropriate teardown
+import atexit
import numpy
import cupy
@@ -9,6 +10,12 @@ import cupy
_nest_count = 0
+@atexit.register
+def _check_teardown():
+ assert _nest_count == 0, ('setup_random() and teardown_random() '
+ 'must be called in pair.')
+
+
def setup_random(numpy_seed=None, cupy_seed=None):
"""Sets up the deterministic random states of ``numpy`` and ``cupy``.
