-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
MAINT: random: Match type of SeedSequence.pool_size to DEFAULT_POOL_SIZE. #14303
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
Conversation
…IZE. Fixes this compiler warning: gcc: numpy/random/bit_generator.c numpy/random/bit_generator.c:4889:41: warning: comparison of integers of different signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare] __pyx_t_6 = ((__pyx_v_self->pool_size != __pyx_v_5numpy_6random_13bit_generator_DEFAULT_POOL_SIZE) != 0); ~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated
@@ -14,7 +14,7 @@ cdef class BitGenerator(): | |||
cdef class SeedSequence(): | |||
cdef readonly object entropy | |||
cdef readonly tuple spawn_key | |||
cdef readonly int pool_size | |||
cdef readonly uint32_t pool_size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this (and the other counts in this struct) isn't size_t?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pool_size
is supposed to be tiny (relatively speaking). n_children_spawned
could be largish, but should be capped at uint32_t
(as it turns into a uint32_t
element in the spawn_key
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring for the pool_size
attribute says "Size of the pooled entropy to store. Default is 4 to give a 128-bit entropy pool. 8 (for 256 bits) is another reasonable choice if working with larger PRNGs, but there is very little to be gained by selecting another value." So 32 bits is far more than necessary, but I guess it is harmless to leave it that size.
n_children_spawned
could be largish, but should be capped atuint32_t
(as it turns into auint32_t
element in thespawn_key
).
OK, I changed n_children_spawned
to uint32_t
in the changes that I just pushed.
In the latest update, both |
@@ -116,7 +116,7 @@ def _coerce_to_uint32_array(x): | |||
Examples | |||
-------- | |||
>>> import numpy as np | |||
>>> from np.random.bit_generator import _coerce_to_uint32_array | |||
>>> from numpy.random.bit_generator import _coerce_to_uint32_array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? The line above should make the old code work ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
I'm not sure which part of the change "this" refers to. The import statement is needed so we can use _coerce_to_uint32_array
without giving the fully qualified name. The change from np
to numpy
is needed because a Python variable can't be used as part of the module in an import statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the import numpy as np
is needed for examples, but that is extraneous to this PR.
@WarrenWeckesser Some lines in your commit message are way long. Might want to check your editor setting for them. Most editors have plugins for git commit messages. |
@charris, the long lines are from the compiler warning that I included in the commit message. I intentionally didn't break that up, but I can do so in the future. |
Fixes this compiler warning:
gcc: numpy/random/bit_generator.c
numpy/random/bit_generator.c:4889:41: warning: comparison of integers of different signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
__pyx_t_6 = ((__pyx_v_self->pool_size != __pyx_v_5numpy_6random_13bit_generator_DEFAULT_POOL_SIZE) != 0);
~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated