pub fn bernoulli(&self, shape: &[usize], p: f64) -> ndarray::Array<T, ndarray::IxDyn> {
            let dist = rand_distr::Uniform::new(0., 1.);
            let mut rng = self.rng.borrow_mut();
            let size: usize = shape.iter().cloned().product();
            unsafe {
                let mut buf = Vec::with_capacity(size);
                for i in 0..size {
                    let val = dist.sample(&mut *rng);
                    *buf.get_unchecked_mut(i) = T::from(i32::from(val < p)).unwrap();
                }
                buf.set_len(size);
                NdArray::from_shape_vec(shape, buf).unwrap()
            }
        }
/// Creates an ndarray sampled from the bernoulli distribution with given params.
Creates an ndarray sampled from the bernoulli distribution with given params.
Creates an ndarray sampled from the bernoulli distribution with given params .
pub fn bernoulli(&self, shape: &[usize], p: f64) -> ndarray::Array<T, ndarray::IxDyn> {
            let dist = rand_distr::Uniform::new(0., 1.);
            let mut rng = self.rng.borrow_mut();
            let size: usize = shape.iter().cloned().product();
            unsafe {
                let mut buf = Vec::with_capacity(size);
                for i in 0..size {
                    let val = dist.sample(&mut *rng);
                    *buf.get_unchecked_mut(i) = T::from(i32::from(val < p)).unwrap();
                }
                buf.set_len(size);
                NdArray::from_shape_vec(shape, buf).unwrap()
            }
        }
pub fn bernoulli ( & self , shape : & [ usize ] , p : f64 ) -> ndarray :: Array < T , ndarray :: IxDyn > { let dist = rand_distr :: Uniform :: new ( 0. , 1. ) ; let mut rng = self . rng . borrow_mut ( ) ; let size : usize = shape . iter ( ) . cloned ( ) . product ( ) ; unsafe { let mut buf = Vec :: with_capacity ( size ) ; for i in 0 .. size { let val = dist . sample ( & mut * rng ) ; * buf . get_unchecked_mut ( i ) = T :: from ( i32 :: from ( val < p ) ) . unwrap ( ) ; } buf . set_len ( size ) ; NdArray :: from_shape_vec ( shape , buf ) . unwrap ( ) } }
Creates an ndarray sampled from the bernoulli distribution with given params.
Creates an ndarray sampled from the bernoulli distribution with given params .
&self
shape
&[usize]
p
f64
&self
shape
&[usize]
p
f64