From 65f2b2b1830817267eace9b778d85e248000bf6f Mon Sep 17 00:00:00 2001 From: Nityahiray Date: Mon, 23 Mar 2026 19:51:49 +0530 Subject: [PATCH] RepeatMask.iterator: float division, NmaeError, Partial tiles Refactor iterator method to improve readability and efficiency. --- csa/_misc.py | 47 +++++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/csa/_misc.py b/csa/_misc.py index ec7abe4..93c6164 100644 --- a/csa/_misc.py +++ b/csa/_misc.py @@ -233,39 +233,22 @@ def __init__ (self, M, N, mask): self.m = mask def iterator (self, low0, high0, low1, high1, state): - try: - jj = low1 - nextHigh1 = (low1 + self.N) / self.N * self.N - while nextHigh1 <= high1: - maskIter = self.m.iterator (0, - self.M, - 0, - self.N, - state) - try: - (i, j) = next (maskIter) - post = j - while post < self.N: - pre = [] - while j == post: - pre.append (i) - (i, j) = next (maskIter) - ii = low0 - while ii < high0: - for k in pre: - yield (ii + k, jj + post) - ii += self.M - post = j - except StopIteration: - ii = low0 - while ii < high0: - for k in pre: - yield (ii + k, jj + post) - ii += self.M - jj = nextHigh1 - nextHigh1 += self.N - except StopIteration: + template = list(self.m.iterator (0, self.M, 0, self.N, state)) + if not template: return + k_min = low0 // self.M + k_max = (high0 - 1) // self.M + l_min = low1 // self.N + l_max = (high1 - 1) // self.N + for l in range (l_min, l_max + 1): + for ti, tj in template: + jj = tj + 1 * self.N + if not (low1 <= jj < high1): + continue + for k in range (k_min, k_max + 1): + ii = ti + k * self.M + if low0 <= ii < high0: + yield (ii, jj) class Transpose (cs.Operator):