Conversation
|
I put a I am not sure if I want a different name, because it clashed with the one in |
Sorry, it should be
I'm not really sure of the answer to that. Any of these can work (from the POV of a dependency):
|
|
I was talking about the naming of I guess I also prefer the last of the 3 options for the name of the trait. |
|
Also, should we do this in a |
This shouldn't be an issue unless a type implements both Except possibly a symmetric distribution like |
I was thinking about both having |
|
The point of using Which leads to another point: we may want a So: That requires |
|
We should decide if we want to keep the possibility to have multidim sampling without allocations or not. If we do not need it, we can ditch the const generics and have less code and then your proposed Trait would make a lot of sense. I am still leaning toward keeping it, because I had a usecase where Multinomial samples where extremely time critical and it helps to save the allocations, especially in multithread where there is synchronization with malloc. But this might also be a niche usecase. (I would only sample once per Multinomial) Edit: Your Trait is also still implementable for a const generic version and you can avoid all allocations. So I would go with this approach. |
|
I thought we did decide to drop the const-generics approach for Your use-case sounds fairly specific. Maybe there are further optimisations available when sampling only once. |
|
Would it be possible to have a non-const generic impl<F: Float> Dirichlet<F> {
pub fn new(alpha: Vec<F>) -> Result<Dirichlet<F>, Error>;
pub fn sample<R: Rng>(&self, rng: &mut R, output: &mut Vec<F>); // Users can re-use this vector to avoid allocations
pub fn into_vec(self) -> Vec<F>; // Recovers the memory passed in with `new()`
}This still requires the For |
In the case of |
dhardy
left a comment
There was a problem hiding this comment.
Some comments on comment style below.
More significantly, the sample method now looks identical to Distribution::sample, hence your idea to use that trait likely makes more sense: we can automatically impl Distribution<Vec<T>> where T: Default.
This would also allow an explicit impl of Distribution<[T; N]> where appropriate (e.g. your mentioned const-generic Multinomial).
But, at this point, do we still want the MultiDistribution trait at all?
| /// This trait allows to sample from a multi-dimensional distribution without extra allocations. | ||
| /// For convenience it also provides a `sample` method which returns the result as a `Vec`. | ||
| pub trait MultiDistribution<T> { |
There was a problem hiding this comment.
Items have a short one-line description, with additional details in new paragraphs.
|
My current favorite would be something like this: The distributions would implement Unfortunately this does not work because of orphan rules. It also does not feel right to define the We could just implement |
dhardy
left a comment
There was a problem hiding this comment.
I think we can go with this trait design.
|
I think we can keep the Final question: Should we keep the const generic Dirichlet and add a non const generic one, or just replace it. |
This is fine IMO.
That question shouldn't be directed here; can we adjust it in a new PR? From what I remember, there didn't appear to be much use (or evidence for use) for the const-generic implementation. |
|
So in this PR, we keep the original const generic Dirichlet, just implementing |
dhardy
left a comment
There was a problem hiding this comment.
We can also just keep these changes to Dirichlet. The only mandatory change is the licence header.
Perhaps we should add an additional trait, ConstMultiDistribution: MultiDistribution with associated const SAMPLE_LEN: usize and an additional macro impleminting Distribution<[T; SAMPLE_LEN]> (array output). This might work better for your time-critical Multinomial distrs.
For another PR however.
|
Needs |
CHANGELOG.mdentrySummary
Some code related to #16