pub fn nearest_neighbors(
    from: &DataFrame,
    to: &DataFrame,
    mut result: Vec<(usize, f64)>,
) -> Vec<(usize, f64)> {
    assert_eq!(from.ncols(), to.ncols());
    assert_eq!(result.len(), from.nrows());

    for (idx_from, row_from) in from.iter_rows().enumerate() {
        let mut min_dist = std::f64::MAX;
        let mut min_idx: usize = 0;
        for (idx_to, row_to) in to.iter_rows().enumerate() {
            let dist = EUCLIDEAN_SQ.distance(row_from, row_to);
            if dist < min_dist {
                min_dist = dist;
                min_idx = idx_to
            }
        }
        result[idx_from] = (min_idx, min_dist.sqrt());
    }
    result
}
/// Nearest-neighbors for multiple starting points, by Euclidean distance.
/// # Returns
/// Vec(index, weighted-distance)
Nearest-neighbors for multiple starting points, by Euclidean distance.
Nearest - neighbors for multiple starting points by Euclidean distance .
pub fn nearest_neighbors(
    from: &DataFrame,
    to: &DataFrame,
    mut result: Vec<(usize, f64)>,
) -> Vec<(usize, f64)> {
    assert_eq!(from.ncols(), to.ncols());
    assert_eq!(result.len(), from.nrows());
    for (idx_from, row_from) in from.iter_rows().enumerate() {
        let mut min_dist = std::f64::MAX;
        let mut min_idx: usize = 0;
        for (idx_to, row_to) in to.iter_rows().enumerate() {
            let dist = EUCLIDEAN_SQ.distance(row_from, row_to);
            if dist < min_dist {
                min_dist = dist;
                min_idx = idx_to
            }
        }
        result[idx_from] = (min_idx, min_dist.sqrt());
    }
    result
}
pub fn nearest_neighbors ( from : & DataFrame , to : & DataFrame , mut result : Vec < ( usize , f64 ) > , ) -> Vec < ( usize , f64 ) > { assert_eq ! ( from ncols ( ) to ncols ( ) ) ; assert_eq ! ( result len ( ) from nrows ( ) ) ; for ( idx_from , row_from ) in from . iter_rows ( ) . enumerate ( ) { let mut min_dist = std :: f64 :: MAX ; let mut min_idx : usize = 0 ; for ( idx_to , row_to ) in to . iter_rows ( ) . enumerate ( ) { let dist = EUCLIDEAN_SQ . distance ( row_from , row_to ) ; if dist < min_dist { min_dist = dist ; min_idx = idx_to } } result [ idx_from ] = ( min_idx , min_dist . sqrt ( ) ) ; } result }
Nearest-neighbors for multiple starting points, by Euclidean distance.
Nearest - neighbors for multiple starting points by Euclidean distance .
from
&DataFrame
to
&DataFrame
result
Vec<(usize, f64)>
None
from
&DataFrame
to
&DataFrame
result
Vec<(usize, f64)>