π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix clippy findings in OCR test code and helper placement
laurenspriemac28f874ca9e
diff --git a/rust/crates/ml/src/ocr/context.rs b/rust/crates/ml/src/ocr/context.rsindex d45c8dfef1..16481cfe8e 100644--- a/rust/crates/ml/src/ocr/context.rs+++ b/rust/crates/ml/src/ocr/context.rs@@ -286,13 +286,10 @@ mod tests {3 => 704,_ => 960,} / mask.shape[2] as usize;- assert_eq!(- mask.values.iter().filter(|&&v| v == 1.0).count(),- height * width / (scale * scale)- );+ let active = height / scale * (width / scale);+ assert_eq!(mask.values.iter().filter(|&&v| v == 1.0).count(), active);let scale_name = mask.name.replace("mask", "pool_scale");if let Some(pool_scale) = inputs.iter().find(|input| input.name == scale_name) {- let active = height * width / (scale * scale);assert!((pool_scale.values[0] * active as f32 / mask.values.len() as f32 - 1.0).abs()diff --git a/rust/crates/ml/src/ocr/recognize.rs b/rust/crates/ml/src/ocr/recognize.rsindex f738d77abb..a823c02a51 100644--- a/rust/crates/ml/src/ocr/recognize.rs+++ b/rust/crates/ml/src/ocr/recognize.rs@@ -427,6 +427,35 @@ fn mean_confidence(spans: &[CharacterSpan]) -> f32 {spans.iter().map(|span| span.confidence).sum::<f32>() / spans.len() as f32}+fn choose_packed_width(pending: &[usize], lines: &[super::context::Line]) -> usize {+ let mut best_width = 7168;+ let mut best_cost = f64::INFINITY;+ for &width in super::context::branch_widths() {+ if width < lines[pending[0]].width {+ continue;+ }+ let mut used = 0;+ let mut payload = 0;+ let mut count = 0;+ for &index in pending {+ let size = lines[index].width.div_ceil(8) * 8;+ if count < width / 336 && used + size <= width {+ used += size + 16;+ payload += lines[index].width;+ count += 1;+ }+ }+ if payload > 0 {+ let cost = (width + 128) as f64 / payload as f64;+ if cost < best_cost {+ best_cost = cost;+ best_width = width;+ }+ }+ }+ best_width+}+#[cfg(test)]mod tests {use super::*;@@ -632,7 +661,9 @@ mod tests {};let expected = decode_output(&[2, 6, 4], &full, &layout, &dictionary()).unwrap();let actual: Vec<_> = compact- .chunks_exact(12)+ .as_chunks::<12>()+ .0+ .iter().zip(&layout.content_widths).map(|(values, &content_width)| {decode_line(@@ -1196,32 +1227,3 @@ mod tests {assert!(matches!(error, OcrError::Cancelled));}}--fn choose_packed_width(pending: &[usize], lines: &[super::context::Line]) -> usize {- let mut best_width = 7168;- let mut best_cost = f64::INFINITY;- for &width in super::context::branch_widths() {- if width < lines[pending[0]].width {- continue;- }- let mut used = 0;- let mut payload = 0;- let mut count = 0;- for &index in pending {- let size = lines[index].width.div_ceil(8) * 8;- if count < width / 336 && used + size <= width {- used += size + 16;- payload += lines[index].width;- count += 1;- }- }- if payload > 0 {- let cost = (width + 128) as f64 / payload as f64;- if cost < best_cost {- best_cost = cost;- best_width = width;- }- }- }- best_width-}