Skip to content

Commit cb41112

Browse files
committed
Address comments
1 parent e89f387 commit cb41112

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ type Result<T> = anyhow::Result<T>;
8484
const 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

0 commit comments

Comments
 (0)