Skip to content

Commit 16bed6b

Browse files
author
Mark Hildebrand
committed
Small cleanups.
1 parent 429c1a5 commit 16bed6b

2 files changed

Lines changed: 23 additions & 26 deletions

File tree

‎diskann-quantization/src/product/tables/basic.rs‎

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,23 @@ where
119119

120120
/// Return a [`Strided`] for the raw pivots of the requested chunk.
121121
///
122-
/// Returns `None` if `chunk >= self.nchunks`.
122+
/// Returns `None` if `chunk >= self.nchunks()`.
123123
pub fn pivots_for(&self, chunk: usize) -> Option<Strided<'_, f32>> {
124124
let range = self.offsets.get(chunk)?;
125125

126126
#[expect(
127127
clippy::expect_used,
128128
reason = "the BasicTable's invariants mean this panic should be unreachable"
129129
)]
130-
Some(
131-
Strided::try_from_data(
132-
&self.pivots.as_slice()[range.start..],
133-
self.pivots.nrows(),
134-
range.len(),
135-
self.pivots.ncols(),
136-
)
137-
.expect("BasicTable asserts that this layout is valid"),
130+
let strided = Strided::try_from_data(
131+
&self.pivots.as_slice()[range.start..],
132+
self.pivots.nrows(),
133+
range.len(),
134+
self.pivots.ncols(),
138135
)
136+
.expect("BasicTable asserts that this layout is valid");
137+
138+
Some(strided)
139139
}
140140
}
141141

@@ -329,7 +329,7 @@ mod tests {
329329
let (pivots, offsets) = create_pivot_tables(schema.to_owned(), num_centers);
330330
let table = BasicTable::new(pivots, offsets).unwrap();
331331

332-
// Check that `pivots_for` works as expected with repsect to the documented
332+
// Check that `pivots_for` works as expected with respect to the documented
333333
// table configuration for `create_pivot_tables`.
334334
for chunk in 0..schema.len() {
335335
let strided = table.pivots_for(chunk).unwrap();
@@ -340,20 +340,17 @@ mod tests {
340340
let base = ((center + chunk) % num_centers) as f32;
341341
row.iter().enumerate().for_each(|(dim, b)| {
342342
let offset = if dim.is_multiple_of(2) { 0.25 } else { -0.25 };
343-
344-
if dim.is_multiple_of(2) {
345-
assert_eq!(
346-
*b,
347-
base + offset,
348-
"failed: chunk {} of {}, center {} of {}, dim {} of {}",
349-
chunk,
350-
schema.len(),
351-
center,
352-
num_centers,
353-
dim,
354-
row.len(),
355-
);
356-
}
343+
assert_eq!(
344+
*b,
345+
base + offset,
346+
"failed: chunk {} of {}, center {} of {}, dim {} of {}",
347+
chunk,
348+
schema.len(),
349+
center,
350+
num_centers,
351+
dim,
352+
row.len(),
353+
);
357354
})
358355
}
359356
}

‎diskann-quantization/src/product/train.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl TrainQuantizer for LightPQTrainingParameters {
6262
type Error = PQTrainingError;
6363

6464
/// Perform product quantization training on the provided training set and return a
65-
/// `SimplePivots` containing the result of kmeans clustering on each partition.
65+
/// [`BasicTable`] containing the result of kmeans clustering on each partition.
6666
///
6767
/// # Panics
6868
///
@@ -208,7 +208,7 @@ impl TrainQuantizer for LightPQTrainingParameters {
208208
BasicTable::new(packed, schema.to_owned()).map_err(|err| PQTrainingError {
209209
chunk: schema.len(),
210210
of: schema.len(),
211-
dim: data.nrows(),
211+
dim: data.ncols(),
212212
kind: PQTrainingErrorKind::InternalError(Box::new(err)),
213213
})?;
214214

0 commit comments

Comments
 (0)