<commit_before>
use std::marker::PhantomData;
use rand::Rng;
use rand::distributions::*;
use ndarray::{DataOwned, Dimension, ArrayBase, ShapeBuilder};
use ndarray_rand::RandomExt;
use num_complex::Complex;
use num_traits::Num;

pub trait RandomExtNormal<S, D>: RandomExt<S, D>
    where S: DataOwned,
          D: Dimension
{
    fn random_normal<Sh>(shape: Sh, mean: S::Elem, variance: S::Elem) -> ArrayBase<S, D> where Sh: ShapeBuilder<Dim = D>;
}

pub trait RandomExtNormalComplex<A, S, D>: RandomExt<S, D>
    where S: DataOwned<Elem = Complex<A>>,
          D: Dimension
{
    fn random_normal_complex<Sh>(shape: Sh, mean: A, variance: A) -> ArrayBase<S, D> where Sh: ShapeBuilder<Dim = D>;
}

pub trait RandomExtRange<S, D>: RandomExt<S, D>
    where S: DataOwned,
          D: Dimension
{
    fn random_range<Sh, IdS>(shape: Sh, min: S::Elem, ma: S::Elem) -> ArrayBase<S, D> where Sh: ShapeBuilder<Dim = D>;
}

impl<A, S, D> RandomExtNormal<S, D> for ArrayBase<S, D>
    where S: DataOwned<Elem = A>,
          D: Dimension,
          A: From<f64> + Into<f64>
{
    fn random_normal<Sh>(shape: Sh, mean: A, variance: A) -> ArrayBase<S, D>
        where Sh: ShapeBuilder<Dim = D>
    {
        let dist = NormalAny::new(mean, variance);
        Self::random(shape, dist)
    }
}

impl<A, S, D> RandomExtNormalComplex<A, S, D> for ArrayBase<S, D>
    where S: DataOwned<Elem = Complex<A>>,
          D: Dimension,
          A: From<f64> + Into<f64> + Clone + Num
{
    fn random_normal_complex<Sh>(shape: Sh, mean: A, variance: A) -> ArrayBase<S, D>
        where Sh: ShapeBuilder<Dim = D>
    {
        let dist = ComplexNormal::new(mean, variance);
        Self::random(shape, dist)
    }
}

impl<A, S, D> RandomExtRange<S, D> for ArrayBase<S, D>
    where S: DataOwned<Elem = A>,
          D: Dimension,
          A: range::SampleRange + PartialOrd
{
    fn random_range<Sh, IdS>(shape: Sh, min: A, max: A) -> ArrayBase<S, D>
        where Sh: ShapeBuilder<Dim = D>
    {
        let dist = Range::new(min, max);
        Self::random(shape, dist)
    }
}

pub struct NormalAny<A> {
    dist: Normal,
    phantom: PhantomData<A>,
}

impl<A: From<f64> + Into<f64>> NormalAny<A> {
    pub fn new(center: A, var: A) -> Self {
        NormalAny {
            dist: Normal::new(center.into(), var.into()),
            phantom: PhantomData,
        }
    }
}

impl<A: From<f64> + Into<f64>> Sample<A> for NormalAny<A> {
    fn sample<R>(&mut self, rng: &mut R) -> A
        where R: Rng
    {
        self.dist.sample(rng).into()
    }
}

impl<A: From<f64> + Into<f64>> IndependentSample<A> for NormalAny<A>
    where f64: Into<A>
{
    fn ind_sample<R>(&self, rng: &mut R) -> A
        where R: Rng
    {
        self.dist.ind_sample(rng).into()
    }
}

pub struct ComplexNormal<A> {
    dist: Normal,
    phantom: PhantomData<A>,
}

impl<A: Into<f64>> ComplexNormal<A> {
    pub fn new(center: A, var: A) -> Self {
        ComplexNormal {
            dist: Normal::new(center.into(), var.into()),
            phantom: PhantomData,
        }
    }
}

impl<A> Sample<Complex<A>> for ComplexNormal<A>
    where A: Clone + Num + From<f64>
{
    fn sample<R>(&mut self, rng: &mut R) -> Complex<A>
        where R: Rng
    {
        let re = self.dist.sample(rng).into();
        let im = self.dist.sample(rng).into();
        Complex::new(re, im)
    }
}

impl<A> IndependentSample<Complex<A>> for ComplexNormal<A>
    where A: Clone + Num + From<f64>
{
    fn ind_sample<R>(&self, rng: &mut R) -> Complex<A>
        where R: Rng
    {
        let re = self.dist.ind_sample(rng).into();
        let im = self.dist.ind_sample(rng).into();
        Complex::new(re, im)
    }
}
<commit_msg>Split type class A<commit_after>
use std::marker::PhantomData;
use rand::Rng;
use rand::distributions::*;
use ndarray::{DataOwned, Dimension, ArrayBase, ShapeBuilder};
use ndarray_rand::RandomExt;
use num_complex::Complex;
use num_traits::Num;

