@@ -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) ]
5958fn 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) ]
101106fn 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) ]
180187fn 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