You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now the Dirichlet distribution allocates inner state and sampled values, even though it can be naturally expressed in terms of arrays and AFAIK is usually used with fixed number of dimensions.
WeightedIndex also can be expressed in terms of arrays, but in practice number of weights can be not known at compile time. We could introduce a "fixed" variant in addition to the existing "dynamic" one.
The text was updated successfully, but these errors were encountered:
Note that we return an array with size dependent on a generic parameter, so I am not sure if minimal const generics will be enough for this. It may be blocked on rust-lang/rust#68436.
We now use const generics: impl<F, const N: usize> Distribution<[F; N]> for Dirichlet<F, N> where ...
Caveat: we currently use Vec to construct some arrays in distribution constructors. Once core::array::try_from_fn is stable, we can use that instead.
Caveat: sometimes arrays of other lengths are required (DirichletFromBeta uses an internal array of length one less than the output length). This isn't really an issue, but currently uses an allocator (doing otherwise would require generic_const_exprs or an empty element).
Caveat: the above approach does not support run-time variable length N. We likely don't need to care about this.
Conclusion: we can improve our code once try_from_fn is stabilized, but probably not beyond that.
I tried simply copying the code behind try_from_fn as a utility fn; this is viable but requires rather more unsafe code than I'd like (besides which, we forbid unsafe from rand_distr).
dhardy
changed the title
Use const generics for the Dirichlet distribution
Use ~~const generics~~ try_from_fn for the Dirichlet distribution
Jul 20, 2024
dhardy
changed the title
Use ~~const generics~~ try_from_fn for the Dirichlet distribution
Use const generics, try_from_fn for the Dirichlet distribution
Jul 20, 2024
Right now the Dirichlet distribution allocates inner state and sampled values, even though it can be naturally expressed in terms of arrays and AFAIK is usually used with fixed number of dimensions.
WeightedIndex
also can be expressed in terms of arrays, but in practice number of weights can be not known at compile time. We could introduce a "fixed" variant in addition to the existing "dynamic" one.The text was updated successfully, but these errors were encountered: