+ # @torch.compile
+ def rec_coo_(self, nb_rec, min_height=3, min_width=3):
+ # @torch.compile
+ def overlap(ia, ja, ib, jb):
+ return (
+ ia[1] >= ib[0] and ia[0] <= ib[1] and ja[1] >= jb[0] and ja[0] <= jb[1]
+ )
+
+ if nb_rec == 3:
+ while True:
+ i = torch.randint(self.height + 1, (nb_rec, 2)).sort(dim=1).values
+ j = torch.randint(self.width + 1, (nb_rec, 2)).sort(dim=1).values
+ if (
+ not (
+ overlap(i[0], j[0], i[1], j[1])
+ or overlap(i[0], j[0], i[2], j[2])
+ or overlap(i[1], j[1], i[2], j[2])
+ )
+ and (i[:, 1] - i[:, 0]).min() >= min_height
+ and (j[:, 1] - j[:, 0]).min() >= min_width
+ ):
+ break
+ return (
+ (i[0, 0], j[0, 0], i[0, 1], j[0, 1]),
+ (i[1, 0], j[1, 0], i[1, 1], j[1, 1]),
+ (i[2, 0], j[2, 0], i[2, 1], j[2, 1]),
+ )
+