Remove const-generic size parameter from Dirichlet distribution #15
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.
CHANGELOG.md
entrySummary
This PR is essentially a revert of rust-random/rand#1292, which changed the Dirichlet distribution to be const-generic over size. This broke my use case, which requires a Dirichlet distribution where the vector size is not known at compile time, see below.
Background
The original change was discussed in rust-random/rand#1292, #8 and rust-random/rand#496. I've also created #14 to discuss reverting that change.
The issue of requiring a statically known size doesn't seem to have been recognized at the time. It's only mentioned in a comment by @dhardy after the code was merged:
I don't think this is correct. A Dirichlet distribution over a dynamic number of elements was used in AlphaZero, one of the most widely read machine learning papers in the field. See the paper and this StackExchange post for details. This is essentially my use case, and given the impact of the paper, I'm sure many other people are doing this.
Additionally, it's not clear to me why the Dirichlet implementation needs to be const-generic at all, apart from a general desire to reduce the number of memory allocations. The performance hit is negligible for any use case I can imagine (feel free to prove me wrong here), and const-generic Dirichlet still requires an allocation, meaning it can't be used without the
alloc
feature.Details
Even though the change was only released a month ago with
0.5
, it was merged almost two years ago, and the code has changed substantially in the meantime. I removed the const generics manually, making as few other changes as possible, so it's possible that the code can now be simplified by someone with a better understand of statistics.