Skip to content

Commit e37f359

Browse files
committed
Manual tweaks.
1 parent 60d85f2 commit e37f359

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

crates/famst/src/lib.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ where
146146
famst_with_rng(data, distance_fn, config, &mut rand::thread_rng())
147147
}
148148

149-
/// FAMST with custom RNG for reproducibility
149+
/// FAMST with custom RNG. (We use a seeded RNG in tests for reproducibility.)
150150
pub fn famst_with_rng<T, D, R>(
151151
data: &[T],
152152
distance_fn: D,
@@ -616,26 +616,26 @@ fn extract_mst_from_ann(ann_graph: &AnnGraph, n: usize) -> Vec<Edge> {
616616
extract_mst(ann_graph, &[], n)
617617
}
618618

619-
/// Euclidean distance for slices of f64
620-
pub fn euclidean_distance(a: &[f64], b: &[f64]) -> f64 {
621-
a.iter()
622-
.zip(b.iter())
623-
.map(|(x, y)| (x - y).powi(2))
624-
.sum::<f64>()
625-
.sqrt()
626-
}
627-
628-
/// Manhattan distance for slices of f64
629-
pub fn manhattan_distance(a: &[f64], b: &[f64]) -> f64 {
630-
a.iter().zip(b.iter()).map(|(x, y)| (x - y).abs()).sum()
631-
}
632-
633619
#[cfg(test)]
634620
mod tests {
635621
use super::*;
636622
use rand::rngs::StdRng;
637623
use rand::SeedableRng;
638624

625+
/// Manhattan distance for slices of f64
626+
pub fn manhattan_distance(a: &[f64], b: &[f64]) -> f64 {
627+
a.iter().zip(b.iter()).map(|(x, y)| (x - y).abs()).sum()
628+
}
629+
630+
/// Euclidean distance for slices of f64
631+
pub fn euclidean_distance(a: &[f64], b: &[f64]) -> f64 {
632+
a.iter()
633+
.zip(b.iter())
634+
.map(|(x, y)| (x - y).powi(2))
635+
.sum::<f64>()
636+
.sqrt()
637+
}
638+
639639
#[test]
640640
fn test_empty_input() {
641641
let points: Vec<Vec<f64>> = vec![];
@@ -657,11 +657,7 @@ mod tests {
657657
#[test]
658658
fn test_k_greater_than_n() {
659659
// 3 points but k=20 (default), so k >= n
660-
let points: Vec<Vec<f64>> = vec![
661-
vec![0.0, 0.0],
662-
vec![1.0, 0.0],
663-
vec![0.0, 1.0],
664-
];
660+
let points: Vec<Vec<f64>> = vec![vec![0.0, 0.0], vec![1.0, 0.0], vec![0.0, 1.0]];
665661
let distance = |a: &Vec<f64>, b: &Vec<f64>| euclidean_distance(a, b);
666662
let config = FamstConfig::default(); // k=20 > n=3
667663
let result = famst(&points, distance, &config);

0 commit comments

Comments
 (0)