Skip to content

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

Merged
merged 3 commits into from
Aug 20, 2019

Conversation

WarrenWeckesser
Copy link
Member

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

…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
Copy link
Member

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?

Copy link
Member

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).

Copy link
Member Author

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 at uint32_t (as it turns into a uint32_t element in the spawn_key).

OK, I changed n_children_spawned to uint32_t in the changes that I just pushed.

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Aug 20, 2019
@charris charris added this to the 1.17.1 release milestone Aug 20, 2019
@WarrenWeckesser
Copy link
Member Author

In the latest update, both SeedSequence.pool_size and SeedSequence.n_children_spawned are changed to uint32_t.

@@ -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
Copy link
Member

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 ...

Copy link
Member Author

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.

Copy link
Member

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.

@charris charris merged commit 58295f2 into numpy:master Aug 20, 2019
@WarrenWeckesser WarrenWeckesser deleted the compiler-warning branch August 20, 2019 17:24
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Aug 20, 2019
@charris charris removed this from the 1.17.1 release milestone Aug 20, 2019
@charris
Copy link
Member

charris commented Aug 20, 2019

@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.

@WarrenWeckesser
Copy link
Member Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants