From 28568404ec08aa535a79b36a07288ff9cd59f4ae Mon Sep 17 00:00:00 2001 From: Nityahiray Date: Sat, 21 Mar 2026 12:15:25 +0530 Subject: [PATCH] Fix: complete iterator implementation for arbitrary tile ranges Refactor iterator method for improved readability and efficiency. --- csa/_misc.py | 48 +++++++++++++----------------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/csa/_misc.py b/csa/_misc.py index ec7abe4..e6c86b1 100644 --- a/csa/_misc.py +++ b/csa/_misc.py @@ -233,41 +233,19 @@ 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: - return - - + jj = (low1 // self.N) * self.N + while jj < high1: + ii = (low0 // self.M) * self.M + while ii < high0: + maskIter = self.m.iterator (0, self.M, 0, self.N, state) + for (i,j) in maskIter: + gi = ii + i + gj = jj + j + if low0 <= gi < high0 and low1 <= gj < high1: + yield (gi, gj) + ii += self.M + jj += self.N + class Transpose (cs.Operator): def __mul__ (self, other): c = cs.coerceCSet (other)