pub trait RandomExtNormal<A, S, D>: RandomExt<S, D>
    where S: DataOwned<Elem = A>,
          D: Dimension
{
    fn random_normal<Sh>(shape: Sh, mean: A, variance: A) -> ArrayBase<S, D> where Sh: ShapeBuilder<Dim = D>;
}

pub trait RandomExtNormalComplex<A, S, D>: RandomExt<S, D>
    where S: DataOwned<Elem = Complex<A>>,
          D: Dimension
{
    fn random_normal_complex<Sh>(shape: Sh, mean: A, variance: A) -> ArrayBase<S, D> where Sh: ShapeBuilder<Dim = D>;
}

pub trait RandomExtRange<S, D>: RandomExt<S, D>
    where S: DataOwned,
          D: Dimension
{
    fn random_range<Sh, IdS>(shape: Sh, min: S::Elem, ma: S::Elem) -> ArrayBase<S, D> where Sh: ShapeBuilder<Dim = D>;
}

impl<A, S, D> RandomExtNormal<A, S, D> for ArrayBase<S, D>
    where S: DataOwned<Elem = A>,
          D: Dimension,
          A: From<f64> + Into<f64>
{
    fn random_normal<Sh>(shape: Sh, mean: A, variance: A) -> ArrayBase<S, D>
        where Sh: ShapeBuilder<Dim = D>
    {
        let dist = NormalAny::new(mean, variance);
        Self::random(shape, dist)
    }
}

impl<A, S, D> RandomExtNormalComplex<A, S, D> for ArrayBase<S, D>
    where S: DataOwned<Elem = Complex<A>>,
          D: Dimension,
          A: From<f64> + Into<f64> + Clone + Num
{
    fn random_normal_complex<Sh>(shape: Sh, mean: A, variance: A) -> ArrayBase<S, D>
        where Sh: ShapeBuilder<Dim = D>
    {
        let dist = ComplexNormal::new(mean, variance);
        Self::random(shape, dist)
    }
}

impl<A, S, D> RandomExtRange<S, D> for ArrayBase<S, D>
    where S: DataOwned<Elem = A>,
          D: Dimension,
          A: range::SampleRange + PartialOrd
{
    fn random_range<Sh, IdS>(shape: Sh, min: A, max: A) -> ArrayBase<S, D>
        where Sh: ShapeBuilder<Dim = D>
    {
        let dist = Range::new(min, max);
        Self::random(shape, dist)
    }
}

pub struct NormalAny<A> {
    dist: Normal,
    phantom: PhantomData<A>,
}

impl<A: From<f64> + Into<f64>> NormalAny<A> {
    pub fn new(center: A, var: A) -> Self {
        NormalAny {
            dist: Normal::new(center.into(), var.into()),
            phantom: PhantomData,
        }
    }
}

impl<A: From<f64> + Into<f64>> Sample<A> for NormalAny<A> {
    fn sample<R>(&mut self, rng: &mut R) -> A
        where R: Rng
    {
        self.dist.sample(rng).into()
    }
}

impl<A: From<f64> + Into<f64>> IndependentSample<A> for NormalAny<A>
    where f64: Into<A>
{
    fn ind_sample<R>(&self, rng: &mut R) -> A
        where R: Rng
    {
        self.dist.ind_sample(rng).into()
    }
}

pub struct ComplexNormal<A> {
    dist: Normal,
    phantom: PhantomData<A>,
}

impl<A: Into<f64>> ComplexNormal<A> {
    pub fn new(center: A, var: A) -> Self {
        ComplexNormal {
            dist: Normal::new(center.into(), var.into()),
            phantom: PhantomData,
        }
    }
}

impl<A> Sample<Complex<A>> for ComplexNormal<A>
    where A: Clone + Num + From<f64>
{
    fn sample<R>(&mut self, rng: &mut R) -> Complex<A>
        where R: Rng
    {
        let re = self.dist.sample(rng).into();
        let im = self.dist.sample(rng).into();
        Complex::new(re, im)
    }
}

impl<A> IndependentSample<Complex<A>> for ComplexNormal<A>
    where A: Clone + Num + From<f64>
{
    fn ind_sample<R>(&self, rng: &mut R) -> Complex<A>
        where R: Rng
    {
        let re = self.dist.ind_sample(rng).into();
        let im = self.dist.ind_sample(rng).into();
        Complex::new(re, im)
    }
}

{'fraction_non_alphanumeric': 0.159192521338572, 'fraction_numerical': 0.0075870478254979, 'mean_word_length': 2.7434077079107504, 'pattern_counts': {'":': 0, '<': 166, '<?xml version=': 0, '>': 190, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6762564', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2725, 'n_words': 688}