Skip to content

Commit ce476ff

Browse files
committed
replace allow clippy lints with expect
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 4048756 commit ce476ff

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

vortex-tensor/public-api.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::arity(&self, _opt
416416

417417
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::child_name(&self, _options: &Self::Options, child_idx: usize) -> vortex_array::scalar_fn::vtable::ChildName
418418

419-
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::execute(&self, options: &Self::Options, args: &dyn vortex_array::scalar_fn::vtable::ExecutionArgs, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::array::erased::ArrayRef>
419+
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::execute(&self, _options: &Self::Options, args: &dyn vortex_array::scalar_fn::vtable::ExecutionArgs, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_array::array::erased::ArrayRef>
420420

421421
pub fn vortex_tensor::scalar_fns::inner_product::InnerProduct::fmt_sql(&self, _options: &Self::Options, expr: &vortex_array::expr::expression::Expression, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
422422

vortex-tensor/src/encodings/turboquant/array/centroids.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ pub fn find_nearest_centroid(value: f32, boundaries: &[f32]) -> u8 {
221221
}
222222

223223
#[cfg(test)]
224-
#[allow(clippy::cast_possible_truncation)]
225224
mod tests {
226225
use rstest::rstest;
227226
use vortex_error::VortexResult;
@@ -312,9 +311,11 @@ mod tests {
312311
let boundaries = compute_centroid_boundaries(&centroids);
313312
assert_eq!(find_nearest_centroid(-1.0, &boundaries), 0);
314313

314+
#[expect(clippy::cast_possible_truncation)]
315315
let last_idx = (centroids.len() - 1) as u8;
316316
assert_eq!(find_nearest_centroid(1.0, &boundaries), last_idx);
317317
for (idx, &cv) in centroids.iter().enumerate() {
318+
#[expect(clippy::cast_possible_truncation)]
318319
let expected = idx as u8;
319320
assert_eq!(find_nearest_centroid(cv, &boundaries), expected);
320321
}

vortex-tensor/src/encodings/turboquant/array/data.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ impl TurboQuantData {
139139
TurboQuant::MAX_CENTROIDS
140140
);
141141

142-
// Guaranteed to be 1-MAX_BIT_WIDTH by the preceding power-of-2 and range checks.
143-
#[expect(clippy::cast_possible_truncation)]
142+
#[expect(
143+
clippy::cast_possible_truncation,
144+
reason = "Guaranteed to be [1,8] by the preceding power-of-2 and range checks."
145+
)]
144146
let bit_width = num_centroids.trailing_zeros() as u8;
145147
vortex_ensure!(
146148
(1..=TurboQuant::MAX_BIT_WIDTH).contains(&bit_width),

vortex-tensor/src/encodings/turboquant/compress.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ impl Default for TurboQuantConfig {
5555
/// Extract elements from a FixedSizeListArray as a flat f32 PrimitiveArray for quantization.
5656
///
5757
/// All quantization (rotation, centroid lookup) happens in f32. f16 is upcast; f64 is truncated.
58-
#[allow(clippy::cast_possible_truncation)]
5958
fn extract_f32_elements(
6059
fsl: &FixedSizeListArray,
6160
ctx: &mut ExecutionCtx,
@@ -74,7 +73,14 @@ fn extract_f32_elements(
7473
PType::F64 => Ok(primitive
7574
.as_slice::<f64>()
7675
.iter()
77-
.map(|&v| v as f32)
76+
.map(|&v| {
77+
#[expect(
78+
clippy::cast_possible_truncation,
79+
reason = "TurboQuant quantization operates in f32, so f64 inputs are intentionally downcast"
80+
)]
81+
let v = v as f32;
82+
v
83+
})
7884
.collect()),
7985
_ => vortex_bail!("TurboQuant requires float elements, got {ptype:?}"),
8086
}
@@ -97,7 +103,6 @@ struct QuantizationResult {
97103
/// Norms are computed in the native element precision via the [`L2Norm`] scalar function.
98104
/// The rotation and centroid lookup happen in f32. Null rows (per the input validity) produce
99105
/// all-zero codes.
100-
#[allow(clippy::cast_possible_truncation)]
101106
fn turboquant_quantize_core(
102107
ext: ArrayView<Extension>,
103108
fsl: &FixedSizeListArray,
@@ -106,7 +111,8 @@ fn turboquant_quantize_core(
106111
validity: &Validity,
107112
ctx: &mut ExecutionCtx,
108113
) -> VortexResult<QuantizationResult> {
109-
let dimension = fsl.list_size() as usize;
114+
let dimension =
115+
usize::try_from(fsl.list_size()).vortex_expect("u32 FixedSizeList dimension fits in usize");
110116
let num_rows = fsl.len();
111117

112118
// Compute native-precision norms via the L2Norm scalar fn. L2Norm propagates validity from
@@ -130,10 +136,12 @@ fn turboquant_quantize_core(
130136

131137
let rotation = RotationMatrix::try_new(seed, dimension)?;
132138
let padded_dim = rotation.padded_dim();
139+
let padded_dim_u32 =
140+
u32::try_from(padded_dim).vortex_expect("padded_dim stays representable as u32");
133141

134142
let f32_elements = extract_f32_elements(fsl, ctx)?;
135143

136-
let centroids = get_centroids(padded_dim as u32, bit_width)?;
144+
let centroids = get_centroids(padded_dim_u32, bit_width)?;
137145
let boundaries = compute_centroid_boundaries(&centroids);
138146

139147
let mut all_indices = BufferMut::<u8>::with_capacity(num_rows * padded_dim);
@@ -176,19 +184,20 @@ fn turboquant_quantize_core(
176184
}
177185

178186
/// Build a `TurboQuantArray` from quantization results.
179-
#[allow(clippy::cast_possible_truncation)]
180187
fn build_turboquant(
181188
fsl: &FixedSizeListArray,
182189
core: QuantizationResult,
183190
ext_dtype: DType,
184191
) -> VortexResult<TurboQuantArray> {
185192
let num_rows = fsl.len();
186193
let padded_dim = core.padded_dim;
194+
let padded_dim_u32 =
195+
u32::try_from(padded_dim).vortex_expect("padded_dim stays representable as u32");
187196
let codes_elements =
188197
PrimitiveArray::new::<u8>(core.all_indices.freeze(), Validity::NonNullable);
189198
let codes = FixedSizeListArray::try_new(
190199
codes_elements.into_array(),
191-
padded_dim as u32,
200+
padded_dim_u32,
192201
Validity::NonNullable,
193202
num_rows,
194203
)?

0 commit comments

Comments
 (0)