def test_positive_fusion(self): t = Tiling( obstructions=[ GriddedPerm((0, 1), [(0, 0), (0, 0)]), GriddedPerm((0, 1), [(0, 0), (1, 0)]), GriddedPerm((0, 1), [(1, 0), (1, 0)]), ], requirements=[[GriddedPerm((0, ), [(0, 0)])]], ) algo = Fusion(t, col_idx=0) assert algo.min_left_right_points() == (1, 0)
def __call__(self, comb_class: Tiling) -> Iterator[Rule]: cols, rows = comb_class.dimensions for row_idx in range(rows - 1): algo = Fusion( comb_class, row_idx=row_idx, tracked=self.tracked, isolation_level=self.isolation_level, ) if algo.fusable(): fused_tiling = algo.fused_tiling() yield FusionStrategy(row_idx=row_idx, tracked=self.tracked)(comb_class, (fused_tiling, )) for col_idx in range(cols - 1): algo = Fusion( comb_class, col_idx=col_idx, tracked=self.tracked, isolation_level=self.isolation_level, ) if algo.fusable(): fused_tiling = algo.fused_tiling() yield FusionStrategy(col_idx=col_idx, tracked=self.tracked)(comb_class, (fused_tiling, ))
def test_fusing_empty_region(self): tiling = Tiling( obstructions=( GriddedPerm((0, 1), ((0, 0), (0, 0))), GriddedPerm((0, 1), ((0, 0), (0, 1))), GriddedPerm((0, 1), ((0, 1), (0, 1))), GriddedPerm((1, 0), ((0, 3), (0, 0))), GriddedPerm((1, 0), ((0, 3), (0, 1))), GriddedPerm((0, 1, 2), ((0, 0), (0, 2), (0, 2))), GriddedPerm((0, 1, 2), ((0, 0), (0, 2), (0, 3))), GriddedPerm((0, 1, 2), ((0, 0), (0, 3), (0, 3))), GriddedPerm((0, 1, 2), ((0, 1), (0, 2), (0, 2))), GriddedPerm((0, 1, 2), ((0, 1), (0, 2), (0, 3))), GriddedPerm((0, 1, 2), ((0, 1), (0, 3), (0, 3))), GriddedPerm((0, 1, 2), ((0, 2), (0, 2), (0, 2))), GriddedPerm((0, 1, 2), ((0, 2), (0, 3), (0, 3))), GriddedPerm((2, 0, 1), ((0, 3), (0, 2), (0, 2))), GriddedPerm((0, 1, 2, 3), ((0, 3), (0, 3), (0, 3), (0, 3))), GriddedPerm((0, 2, 3, 1), ((0, 2), (0, 2), (0, 3), (0, 2))), GriddedPerm((0, 2, 3, 1), ((0, 3), (0, 3), (0, 3), (0, 3))), GriddedPerm((3, 0, 1, 2), ((0, 3), (0, 3), (0, 3), (0, 3))), ), requirements=((GriddedPerm((0, 1), ((0, 3), (0, 3))), ), ), assumptions=(TrackingAssumption((GriddedPerm((0, ), ((0, 0), )), )), ), ) assert not Fusion(tiling, col_idx=0, tracked=True).fusable()
def test_rule(row_fusion): assert row_fusion.formal_step == "fuse rows 0 and 1" assert list(row_fusion.children) == [ Fusion(row_fusion.comb_class, row_idx=0).fused_tiling() ] assert row_fusion.inferrable assert row_fusion.workable assert not row_fusion.possibly_empty assert isinstance(row_fusion.constructor, FusionConstructor)
def test_fusable(self, row_fusion, col_fusion, col_fusion_big, fusion_with_req): assert row_fusion.fusable() assert col_fusion.fusable() assert fusion_with_req.fusable() assert not col_fusion_big.fusable() t = Tiling(obstructions=[ GriddedPerm((0, 1), ((0, 0), (0, 0))), GriddedPerm((0, 1), ((1, 0), (1, 0))), ]) assert not Fusion(t, row_idx=0).fusable()
def fusion_algorithm(self, tiling: Tiling) -> Fusion: return Fusion( tiling, row_idx=self.row_idx, col_idx=self.col_idx, tracked=self.tracked )
def col_fusion_big(self, big_tiling): return Fusion(big_tiling, col_idx=0)
def fusion_with_req(self, tiling_with_req): return Fusion(tiling_with_req, col_idx=0)
def col_fusion(self, small_tiling): return Fusion(small_tiling, col_idx=0)
def row_fusion(self, small_tiling): return Fusion(small_tiling, row_idx=0)
def test_unfuse_gridded_perm(self): rf0 = Fusion(Tiling(), row_idx=0) rf1 = Fusion(Tiling(), row_idx=1) cf0 = Fusion(Tiling(), col_idx=0) ob1 = GriddedPerm((0, 1, 2, 3), ((0, 0), (0, 1), (0, 1), (0, 2))) assert list(rf1.unfuse_gridded_perm(ob1)) == [ GriddedPerm((0, 1, 2, 3), ((0, 0), (0, 2), (0, 2), (0, 3))), GriddedPerm((0, 1, 2, 3), ((0, 0), (0, 1), (0, 2), (0, 3))), GriddedPerm((0, 1, 2, 3), ((0, 0), (0, 1), (0, 1), (0, 3))), ] ob2 = GriddedPerm((0, 2, 1, 3), ((0, 0), (0, 1), (0, 1), (0, 2))) assert list(rf1.unfuse_gridded_perm(ob2)) == [ GriddedPerm((0, 2, 1, 3), ((0, 0), (0, 2), (0, 2), (0, 3))), GriddedPerm((0, 2, 1, 3), ((0, 0), (0, 2), (0, 1), (0, 3))), GriddedPerm((0, 2, 1, 3), ((0, 0), (0, 1), (0, 1), (0, 3))), ] ob3 = GriddedPerm((0, 2, 1, 4, 3), ((0, 0), (0, 1), (0, 1), (0, 2), (0, 1))) assert list(rf1.unfuse_gridded_perm(ob3)) == [ GriddedPerm((0, 2, 1, 4, 3), ((0, 0), (0, 2), (0, 2), (0, 3), (0, 2))), GriddedPerm((0, 2, 1, 4, 3), ((0, 0), (0, 2), (0, 1), (0, 3), (0, 2))), GriddedPerm((0, 2, 1, 4, 3), ((0, 0), (0, 1), (0, 1), (0, 3), (0, 2))), GriddedPerm((0, 2, 1, 4, 3), ((0, 0), (0, 1), (0, 1), (0, 3), (0, 1))), ] ob4 = GriddedPerm((0, 2, 3, 1), ((0, 0), (0, 1), (1, 1), (1, 0))) assert list(rf0.unfuse_gridded_perm(ob4)) == [ GriddedPerm((0, 2, 3, 1), ((0, 1), (0, 2), (1, 2), (1, 1))), GriddedPerm((0, 2, 3, 1), ((0, 0), (0, 2), (1, 2), (1, 1))), GriddedPerm((0, 2, 3, 1), ((0, 0), (0, 2), (1, 2), (1, 0))), ] assert list(cf0.unfuse_gridded_perm(ob4)) == [ GriddedPerm((0, 2, 3, 1), ((1, 0), (1, 1), (2, 1), (2, 0))), GriddedPerm((0, 2, 3, 1), ((0, 0), (1, 1), (2, 1), (2, 0))), GriddedPerm((0, 2, 3, 1), ((0, 0), (0, 1), (2, 1), (2, 0))), ] # Unfuse column ob5 = GriddedPerm((2, 0, 1), ((0, 0), (0, 0), (0, 0))) assert list(cf0.unfuse_gridded_perm(ob5)) == [ GriddedPerm((2, 0, 1), ((1, 0), (1, 0), (1, 0))), GriddedPerm((2, 0, 1), ((0, 0), (1, 0), (1, 0))), GriddedPerm((2, 0, 1), ((0, 0), (0, 0), (1, 0))), GriddedPerm((2, 0, 1), ((0, 0), (0, 0), (0, 0))), ] # Unfuse pattern with no point in the fuse region ob6 = GriddedPerm((0, 1, 2), ((1, 0), (1, 0), (1, 0))) assert list(cf0.unfuse_gridded_perm(ob6)) == [ GriddedPerm((0, 1, 2), ((2, 0), (2, 0), (2, 0))), ] ob6 = GriddedPerm((1, 0, 2), ((0, 0), (0, 0), (1, 0))) assert list(cf0.unfuse_gridded_perm(ob6)) == [ GriddedPerm((1, 0, 2), ((1, 0), (1, 0), (2, 0))), GriddedPerm((1, 0, 2), ((0, 0), (1, 0), (2, 0))), GriddedPerm((1, 0, 2), ((0, 0), (0, 0), (2, 0))), ]
def test_init(self, small_tiling): Fusion(small_tiling, row_idx=0) Fusion(small_tiling, col_idx=0) with pytest.raises(RuntimeError): Fusion(small_tiling, row_idx=0, col_idx=1)