Skip to main content

superkmeans/
lib.rs

1//! Rust port of SuperKMeans — a fast k-means clustering library for
2//! high-dimensional vector embeddings using BLAS+ADSampling pruning.
3//!
4//! The C++ original lives in `SuperKMeans/`; this crate re-implements the
5//! C++ public API (no Python surface) in pure Rust with no FFI dependencies.
6
7// The numeric kernels favor explicit index arithmetic and wide, positional
8// argument lists that mirror the C++ original, so a handful of Clippy style
9// lints are relaxed crate-wide rather than obscuring the ports.
10#![allow(
11    clippy::needless_range_loop,
12    clippy::too_many_arguments,
13    clippy::manual_memcpy,
14    clippy::field_reassign_with_default,
15    clippy::doc_lazy_continuation
16)]
17
18// OpenBLAS is linked by `build.rs` (via pkg-config or OPENBLAS_LIB_DIR);
19// Accelerate is linked by the framework attribute in `gemm.rs`.
20#[cfg(all(
21    feature = "blas",
22    not(any(feature = "accelerate", feature = "openblas"))
23))]
24compile_error!(
25    "the `blas` feature is a marker — enable a concrete backend instead: \
26     `accelerate` (macOS) or `openblas` (Linux/Windows/macOS)"
27);
28
29pub mod adsampling;
30pub mod batch;
31pub mod common;
32pub mod distance;
33pub mod gemm;
34pub mod hierarchical;
35pub mod layout;
36pub mod pdxearch;
37pub mod superkmeans;
38pub mod utils;
39
40pub use common::{DistanceFunction, KnnCandidate};
41pub use hierarchical::{
42    HierarchicalSuperKMeans, HierarchicalSuperKMeansConfig, HierarchicalSuperKMeansIterationStats,
43};
44pub use superkmeans::{
45    ClusterBalanceStats, SuperKMeans, SuperKMeansConfig, SuperKMeansIterationStats,
46};
47pub use utils::{
48    TicToc, compute_l2_squared, compute_norms_row_major, find_nearest_neighbor_brute_force,
49    generate_random_vectors, make_blobs,
50};