1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! Rayon-backed parallel distance scan.
//!
//! The function is feature-gated to `parallel`; the sequential path in
//! [`crate::flat`] is the correctness baseline.
//!
//! ## Determinism
//!
//! The chunked computation is byte-identical to a single
//! [`iqdb_distance::compute_batch`] call over the same candidates: each
//! `(query, candidate)` pair is computed by the same per-metric kernel
//! regardless of which thread runs it, so the resulting `f32` bytes match
//! the sequential path exactly. The differential test
//! `tests/parallel_equivalence.rs` enforces this.
use ;
use *;
/// Chunk size used by the parallel scan. Small inputs short-circuit to the
/// sequential path; large inputs split into fixed-size chunks for
/// even-ish load distribution without unbounded scheduler overhead.
const PARALLEL_CHUNK: usize = 1024;
/// Compute `metric(query, candidates[i])` into `out[i]` in parallel.
///
/// `out.len()` MUST equal `candidates.len()`; the underlying
/// [`iqdb_distance::compute_batch`] surface enforces that and returns
/// [`iqdb_types::IqdbError::InvalidConfig`] otherwise.
pub