|
|
|
@ -81,6 +81,29 @@ on a signal. ``'N'``, ``'n'``, and ``'v'`` are interpreted as ``NPULSE``. |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 0 X - 1 P R F N |
|
|
|
|
|
|
|
_mv_xor = np.array([[0,1,1,3,4,5,6,7], # 0 |
|
|
|
|
|
|
|
[1,1,1,1,1,1,1,1], # X |
|
|
|
|
|
|
|
[1,1,1,1,1,1,1,1], # - |
|
|
|
|
|
|
|
[3,1,1,0,7,6,5,4], # 1 |
|
|
|
|
|
|
|
[4,1,1,7,4,5,6,7], # P |
|
|
|
|
|
|
|
[5,1,1,6,5,4,7,6], # R |
|
|
|
|
|
|
|
[6,1,1,5,6,7,4,5], # F |
|
|
|
|
|
|
|
[7,1,1,4,7,6,5,4], # N |
|
|
|
|
|
|
|
], dtype=np.uint8) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 0 X - 1 P R F N |
|
|
|
|
|
|
|
_mv_merge = np.array([[0,0,0,1,1,1,1,1], # 0 |
|
|
|
|
|
|
|
[0,1,1,3,4,5,6,7], # X |
|
|
|
|
|
|
|
[0,1,2,3,4,5,6,7], # - |
|
|
|
|
|
|
|
[1,3,3,3,1,1,1,1], # 1 |
|
|
|
|
|
|
|
[1,4,4,1,4,1,1,1], # P |
|
|
|
|
|
|
|
[1,5,5,1,1,5,1,1], # R |
|
|
|
|
|
|
|
[1,6,6,1,1,1,6,1], # F |
|
|
|
|
|
|
|
[1,7,7,1,1,1,1,7], # N |
|
|
|
|
|
|
|
], dtype=np.uint8) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def interpret(value): |
|
|
|
def interpret(value): |
|
|
|
"""Converts characters, strings, and lists of them to lists of logic constants defined above. |
|
|
|
"""Converts characters, strings, and lists of them to lists of logic constants defined above. |
|
|
|
|
|
|
|
|
|
|
|
@ -191,19 +214,26 @@ def mv_and(x1, x2, out=None): |
|
|
|
return out |
|
|
|
return out |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _mv_xor(out, *ins): |
|
|
|
def mv_xor(x1, x2, out=None): |
|
|
|
any_unknown = (ins[0] == UNKNOWN) | (ins[0] == UNASSIGNED) |
|
|
|
"""A multi-valued XOR operator. |
|
|
|
for inp in ins[1:]: any_unknown |= (inp == UNKNOWN) | (inp == UNASSIGNED) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out[...] = ZERO |
|
|
|
:param x1: A multi-valued array. |
|
|
|
for inp in ins: |
|
|
|
:param x2: A multi-valued array. |
|
|
|
np.bitwise_xor(out, inp & 0b011, out=out) |
|
|
|
:param out: An optional storage destination. If None, a new multi-valued array is returned. |
|
|
|
np.bitwise_or(out, inp & 0b100, out=out) |
|
|
|
:return: A multi-valued array with the result. |
|
|
|
np.putmask(out, any_unknown, UNKNOWN) |
|
|
|
""" |
|
|
|
|
|
|
|
out = out or np.empty(np.broadcast(x1, x2).shape, dtype=np.uint8) |
|
|
|
|
|
|
|
out[...] = _mv_xor[x1, x2] |
|
|
|
|
|
|
|
return out |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def mv_xor(x1, x2, out=None): |
|
|
|
def mv_merge(x1, x2, out=None): |
|
|
|
"""A multi-valued XOR operator. |
|
|
|
"""A multi-valued merge operator. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Merging identical values ``a`` and ``a`` yields ``a``. |
|
|
|
|
|
|
|
Merging ``X`` and ``-`` yields ``X``. |
|
|
|
|
|
|
|
Merging any value ``a`` with ``X`` or ``-`` yields ``a``. |
|
|
|
|
|
|
|
Merging any other values ``a != b`` yields ``X``. |
|
|
|
|
|
|
|
|
|
|
|
:param x1: A multi-valued array. |
|
|
|
:param x1: A multi-valued array. |
|
|
|
:param x2: A multi-valued array. |
|
|
|
:param x2: A multi-valued array. |
|
|
|
@ -211,7 +241,7 @@ def mv_xor(x1, x2, out=None): |
|
|
|
:return: A multi-valued array with the result. |
|
|
|
:return: A multi-valued array with the result. |
|
|
|
""" |
|
|
|
""" |
|
|
|
out = out or np.empty(np.broadcast(x1, x2).shape, dtype=np.uint8) |
|
|
|
out = out or np.empty(np.broadcast(x1, x2).shape, dtype=np.uint8) |
|
|
|
_mv_xor(out, x1, x2) |
|
|
|
out[...] = _mv_merge[x1, x2] |
|
|
|
return out |
|
|
|
return out |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|