Skip to content
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

[xrandom] Improve random::choice #1011

Merged
merged 2 commits into from Jul 30, 2018
Merged

[xrandom] Improve random::choice #1011

merged 2 commits into from Jul 30, 2018

Conversation

OneRaynyDay
Copy link
Contributor

This PR corresponds to the following fixes:

  1. The garbage values produced by this issue is due to an optional assert. We throw std::runtime_error instead.

  2. Previously, we performed a Fisher Yates shuffle on the array and then copied the shuffle. As @wolfv has pointed out, the stdlib implements it using reservoir sampling, which we implement here.

  3. We also add an option to perform sample with replacement, and make it true by default, since that is numpy's behavior

@SylvainCorlay
Copy link
Member

Thanks!

FYI It seems that your commit email does not correspond top the your GitHub account email. If we merge this as it is, you won't be credited for the commit.

for(auto it = de.storage().begin() + n; it != de.storage().end(); ++it, ++i)
{
auto idx = std::uniform_int_distribution<std::size_t>(0, i)(engine);
if (idx < n)
Copy link
Member

Choose a reason for hiding this comment

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

we require brackets even around one liners! sry :)

@wolfv
Copy link
Member

wolfv commented Jul 30, 2018

Looks great! just the single nitpick...

@wolfv
Copy link
Member

wolfv commented Jul 30, 2018

I'll merge after the tests show up green!

@wolfv wolfv merged commit dd957e0 into xtensor-stack:master Jul 30, 2018
@wolfv
Copy link
Member

wolfv commented Jul 30, 2018

Congrats! 🎉

@OneRaynyDay
Copy link
Contributor Author

Thanks @wolfv! :)

FrozenWinters pushed a commit to FrozenWinters/xtensor that referenced this pull request Aug 14, 2018
Added resevoir sampling and sampling with replacement with corresponding tests
FrozenWinters pushed a commit to FrozenWinters/xtensor that referenced this pull request Aug 14, 2018
Avoided installation failure in absence of nlohmann_json

Fix more warnings (xtensor-stack#999)

* refactor strides computation

* use better temporary type for strided view

* remove rebind container for fixed shape type

Shared xexpression + automatic xclosure detection (xtensor-stack#992)

add xshared expression

Update view.rst

convertible types instead of same type

basic usage replaced with getting started

fix where on xview

[xrandom] Improve `random::choice` (xtensor-stack#1011)

Added resevoir sampling and sampling with replacement with corresponding tests

Add tests to evaluate shared expression

[xnpy] Add `signed char` to deserialization format (xtensor-stack#1017)

* Add int8 support to xnpy

[xexpression] - Fix make_xshared (xtensor-stack#1024)

Fix make_xshared

[docs] Kwargs don't exist in C++

Quick nit about the documentation on numpy -> xtensor

xshared_expression fix (xtensor-stack#1025)

xshared_expression fixed

changelog updated

Release 0.17.0

Update binder and releasing instructions

missing comparison operators for xlices

fix rebind_container for gcc8 c++17

..

functor return value fixed

fix up shape_type in case xtensor fixed is used

fix up shape_type in case xtensor fixed is used, use std::array for xtensor_fixed in MSVC

add more adapt functions

add docs + tests

fix strided view on view

fix warnings for braces on older clang versions

Improved CRTP base class detection

add std qualifiers to size_t and ptrdiff_t

ifdef copysign for MSVC

release 0.17.1

[docs] tanh typo

Quick nit

add missing parenthesis around std::min and std::max
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.

None yet

3 participants