diff --git a/okolors/src/kmeans.rs b/okolors/src/kmeans.rs index 9a34a32..fe6a5e5 100644 --- a/okolors/src/kmeans.rs +++ b/okolors/src/kmeans.rs @@ -170,7 +170,7 @@ fn kmeans_plus_plus( /// Initializes the center sums and counts based off the initial centroids fn compute_initial_sums(oklab: &OklabCounts, centers: &mut CenterData, assignment: &[u8]) { - for ((color, n), ¢er) in oklab.iter().zip(assignment) { + for ((color, n), ¢er) in oklab.pairs().zip(assignment) { let i = usize::from(center); let nf = f64::from(n); let sum = &mut centers.sum[i]; @@ -211,7 +211,7 @@ fn update_assignments( points: &mut PointData, ) { let k = centers.centroid.len(); - for ((color, n), center) in oklab.iter().zip(&mut points.assignment) { + for ((color, n), center) in oklab.pairs().zip(&mut points.assignment) { let ci = usize::from(*center); let dist = D::squared_distance(color, centers.centroid[ci]); @@ -396,7 +396,7 @@ fn kmeans( } let variance = oklab - .iter() + .pairs() .zip(&points.assignment) .map(|((color, n), ¢er)| { f64::from(n) * f64::from(D::squared_distance(color, centers.centroid[usize::from(center)])) @@ -630,7 +630,7 @@ mod tests { let mut expected_sum = Oklab { l: 0.0, a: 0.0, b: 0.0 }; let mut expected_count = 0; - for (color, count) in data.iter() { + for (color, count) in data.pairs() { expected_count += count; let n = f64::from(count); expected_sum.l += n * f64::from(color.l); @@ -661,7 +661,7 @@ mod tests { update_assignments::(&data, &mut state.centers, &state.distances, &mut state.points); - for ((color, count), ¢er) in data.iter().zip(&state.points.assignment) { + for ((color, count), ¢er) in data.pairs().zip(&state.points.assignment) { let center = usize::from(center); let n = f64::from(count); let sum = &mut state.centers.sum[center]; diff --git a/okolors/src/lib.rs b/okolors/src/lib.rs index 122c0fb..16bb35a 100644 --- a/okolors/src/lib.rs +++ b/okolors/src/lib.rs @@ -192,7 +192,7 @@ impl OklabCounts { } /// Returns an iterator over each `(Oklab, count: u32)` pair - pub fn iter(&self) -> impl Iterator + '_ { + pub fn pairs(&self) -> impl Iterator + '_ { self.colors.iter().copied().zip(self.counts.iter().copied()) }