-
-
Notifications
You must be signed in to change notification settings - Fork 461
Rename WeightedError → WeightError; add IndexedRandom, IndexedMutRandom #1382
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
This no longer panics and now returns an error when not enough weights are positive.
I took a general look at 06fe3d8 (the commit where you split Unless I'm missing something (it's been a while since I touched
Personally, I'm a fan of this solution. Not only does it make it possible for non-std collections to implement random functionality, but it makes it as simple as impl-ing one method on one trait. Still, if you come up with a better idea, don't be afraid to poke me and I'll tell you what I think. |
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.
Looks good to me
Thanks @TheIronBorn |
see rust-random/rand#1382. in particular, this part of the change: https://github.com/rust-random/rand/pull/1382/files#diff-b0eb1b0ef894742b65e07f23af6cbeffae64ec8311adb6ea606603e978023e0cL116-R113 see also rust-random/rand#1470. Signed-off-by: katelyn martin <kate@buoyant.io>
see rust-random/rand#1382. in particular, this part of the change: https://github.com/rust-random/rand/pull/1382/files#diff-b0eb1b0ef894742b65e07f23af6cbeffae64ec8311adb6ea606603e978023e0cL116-R113 see also rust-random/rand#1470. Signed-off-by: katelyn martin <kate@buoyant.io>
supersedes #3569. this branch updates [`rand`](https://github.com/rust-random/rand) from 0.8.5 to 0.9.0. - [release notes](https://github.com/rust-random/rand/releases) - [changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md) - [commits](rust-random/rand@0.8.5...0.9.0) note the changes to `rand::distr::weighted::Error`'s variants. see rust-random/rand#1382, and rust-random/rand#1470. in particular, this change: https://github.com/rust-random/rand/pull/1382/files#diff-b0eb1b0ef894742b65e07f23af6cbeffae64ec8311adb6ea606603e978023e0cL116-R113 most other changes in this branch relate to the renaming of `thread_rng()` to `rng()`, and `gen()` to `random()`. --- * build(deps): bump rand from 0.8.5 to 0.9.0 Bumps [rand](https://github.com/rust-random/rand) from 0.8.5 to 0.9.0. - [Release notes](https://github.com/rust-random/rand/releases) - [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md) - [Commits](rust-random/rand@0.8.5...0.9.0) --- updated-dependencies: - dependency-name: rand dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(exp-backoff): address `rand` breaking changes Signed-off-by: katelyn martin <kate@buoyant.io> * chore(pool/p2c): address `rand` breaking changes Signed-off-by: katelyn martin <kate@buoyant.io> * chore(distribute): address `rand` breaking changes see rust-random/rand#1382. in particular, this part of the change: https://github.com/rust-random/rand/pull/1382/files#diff-b0eb1b0ef894742b65e07f23af6cbeffae64ec8311adb6ea606603e978023e0cL116-R113 see also rust-random/rand#1470. Signed-off-by: katelyn martin <kate@buoyant.io> * chore(http/route): address `rand` breaking changes Signed-off-by: katelyn martin <kate@buoyant.io> * chore(exp-backoff): address `rand` breaking changes Signed-off-by: katelyn martin <kate@buoyant.io> * chore(deny.toml): skip previous `rand` dependencies this addresses some ci errors related to duplicate dependencies: ``` error[duplicate]: found 2 duplicate entries for crate 'getrandom' ┌─ /github/workspace/Cargo.lock:75:1 │ 75 │ ╭ getrandom 0.2.15 registry+https://github.com/rust-lang/crates.io-index 76 │ │ getrandom 0.3.1 registry+https://github.com/rust-lang/crates.io-index │ ╰─────────────────────────────────────────────────────────────────────┘ lock entries │ ``` Signed-off-by: katelyn martin <kate@buoyant.io> * review(distribute): add `use` statement Signed-off-by: katelyn martin <kate@buoyant.io> --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: katelyn martin <kate@buoyant.io> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…om (rust-random#1382) * Remove deprecated module rand::distributions::weighted * WeightedTree: return InvalidWeight on not-a-number * WeightedTree::try_sample return AllWeightsZero given no weights * Rename WeightedError -> WeightError and revise variants * Re-export WeightError from rand::seq * Revise errors of rand::index::sample_weighted * Split SliceRandom into IndexedRandom, IndexedMutRandom and SliceRandom
Fixes #1307. CC @LikeLakers2.
Renames
WeightedError
→WeightError
, revises variants and re-exports fromrand::seq
.Adjusts
WeightError
cases:WeightedTreeIndex
(NaNs andtry_sample
@xmakro) andrand::seq::index::sample_weighted
(replace panic; catch too-many-zeros).Splits
SliceRandom
into multiple traits to solve #1307. I'm not wildly keen on the result but don't currently have a better idea.