Skip to content

Commit b68c706

Browse files
committed
Upsampling BVDDs works, needs more testing
1 parent d6cbf78 commit b68c706

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

tools/bvdd.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -287,54 +287,58 @@ def swap(self):
287287
for i in pt])
288288
return new_bvdd.link(swap2right_bvdd, return_tuples)
289289

290-
def unapply(self, a_rt_inv, rt = None, rt_inv = None, index = 0):
290+
def unapply(self, b_rt_inv, rt = None, rt_inv = None, index = 0):
291291
new_bvdd = type(self)({})
292-
a_rt_inv = a_rt_inv if a_rt_inv is not None else {}
292+
b_rt_inv = b_rt_inv if b_rt_inv is not None else {}
293293
rt = rt if rt is not None else {}
294294
rt_inv = rt_inv if rt_inv is not None else {}
295295
s2o = self.get_s2o()
296296
for inputs in s2o:
297297
output = s2o[inputs]
298298
if isinstance(output, BVDD):
299-
output, a_rt_inv, rt, rt_inv = output.unapply(a_rt_inv, rt, rt_inv, index + 1)
299+
output, b_rt_inv, rt, rt_inv = output.unapply(b_rt_inv, rt, rt_inv, index + 1)
300300
new_bvdd.set(inputs, output)
301301
else:
302302
if output not in rt_inv:
303303
rt_inv[output] = len(rt_inv) + 1
304-
if output not in a_rt_inv:
305-
a_rt_inv[output] = len(a_rt_inv) + 1
306-
rt[rt_inv[output]] = a_rt_inv[output]
304+
if output not in b_rt_inv:
305+
b_rt_inv[output] = len(b_rt_inv) + 1
306+
rt[rt_inv[output]] = b_rt_inv[output]
307307
new_bvdd.set(inputs, rt_inv[output])
308-
return new_bvdd.reduce_SBDD().reduce_BVDD(index), a_rt_inv, rt, rt_inv
308+
return new_bvdd.reduce_SBDD().reduce_BVDD(index), b_rt_inv, rt, rt_inv
309309

310-
def upsample(self, level, a_rt_inv = None, b_cs = None, b_rts = None, index = 0):
310+
def upsample(self, level, a_rt_inv = None, b_rt_inv = None, b_cs = None, b_rts = None, index = 0):
311311
assert level > 0
312312
a_c = type(self)({})
313313
a_rt_inv = a_rt_inv if a_rt_inv is not None else {}
314+
b_rt_inv = b_rt_inv if b_rt_inv is not None else {}
314315
b_cs = b_cs if b_cs is not None else {}
315316
b_rts = b_rts if b_rts is not None else {}
316317
s2o = self.get_s2o()
317318
for inputs in s2o:
318319
output = s2o[inputs]
319320
if isinstance(output, BVDD):
320321
if index < 2**(level - 1) - 1:
321-
output, a_rt_inv, b_cs, b_rts = output.upsample(level,
322-
a_rt_inv, b_cs, b_rts, index + 1)
322+
output, a_rt_inv, b_rt_inv, b_cs, b_rts = output.upsample(level,
323+
a_rt_inv, b_rt_inv, b_cs, b_rts, index + 1)
323324
a_c.set(inputs, output)
324325
else:
325-
output, a_rt_inv, rt, rt_inv = output.unapply(a_rt_inv)
326-
if output not in a_rt_inv:
327-
a_rt_inv[output] = len(a_rt_inv) + 1
328-
b_cs[a_rt_inv[output]] = output
329-
b_rts[a_rt_inv[output]] = rt
330-
a_c.set(inputs, a_rt_inv[output])
326+
output, b_rt_inv, rt, rt_inv = output.unapply(b_rt_inv)
327+
key = (output, tuple(rt.values()))
328+
if key not in a_rt_inv:
329+
a_rt_inv[key] = len(a_rt_inv) + 1
330+
b_cs[a_rt_inv[key]] = output
331+
b_rts[a_rt_inv[key]] = rt
332+
a_c.set(inputs, a_rt_inv[key])
331333
else:
332334
if output not in a_rt_inv:
333335
a_rt_inv[output] = len(a_rt_inv) + 1
336+
if output not in b_rt_inv:
337+
b_rt_inv[output] = len(b_rt_inv) + 1
334338
b_cs[a_rt_inv[output]] = BVDD.constant(1)
335-
b_rts[a_rt_inv[output]] = {1:a_rt_inv[output]}
339+
b_rts[a_rt_inv[output]] = {1:b_rt_inv[output]}
336340
a_c.set(inputs, a_rt_inv[output])
337-
return a_c.reduce_SBDD().reduce_BVDD(index), a_rt_inv, b_cs, b_rts
341+
return a_c.reduce_SBDD().reduce_BVDD(index), a_rt_inv, b_rt_inv, b_cs, b_rts
338342

339343
def downsample(self, bvdds, return_tuples):
340344
# apply to bvdds may reduce to constants

tools/cflobvdd.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,12 @@ def upsample(self):
382382
if self.is_upsample_cached():
383383
return self.get_cached_upsample()
384384

385-
g_a_bvdd, _, g_b_bvdds, g_b_return_tuples = self.bvdd.upsample(self.level)
385+
g_a_bvdd, g_a_rt_inv, g_b_rt_inv, g_b_bvdds, g_b_return_tuples = self.bvdd.upsample(self.level)
386+
387+
assert g_a_bvdd.number_of_exits() == len(g_a_rt_inv)
386388

387389
# TODO: enable different input orderings
388-
g = BV_Internal_Grouping(self.level, self.swap_level, self.fork_level, True,
389-
len(g_b_return_tuples))
390+
g = BV_Internal_Grouping(self.level, self.swap_level, self.fork_level, True, len(g_b_rt_inv))
390391

391392
if g_a_bvdd.is_constant():
392393
g.a_connection = BV_No_Distinction_Proto.representative(self.level - 1,
@@ -414,9 +415,6 @@ def upsample(self):
414415

415416
g.b_return_tuples = g_b_return_tuples
416417

417-
if g.a_connection.is_no_distinction_proto():
418-
print(self)
419-
420418
if (g.a_connection.is_no_distinction_proto() and
421419
g.number_of_b_connections == 1 and
422420
g.b_connections[1].is_no_distinction_proto()):
@@ -521,8 +519,6 @@ def reduce(self, reduction_tuple):
521519

522520
bvdd = self.bvdd.reduce(reduction_tuple)
523521

524-
assert self.level == self.fork_level
525-
526522
if bvdd.is_constant():
527523
g = No_Distinction_Proto.representative(self.level,
528524
self.swap_level, self.fork_level)

0 commit comments

Comments
 (0)