accepts a wire as a bus

This commit is contained in:
Vojta Mrazek 2023-03-23 13:39:32 +01:00
parent 363e402e16
commit 49bbc86a0f
2 changed files with 22 additions and 0 deletions

View File

@ -255,6 +255,11 @@ class Wire():
else:
return f"<w={self.name}>"
""" define read-only parameter N"""
@property
def N(self):
return 1
# Wires with constant values #
class ConstantWireValue0(Wire):

View File

@ -341,3 +341,20 @@ def test_direct():
expected = np.array([[0, 3, 0, 3], [2, 3, 2, 3], [0, 3, 0, 3], [2, 3, 2, 3]])
np.testing.assert_equal(r, expected)
print(r)
def test_wire_as_bus():
""" accept a wire as a bus """
class test_circuit(GeneralCircuit):
def __init__(self, a: Wire, b: Wire, c: Bus, prefix="test_circuit", **kwargs):
super().__init__(prefix=prefix, name="test_circuit", inputs=[a, b, c], out_N=1, **kwargs)
g = self.add_component(AndGate(a, b, prefix="g2"))
g2 = self.add_component(AndGate(g.out, c[0], prefix="g2"))
g3 = self.add_component(AndGate(g2.out, c[1], prefix="g2"))
self.out[0] = g3.out
circ = test_circuit(Wire("a"), Wire("b"), Bus("c", 2), "c1")
r = circ(np.array([0, 1]),
np.array([0, 1]).reshape(-1, 1),
np.arange(4).reshape(-1, 1, 1))
assert r.sum() == 1
assert r[-1, -1, -1] == 1