self.task_scale,
self.task_symbols,
self.task_isometry,
- # self.task_path,
+ self.task_islands,
]
if tasks is None:
1000,
self.height,
self.width,
- nb_seeds=self.height * self.width // 9,
- nb_iterations=self.height * self.width // 20,
+ nb_seeds=self.height * self.width // 8,
+ nb_iterations=self.height * self.width // 10,
)
)
def task_islands(self, A, f_A, B, f_B):
c = torch.randperm(len(self.colors) - 1)[:2] + 1
for X, f_X in [(A, f_A), (B, f_B)]:
- while True:
- k = torch.randperm(self.height * self.width)
- Z = torch.zeros(self.height + 2, self.width + 2)
-
- i0, j0 = (
- torch.randint(self.height, (1,)).item() + 1,
- torch.randint(self.width, (1,)).item() + 1,
+ if not hasattr(self, "cache_islands") or len(self.cache_islands) == 0:
+ self.cache_islands = list(
+ grow_islands(
+ 1000,
+ self.height,
+ self.width,
+ nb_seeds=self.height * self.width // 20,
+ nb_iterations=self.height * self.width // 2,
+ )
)
- Z[i0 - 1 : i0 + 2, j0 - 1 : j0 + 2] = 1
-
- nb = 9
-
- for q in k:
- i, j = q % self.height + 1, q // self.height + 1
-
- if Z[i, j] == 0:
- r, s, t, u, v, w, x, y = (
- Z[i - 1, j],
- Z[i - 1, j + 1],
- Z[i, j + 1],
- Z[i + 1, j + 1],
- Z[i + 1, j],
- Z[i + 1, j - 1],
- Z[i, j - 1],
- Z[i - 1, j - 1],
- )
-
- if (
- (nb < 16 or r + s + t + u + v + w + x + y > 0)
- and (s == 0 or r + t > 0)
- and (u == 0 or t + v > 0)
- and (w == 0 or x + v > 0)
- and (y == 0 or x + r > 0)
- ):
- # if r+s+t+u+v+w+x+y==0:
- Z[i, j] = 1
- nb += 1
-
- if nb == self.height * self.width // 2:
- break
-
- if nb == self.height * self.width // 2:
- break
-
- M = Z.clone()
- Z[i0, j0] = 2
- X[...] = (Z[1:-1, 1:-1] == 1) * c[0] + (Z[1:-1, 1:-1] == 2) * c[1]
+ A = self.cache_islands.pop()
- for _ in range(self.height + self.width):
- Z[1:-1, 1:-1] = Z[1:-1, 1:-1].maximum(
- torch.maximum(
- torch.maximum(Z[0:-2, 1:-1], Z[2:, 1:-1]),
- torch.maximum(Z[1:-1, 0:-2], Z[1:-1, 2:]),
- )
+ while True:
+ i, j = (
+ torch.randint(self.height // 2, (1,)).item(),
+ torch.randint(self.width // 2, (1,)).item(),
)
- Z *= M
+ if A[i, j] > 0:
+ break
- f_X[...] = (Z[1:-1, 1:-1] == 1) * c[0] + (Z[1:-1, 1:-1] == 2) * c[1]
+ X[...] = (A > 0) * c[0]
+ X[i, j] = c[1]
+ f_X[...] = (A == A[i, j]) * c[1] + ((A > 0) & (A != A[i, j])) * c[0]
######################################################################
# nb, nrow = 8, 2
# for t in grids.all_tasks:
- for t in [grids.task_count]:
+ for t in [grids.task_islands]:
print(t.__name__)
prompts, answers = grids.generate_prompts_and_answers_(nb, tasks=[t])
grids.save_quiz_illustrations(
nb = 1000
# for t in grids.all_tasks:
- for t in [grids.task_count]:
+ for t in [grids.task_islands]:
start_time = time.perf_counter()
prompts, answers = grids.generate_prompts_and_answers_(nb, tasks=[t])
delay = time.perf_counter() - start_time