pub fn distances_to_point(
        &self,
        x: &[f32],
        indexes: &[PointIndex],
    ) -> PointCloudResult<Vec<f32>> {
        let len = indexes.len();
        if len > self.chunk * 3 {
            let mut dists: Vec<f32> = vec![0.0;len];
            let dist_iter = dists.par_chunks_mut(self.chunk);
            let indexes_iter = indexes.par_chunks(self.chunk);
            let error: Mutex<Result<(), PointCloudError>> = Mutex::new(Ok(()));
            dist_iter.zip(indexes_iter).for_each(|(chunk_dists,chunk_indexes)| {
                for (d,i) in chunk_dists.iter_mut().zip(chunk_indexes) {
                    match self.get_point(*i) {
                        Ok(y) => *d = (M::dense)(x, y),
                        Err(e) => {
                            *error.lock().unwrap() = Err(e);
                        }
                    }
                }
            });
            (error.into_inner().unwrap())?;
            Ok(dists)
        } else {
            indexes
                .iter()
                .map(|i| {
                    let y = self.get_point(*i)?;
                    Ok((M::dense)(x, y))
                })
                .collect()
        }
    }
/// The main distance function. This paralizes if there are more than 100 points.
The main distance function. This paralizes if there are more than 100 points.
The main distance function . This paralizes if there are more than 100 points .
pub fn distances_to_point(
        &self,
        x: &[f32],
        indexes: &[PointIndex],
    ) -> PointCloudResult<Vec<f32>> {
        let len = indexes.len();
        if len > self.chunk * 3 {
            let mut dists: Vec<f32> = vec![0.0;len];
            let dist_iter = dists.par_chunks_mut(self.chunk);
            let indexes_iter = indexes.par_chunks(self.chunk);
            let error: Mutex<Result<(), PointCloudError>> = Mutex::new(Ok(()));
            dist_iter.zip(indexes_iter).for_each(|(chunk_dists,chunk_indexes)| {
                for (d,i) in chunk_dists.iter_mut().zip(chunk_indexes) {
                    match self.get_point(*i) {
                        Ok(y) => *d = (M::dense)(x, y),
                        Err(e) => {
                            *error.lock().unwrap() = Err(e);
                        }
                    }
                }
            });
            (error.into_inner().unwrap())?;
            Ok(dists)
        } else {
            indexes
                .iter()
                .map(|i| {
                    let y = self.get_point(*i)?;
                    Ok((M::dense)(x, y))
                })
                .collect()
        }
    }
pub fn distances_to_point ( & self , x : & [ f32 ] , indexes : & [ PointIndex ] , ) -> PointCloudResult < Vec < f32 > > { let len = indexes . len ( ) ; if len > self . chunk * 3 { let mut dists : Vec < f32 > = vec ! [ 0.0 len ] ; let dist_iter = dists . par_chunks_mut ( self . chunk ) ; let indexes_iter = indexes . par_chunks ( self . chunk ) ; let error : Mutex < Result < ( ) , PointCloudError > > = Mutex :: new ( Ok ( ( ) ) ) ; dist_iter . zip ( indexes_iter ) . for_each ( | ( chunk_dists , chunk_indexes ) | { for ( d , i ) in chunk_dists . iter_mut ( ) . zip ( chunk_indexes ) { match self . get_point ( * i ) { Ok ( y ) => * d = ( M :: dense ) ( x , y ) , Err ( e ) => { * error . lock ( ) . unwrap ( ) = Err ( e ) ; } } } } ) ; ( error . into_inner ( ) . unwrap ( ) ) ? ; Ok ( dists ) } else { indexes . iter ( ) . map ( | i | { let y = self . get_point ( * i ) ? ; Ok ( ( M :: dense ) ( x , y ) ) } ) . collect ( ) } }
The main distance function.
The main distance function .
&self
x
&[f32]
indexes
&[PointIndex]
&self
x
&[f32]
indexes
&[PointIndex]