pub fn maxima_finder(index: &mut Vec<usize>,
                     density: &[f64],
                     voxel_map: &VoxelMap,
                     threads: usize,
                     progress_bar: Bar)
                     -> Result<Vec<isize>> {
    let mut bader_maxima = Vec::<isize>::new();
    let pbar = &progress_bar;
    let index_len = index.len();
    let chunk_size = (index_len / threads) + (index_len % threads).min(1);
    thread::scope(|s| {
        // Identify all the maxima
        let th = index.chunks_mut(chunk_size)
                      .map(|chunk| {
                          s.spawn(move |_| {
                               chunk.iter_mut()
                                    .filter_map(|p| {
                                        // we have to tick first due to early return
                                        pbar.tick();
                                        let rho = density[*p];
                                        for (pt, _) in
                                            voxel_map.grid
                                                     .voronoi_shifts(*p
                                                                     as isize)
                                        {
                                            if density[pt as usize] > rho {
                                                return None;
                                            }
                                        }
                                        // if we made it this far we have a maxima
                                        // change this index to a value it could
                                        // never be and return it
                                        let maxima = Some(*p as isize);
                                        *p = index_len;
                                        maxima
                                    })
                                    .collect::<Vec<isize>>()
                           })
                      })
                      .collect::<Vec<_>>();
        for thread in th {
            if let Ok(mut maxima_list) = thread.join() {
                bader_maxima.append(&mut maxima_list);
            } else {
                panic!("Failed to join thread in maxima finder.")
            };
        }
    }).unwrap();
    // remove the index of the maxima
    index.retain(|&i| i != index_len);
    Ok(bader_maxima)
}
/// Find (and remove from a sorted index) the maxima within the charge density
Find (and remove from a sorted index) the maxima within the charge density
Find ( and remove from a sorted index ) the maxima within the charge density
pub fn maxima_finder(index: &mut Vec<usize>,
                     density: &[f64],
                     voxel_map: &VoxelMap,
                     threads: usize,
                     progress_bar: Bar)
                     -> Result<Vec<isize>> {
    let mut bader_maxima = Vec::<isize>::new();
    let pbar = &progress_bar;
    let index_len = index.len();
    let chunk_size = (index_len / threads) + (index_len % threads).min(1);
    thread::scope(|s| {
        // Identify all the maxima
        let th = index.chunks_mut(chunk_size)
                      .map(|chunk| {
                          s.spawn(move |_| {
                               chunk.iter_mut()
                                    .filter_map(|p| {
                                        // we have to tick first due to early return
                                        pbar.tick();
                                        let rho = density[*p];
                                        for (pt, _) in
                                            voxel_map.grid
                                                     .voronoi_shifts(*p
                                                                     as isize)
                                        {
                                            if density[pt as usize] > rho {
                                                return None;
                                            }
                                        }
                                        // if we made it this far we have a maxima
                                        // change this index to a value it could
                                        // never be and return it
                                        let maxima = Some(*p as isize);
                                        *p = index_len;
                                        maxima
                                    })
                                    .collect::<Vec<isize>>()
                           })
                      })
                      .collect::<Vec<_>>();
        for thread in th {
            if let Ok(mut maxima_list) = thread.join() {
                bader_maxima.append(&mut maxima_list);
            } else {
                panic!("Failed to join thread in maxima finder.")
            };
        }
    }).unwrap();
    // remove the index of the maxima
    index.retain(|&i| i != index_len);
    Ok(bader_maxima)
}
pub fn maxima_finder ( index : & mut Vec < usize > , density : & [ f64 ] , voxel_map : & VoxelMap , threads : usize , progress_bar : Bar ) -> Result < Vec < isize > > { let mut bader_maxima = Vec :: < isize > :: new ( ) ; let pbar = & progress_bar ; let index_len = index . len ( ) ; let chunk_size = ( index_len / threads ) + ( index_len % threads ) . min ( 1 ) ; thread :: scope ( | s | { // Identify all the maxima let th = index . chunks_mut ( chunk_size ) . map ( | chunk | { s . spawn ( move | _ | { chunk . iter_mut ( ) . filter_map ( | p | { // we have to tick first due to early return pbar . tick ( ) ; let rho = density [ * p ] ; for ( pt , _ ) in voxel_map . grid . voronoi_shifts ( * p as isize ) { if density [ pt as usize ] > rho { return None ; } } // if we made it this far we have a maxima // change this index to a value it could // never be and return it let maxima = Some ( * p as isize ) ; * p = index_len ; maxima } ) . collect :: < Vec < isize > > ( ) } ) } ) . collect :: < Vec < _ > > ( ) ; for thread in th { if let Ok ( mut maxima_list ) = thread . join ( ) { bader_maxima . append ( & mut maxima_list ) ; } else { panic ! ( " " ) } ; } } ) . unwrap ( ) ; // remove the index of the maxima index . retain ( | & i | i != index_len ) ; Ok ( bader_maxima ) }
Find (and remove from a sorted index) the maxima within the charge density
Find ( and remove from a sorted index ) the maxima within the charge density
index
&mut Vec<usize>
density
&[f64]
voxel_map
&VoxelMap
threads
usize
progress_bar
Bar
index
&mut Vec<usize>
density
&[f64]
voxel_map
&VoxelMap
threads
usize
progress_bar
Bar