Skip to content

Commit 660c165

Browse files
committed
updt: move hnsw mod to hnswcore crate pkg for more unit tests
Signed-off-by: weedge <[email protected]>
1 parent 36637fd commit 660c165

File tree

13 files changed

+53
-35
lines changed

13 files changed

+53
-35
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ redis = "0.23"
4343
redis-module = { version = "2.0.5", features = ["default"] }
4444

4545
[workspace]
46-
members = ["rust/usearch", "rust/faiss", "rust/hnsw"]
46+
members = ["rust/usearch", "rust/faiss", "rust/hnsw/hnswcore", "rust/hnsw"]

Makefile

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ build:
5959
build_faiss:
6060
export LIBRARY_PATH=/usr/local/lib && RUSTFLAGS="-C link-args=-Wl,-rpath,/usr/local/lib" cargo build --manifest-path rust/faiss/Cargo.toml $(CARGO_FLAGS)
6161

62+
build_hnswcore:
63+
cargo build --manifest-path rust/hnsw/hnswcore/Cargo.toml $(CARGO_FLAGS)
64+
6265
build_hnsw:
6366
cargo build --manifest-path rust/hnsw/Cargo.toml $(CARGO_FLAGS)
6467

@@ -76,13 +79,22 @@ endif
7679

7780
#----------------------------------------------------------------------------------------------
7881

79-
test: cargo_test
82+
test: cargo_test_workspace
83+
84+
cargo_test_workspace: build
85+
export LIBRARY_PATH=/usr/local/lib && RUSTFLAGS="-C link-args=-Wl,-rpath,/usr/local/lib" cargo test --workspace \
86+
--exclude redisxann-hnsw \
87+
--exclude redisxann-usearch \
88+
--exclude redisxann-faiss \
89+
$(CARGO_FLAGS)
8090

81-
cargo_test:
82-
export LIBRARY_PATH=/usr/local/lib && RUSTFLAGS="-C link-args=-Wl,-rpath,/usr/local/lib" cargo test --workspace $(CARGO_FLAGS)
83-
# export LIBRARY_PATH=/usr/local/lib && RUSTFLAGS="-C link-args=-Wl,-rpath,/usr/local/lib" cargo test --doc --workspace $(CARGO_FLAGS)
91+
cargo_test: build
92+
export LIBRARY_PATH=/usr/local/lib && RUSTFLAGS="-C link-args=-Wl,-rpath,/usr/local/lib" cargo test --tests $(CARGO_FLAGS)
8493

85-
.PHONY: test cargo_test
94+
cargo_test_doc:
95+
export LIBRARY_PATH=/usr/local/lib && RUSTFLAGS="-C link-args=-Wl,-rpath,/usr/local/lib" cargo test --doc --workspace $(CARGO_FLAGS)
96+
97+
.PHONY: test cargo_test cargo_test_workspace cargo_test_doc
8698

8799
#----------------------------------------------------------------------------------------------
88100

@@ -94,3 +106,5 @@ info:
94106
cargo --version
95107
rustup --version
96108
rustup show
109+
110+
.PHONY: info

rust/hnsw/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ path = "src/lib.rs"
2323
redis-module = { version = "2.0.5", features = ["default"] }
2424
lazy_static = "1.4.0"
2525
rand = "0.8.5"
26-
ordered-float = { version = "1.0.2" }
26+
ordered-float = { version = "4.1.0" }
2727
owning_ref = "0.4.1"
2828
#num = "0.4.1"
2929
num-traits = "^0.2"
30-
31-
[dev-dependencies]
32-
redis-module = { version = "2.0.5", features = ["default"] }
30+
hnswcore = { path = "./hnswcore" }

rust/hnsw/hnswcore/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "hnswcore"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
rand = "0.8.5"
10+
ordered-float = { version = "4.1.0" }
11+
owning_ref = "0.4.1"
12+
#num = "0.4.1"
13+
num-traits = "^0.2"
File renamed without changes.

rust/hnsw/src/hnsw/core.rs renamed to rust/hnsw/hnswcore/src/core.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::metrics;
22

33
use num_traits::Float;
4-
use ordered_float::OrderedFloat;
4+
use ordered_float::{FloatCore, OrderedFloat};
55
use owning_ref::{RefMutRefMut, RefRef, RwLockReadGuardRef, RwLockWriteGuardRefMut};
66
use rand::prelude::*;
77
use std::cell::RefCell;
@@ -236,7 +236,7 @@ type SimPairRef<T, R> = Rc<RefCell<_SimPair<T, R>>>;
236236
struct _SimPair<T, R>
237237
where
238238
T: Float,
239-
R: Float,
239+
R: Float + FloatCore,
240240
{
241241
pub sim: OrderedFloat<R>,
242242
pub node: Node<T>,
@@ -246,12 +246,12 @@ where
246246
struct SimPair<T, R>(SimPairRef<T, R>)
247247
where
248248
T: Float,
249-
R: Float;
249+
R: Float + FloatCore;
250250

251251
impl<T, R> SimPair<T, R>
252252
where
253253
T: Float,
254-
R: Float,
254+
R: Float + FloatCore,
255255
{
256256
fn new(sim: OrderedFloat<R>, node: Node<T>) -> Self {
257257
let sp = _SimPair { sim, node };
@@ -270,19 +270,19 @@ where
270270
impl<T, R> PartialEq for SimPair<T, R>
271271
where
272272
T: Float,
273-
R: Float,
273+
R: Float + FloatCore,
274274
{
275275
fn eq(&self, other: &Self) -> bool {
276276
self.0.borrow().sim == other.0.borrow().sim
277277
}
278278
}
279279

280-
impl<T: Float, R: Float> Eq for SimPair<T, R> {}
280+
impl<T: Float, R: Float + FloatCore> Eq for SimPair<T, R> {}
281281

282282
impl<T, R> PartialOrd for SimPair<T, R>
283283
where
284284
T: Float,
285-
R: Float,
285+
R: Float + FloatCore,
286286
{
287287
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
288288
self.0.borrow().sim.partial_cmp(&other.0.borrow().sim)
@@ -292,7 +292,7 @@ where
292292
impl<T, R> Ord for SimPair<T, R>
293293
where
294294
T: Float,
295-
R: Float,
295+
R: Float + FloatCore,
296296
{
297297
fn cmp(&self, other: &Self) -> Ordering {
298298
self.0.borrow().sim.cmp(&other.0.borrow().sim)
@@ -378,7 +378,7 @@ impl<T: Float, R: Float> fmt::Debug for Index<T, R> {
378378
impl<T, R> Index<T, R>
379379
where
380380
T: Float + Send + Sync + 'static,
381-
R: Float,
381+
R: Float + FloatCore,
382382
{
383383
pub fn add_node(
384384
&mut self,

rust/hnsw/hnswcore/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod core;
2+
pub mod metrics;
File renamed without changes.

rust/hnsw/src/hnsw/core_tests.rs renamed to rust/hnsw/hnswcore/tests/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::hnsw::core::*;
2-
use crate::hnsw::metrics::euclidean;
1+
use hnswcore::core::*;
2+
use hnswcore::metrics::euclidean;
33
use std::sync::Arc;
44
// use std::{thread, time};
55

rust/hnsw/src/hnsw/metrics_tests.rs renamed to rust/hnsw/hnswcore/tests/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::hnsw::metrics;
1+
use hnswcore::metrics;
22

33
#[test]
44
fn diff_is_zero() {

0 commit comments

Comments
 (0)