8000 SeedSequence fixes by rkern · Pull Request #39 · mattip/numpy · GitHub
[go: up one dir, main page]

Skip to content

SeedSequence fixes #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 20, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DOC: docstring formatting and cleanups.
  • Loading branch information
rkern committed Jun 20, 2019
commit 3608e186b464af9c97a965c3f5a53b108029b9db
17 changes: 12 additions & 5 deletions numpy/random/bit_generator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ BitGenerator base class and SeedSequence used to seed the BitGenerators.

SeedSequence is derived from Melissa E. O'Neill's C++11 `std::seed_seq`
implementation, as it has a lot of nice properties that we want.

https://gist.github.com/imneme/540829265469e673d045
http://www.pcg-random.org/posts/developing-a-seed_seq-alternative.html

The MIT License (MIT)

Copyright (c) 2015 Melissa E. O'Neill
Copyright (c) 2019 Robert Kern

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -80,13 +86,15 @@ def _int_to_uint32_array(n):

def _coerce_to_uint32_array(x):
""" Coerce an input to a uint32 array.

If a `uint32` array, pass it through directly.
If a non-negative integer, then break it up into `uint32` words, lowest
bits first.
If a string starting with "0x", then interpret as a hex integer, as above.
If a string of decimal digits, interpret as a decimal integer, as above.
If a sequence of ints or strings, interpret each element as above and
concatenate.

Note that the handling of `int64` or `uint64` arrays are not just
straightforward views as `uint32` arrays. If an element is small enough to
fit into a `uint32`, then it will only take up one `uint32` element in the
Expand Down Expand Up @@ -323,9 +331,7 @@ cdef class SeedSequence():

Parameters
----------

mixer: 1D uint32 array, modified in-place

mixer : 1D uint32 array, modified in-place
entropy_array : 1D uint32 array
"""
cdef uint32_t hash_const[1]
Expand Down Expand Up @@ -357,6 +363,7 @@ cdef class SeedSequence():
def get_assembled_entropy(self):
""" Convert and assemble all entropy sources into a uniform uint32
array.

Returns
-------
entropy_array : 1D uint32 array
Expand Down Expand Up @@ -466,14 +473,14 @@ cdef class BitGenerator():

Parameters
----------
seed_seq: {None, ISeedSequence, int, sequence[int]}, optional
seed_seq : {None, ISeedSequence, int, sequence[int]}, optional
A ISeedSequence to initialize the BitGenerator. If None, one will be
created. If an int or a sequence of ints, it will be used as the
entropy for creating a SeedSequence.

Attributes
----------
lock: threading.Lock
lock : threading.Lock
Lock instance that is shared so that the same bit git generator can
be used in multiple Generators without corrupting the state. Code that
generates values from a bit generator should hold the bit generator's
Expand Down
0