concision_core/params/impls/
impl_params_rand.rs

1/*
2    appellation: impl_params_init <module>
3    authors: @FL03
4*/
5use crate::params::ParamsBase;
6
7use ndarray::{DataOwned, Dimension, RawData, RemoveAxis, ScalarOperand, ShapeBuilder};
8use num_traits::{Float, FromPrimitive};
9use rand_distr::Distribution;
10
11impl<A, S, D> ParamsBase<S, D>
12where
13    A: Float + FromPrimitive + ScalarOperand,
14    D: Dimension,
15    S: RawData<Elem = A>,
16{
17    /// returns a new instance of the [`ParamsBase`] with the given shape and values
18    /// initialized according to the provided random distribution `distr`.
19    pub fn random_with<Dst, Sh>(shape: Sh, distr: Dst) -> Self
20    where
21        D: RemoveAxis,
22        S: DataOwned,
23        Sh: ShapeBuilder<Dim = D>,
24        Dst: Clone + Distribution<A>,
25    {
26        Self::init_from_fn(shape, || distr.sample(&mut rand::rng()))
27    }
28}