Rename WeightedError → WeightError; add IndexedRandom, IndexedMutRandom#1382
Merged
dhardy merged 8 commits intorust-random:masterfrom Feb 15, 2024
Merged
Rename WeightedError → WeightError; add IndexedRandom, IndexedMutRandom#1382dhardy merged 8 commits intorust-random:masterfrom
dhardy merged 8 commits intorust-random:masterfrom
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. |
Member
Author
|
Thanks @TheIronBorn |
dhardy
added a commit
to dhardy/rand
that referenced
this pull request
Feb 18, 2024
cratelyn
added a commit
to linkerd/linkerd2-proxy
that referenced
this pull request
Jan 28, 2025
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>
cratelyn
added a commit
to linkerd/linkerd2-proxy
that referenced
this pull request
Jan 28, 2025
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>
cratelyn
added a commit
to linkerd/linkerd2-proxy
that referenced
this pull request
Jan 28, 2025
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>
benjamin-lieser
pushed a commit
to benjamin-lieser/rand
that referenced
this pull request
Feb 5, 2025
…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
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1307. CC @LikeLakers2.
Renames
WeightedError→WeightError, revises variants and re-exports fromrand::seq.Adjusts
WeightErrorcases:WeightedTreeIndex(NaNs andtry_sample@xmakro) andrand::seq::index::sample_weighted(replace panic; catch too-many-zeros).Splits
SliceRandominto multiple traits to solve #1307. I'm not wildly keen on the result but don't currently have a better idea.