fn measure_split(&mut self, partition: impl Fn(BasisVector<N>) -> bool) -> bool {
        let prob_true: f64 = self
            .decomposed
            .iter()
            .filter(|&(&bv, _): &(&BasisVector<N>,&Complex)| partition(bv))
            .map(|(_, val)| val.norm_squared())
            .sum();

        let measure = prob_true >= rand();
        let prob = if measure { prob_true } else { 1.0 - prob_true };
        self.decomposed.drain_filter(|basis, val| {
            *val = *val / c!(prob.sqrt());
            // TODO: Sign?
            partition(*basis) != measure
        }).for_each(drop);

        self.update_reusability();
        measure
    }
/// Split basis vectors into two sets, measure to decide which
/// set to keep, and throw out the other set.
Split basis vectors into two sets, measure to decide which
set to keep, and throw out the other set.
Split basis vectors into two sets measure to decide which set to keep and throw out the other set .
fn measure_split(&mut self, partition: impl Fn(BasisVector<N>) -> bool) -> bool {
        let prob_true: f64 = self
            .decomposed
            .iter()
            .filter(|&(&bv, _): &(&BasisVector<N>,&Complex)| partition(bv))
            .map(|(_, val)| val.norm_squared())
            .sum();
        let measure = prob_true >= rand();
        let prob = if measure { prob_true } else { 1.0 - prob_true };
        self.decomposed.drain_filter(|basis, val| {
            *val = *val / c!(prob.sqrt());
            // TODO: Sign?
            partition(*basis) != measure
        }).for_each(drop);
        self.update_reusability();
        measure
    }
fn measure_split ( & mut self , partition : impl Fn ( BasisVector < N > ) -> bool ) -> bool { let prob_true : f64 = self . decomposed . iter ( ) . filter ( | & ( & bv , _ ) : & ( & BasisVector < N > , & Complex ) | partition ( bv ) ) . map ( | ( _ , val ) | val . norm_squared ( ) ) . sum ( ) ; let measure = prob_true >= rand ( ) ; let prob = if measure { prob_true } else { 1.0 - prob_true } ; self . decomposed . drain_filter ( | basis , val | { * val = * val / c ! ( prob sqrt ( ) ) ; // TODO: Sign? partition ( * basis ) != measure } ) . for_each ( drop ) ; self . update_reusability ( ) ; measure }
Split basis vectors into two sets, measure to decide which
set to keep, and throw out the other set.
Split basis vectors into two sets measure to decide which set to keep and throw out the other set .
&mut self
partition
impl Fn(BasisVector<N>) -> bool
&mut self
partition
impl Fn(BasisVector<N>) -> bool