Skip to content

BUG: internal call fix in random.choice - #2823

Merged
njsmith merged 1 commit into
numpy:masterfrom
seberg:random-choice-state
Dec 15, 2012
Merged

njsmith merged 1 commit into
numpy:masterfrom
seberg:random-choice-state

Conversation

@seberg

@seberg seberg commented Dec 14, 2012

Copy link
Copy Markdown
Member

An random.random call from within mtrand was done by a call to np.random.random instead of inside the class. This can possibly lead to non-deterministic results after seeding.

Sorry that I noticed this only after mtrand was recreated already for this function... @njsmith this is the extremely simple fix, I guess @certik should put this into 1.7. as well? I included a regression test that failed before and double checked that there is no further occurrence of this at the time.

Comment thread numpy/random/tests/test_regression.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this just checks that m.choice calls some self random function that affects the output; really we want to test that it only calls self random functions. But obviously it catches this particular bug, so this is finicky. I think the ideal tests for this kind of thing though look like:

for i in xrange(3):
  np.random.seed(i)
  assert_equal(RandomState(1234).choice(10, ...), [0, 3, 5, 2, ..., 7])

i.e. scrambling the global random state around while checking that a fixed seed continues to produce the same fixed output, and where this output is specified explicitly so that we can compare this version of numpy's .choice method to all the other versions we've shipped.

This kind of test is relevant for all the random functions though, arguably a separate project.

@njsmith

njsmith commented Dec 15, 2012

Copy link
Copy Markdown
Member

Oh yes and the fix itself is obviously correct, and @certik this is RC.

An random.random call from within mtrand was done by a call to
np.random.random instead of inside the class. This can possibly lead
to non-deterministic results after seeding.
@seberg

seberg commented Dec 15, 2012

Copy link
Copy Markdown
Member Author

OK, changed it to your version... can't hurt to do it the nice way, some day someone might copy the design.

@njsmith

njsmith commented Dec 15, 2012

Copy link
Copy Markdown
Member

Yeah you're right; I was just trying to be nice :-)

I would hit the green button but already turned off my computer for the
night. Will do in the morning if no one beats me to it.
On 15 Dec 2012 00:24, "seberg" [email protected] wrote:

OK, changed it to your version... can't hurt to do it the nice way, some
day someone might copy the design.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/2823#issuecomment-11397296.

@njsmith

njsmith commented Dec 15, 2012

Copy link
Copy Markdown
Member

(Whose job is it to regenerate mtrand.c?)
On 15 Dec 2012 00:35, [email protected] wrote:

Yeah you're right; I was just trying to be nice :-)

I would hit the green button but already turned off my computer for the
night. Will do in the morning if no one beats me to it.
On 15 Dec 2012 00:24, "seberg" [email protected] wrote:

OK, changed it to your version... can't hurt to do it the nice way, some
day someone might copy the design.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/2823#issuecomment-11397296.

@seberg

seberg commented Dec 15, 2012

Copy link
Copy Markdown
Member Author

oh, I have regenerated it here (cython version 0.17.1), but maybe better if someone else does it, certik has done it with the other PR I think, so if it makes things easier, I can remove that again.

@njsmith

njsmith commented Dec 15, 2012

Copy link
Copy Markdown
Member

I think this is fine, just wanted to make sure that I didn't have to make sure to do it when merging into master.

njsmith added a commit that referenced this pull request Dec 15, 2012
BUG: internal call fix in random.choice
@njsmith
njsmith merged commit 5f04dc8 into numpy:master Dec 15, 2012
@certik certik mentioned this pull request Dec 15, 2012
@certik

certik commented Dec 15, 2012

Copy link
Copy Markdown
Contributor

Backported in #2827.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants