From a2b1b7b7260d0eff64944f9be31e5eeb2259af57 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 18 May 2021 11:34:01 +0200 Subject: [PATCH] wip --- Cargo.toml | 3 --- instant-distance/Cargo.toml | 2 +- instant-distance/benches/all.rs | 14 +++++++++----- instant-distance/src/lib.rs | 11 +++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0f7eac6..98959cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,2 @@ [workspace] members = ["instant-distance", "instant-distance-py"] - -[profile.bench] -debug = true diff --git a/instant-distance/Cargo.toml b/instant-distance/Cargo.toml index fb678b2..13008de 100644 --- a/instant-distance/Cargo.toml +++ b/instant-distance/Cargo.toml @@ -20,7 +20,7 @@ num_cpus = "1.13" ordered-float = "2.0" parking_lot = "0.11" rand = { version = "0.8", features = ["small_rng"] } -rayon = "1.5" +#rayon = "1.5" serde = { version = "1.0.118", features = ["derive"], optional = true } serde-big-array = { version = "0.3.1", optional = true } diff --git a/instant-distance/benches/all.rs b/instant-distance/benches/all.rs index 60b422b..78a0ecf 100644 --- a/instant-distance/benches/all.rs +++ b/instant-distance/benches/all.rs @@ -1,5 +1,5 @@ use bencher::{benchmark_group, benchmark_main, Bencher}; -use rand::rngs::{StdRng, ThreadRng}; +use rand::rngs::StdRng; //, ThreadRng}; use rand::{Rng, SeedableRng}; use instant_distance::Builder; @@ -8,14 +8,18 @@ benchmark_main!(benches); benchmark_group!(benches, build_heuristic); fn build_heuristic(bench: &mut Bencher) { - let seed = ThreadRng::default().gen::(); - let mut rng = StdRng::seed_from_u64(seed); - let points = (0..1024) + //let seed = dbg!(ThreadRng::default().gen::()); + let mut rng = StdRng::seed_from_u64(11823281459843198809); //seed); + let points = (0..512) .into_iter() .map(|_| Point(rng.gen(), rng.gen())) .collect::>(); - bench.iter(|| Builder::default().seed(seed).build_hnsw(points.clone())) + bench.iter(|| { + Builder::default() + .seed(11823281459843198809) + .build_hnsw(points.clone()) + }) } /* diff --git a/instant-distance/src/lib.rs b/instant-distance/src/lib.rs index c1f39f5..54d58be 100644 --- a/instant-distance/src/lib.rs +++ b/instant-distance/src/lib.rs @@ -10,7 +10,7 @@ use ordered_float::OrderedFloat; use parking_lot::{Mutex, RwLock}; use rand::rngs::SmallRng; use rand::{Rng, SeedableRng}; -use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator}; +//use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -291,7 +291,7 @@ where } let end = range.end; - nodes[range].into_par_iter().for_each(|(_, pid)| { + nodes[range].into_iter().for_each(|(_, pid)| { let node = zero.as_slice()[*pid].write(); let (mut search, mut insertion) = pool.pop(); let point = &points.as_slice()[*pid]; @@ -337,11 +337,10 @@ where // For layers above the zero layer, make a copy of the current state of the zero layer // with `nearest` truncated to `M` elements. if !layer.is_zero() { - let mut upper = Vec::new(); - (&zero[..end]) - .into_par_iter() + let upper = (&zero[..end]) + .into_iter() .map(|zero| UpperNode::from_zero(&zero.read())) - .collect_into_vec(&mut upper); + .collect(); layers[layer.0 - 1] = upper; } }