File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,6 +84,11 @@ type Result<T> = anyhow::Result<T>;
8484const DEFAULT_PROGRESS_TEMPLATE : & str =
8585 "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {count}/{total} ({eta})" ;
8686
87+ /// Minimum value for quantized scores.
88+ const MIN_QUANTIZED_VALUE : i32 = 1 ;
89+ /// Maximum value for quantized scores.
90+ const MAX_QUANTIZED_VALUE : i32 = 255 ;
91+
8792/// Wraps [`proto::Header`] and additionally provides some important counts that are already cast
8893/// to an unsigned type.
8994#[ derive( PartialEq , Clone , Default ) ]
@@ -944,8 +949,9 @@ impl JsonlToCiff {
944949 0 // Will be filtered out below
945950 } else {
946951 let normalized = ( score - min_score) / ( max_score - min_score) ;
947- let quantized = ( normalized * 254.0 + 1.0 ) . round ( ) as i32 ;
948- quantized. max ( 1 ) . min ( 255 )
952+ let quantization_range = MAX_QUANTIZED_VALUE - MIN_QUANTIZED_VALUE ;
953+ let quantized = ( normalized * quantization_range as f64 + MIN_QUANTIZED_VALUE as f64 ) . round ( ) as i32 ;
954+ quantized. clamp ( MIN_QUANTIZED_VALUE , MAX_QUANTIZED_VALUE )
949955 }
950956 } else {
951957 // Assume scores are already pre-quantized integers
You can’t perform that action at this time.
0 commit comments