Skip to content

Commit

Permalink
DOC: Correct docs
Browse files Browse the repository at this point in the history
Correct docs
Fix for new code
closes #356
  • Loading branch information
bashtage committed Sep 20, 2024
1 parent fe91a42 commit b1eecf4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions doc/source/multithreading.rst
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
Multithreaded Generation
========================

The four core distributions all allow existing arrays to be filled using the
``out`` keyword argument. Existing arrays need to be contiguous and
well-behaved (writable and aligned). Under normal circumstances, arrays
created using the common constructors such as :meth:`numpy.empty` will satisfy
these requirements.
The four core distributions in :class:`~numpy.random.Generator` all allow
existing arrays to be filled using the ``out`` keyword argument.
Existing arrays need to be contiguous and well-behaved (writable and aligned).
Under normal circumstances, arrays created using the common constructors such
as :meth:`numpy.empty` will satisfy these requirements.

This example makes use of Python 3 :mod:`concurrent.futures` to fill an array
using multiple threads. Threads are long-lived so that repeated calls do not
require any additional overheads from thread creation. The underlying PRNG is
xorshift2014 which is fast, has a long period and supports using ``jumped`` to
xorshift256 which is fast, has a long period and supports using ``jumped`` to
advance the state. The random numbers generated are reproducible in the sense
that the same seed will produce the same outputs.

.. code-block:: ipython
from randomgen import Xoshiro256
import multiprocessing
import concurrent.futures
import numpy as np
import warnings
warnings.filterwarnings("ignore", "Generator", FutureWarning)
from numpy.random import Generator
from randomgen import Xoshiro256
class MultithreadedRNG(object):
def __init__(self, n, seed=None, threads=None):
last_bg = Xoshiro256(seed, mode="sequence")
last_bg = Xoshiro256(seed)
if threads is None:
threads = multiprocessing.cpu_count()
self.threads = threads
Expand Down

0 comments on commit b1eecf4

Please sign in to comment.