<commit_before>from __future__ import unicode_literals, division, absolute_import

from gatesym.gates import And, Or, Not, block


@block
def address_decode(address):
    control_lines = []
    for i in range(2**len(address)):
        addr_lines = []
        for j, line in enumerate(address):
            if i & 2**j:
                addr_lines.append(line)
            else:
                addr_lines.append(Not(line))
        control_lines.append(And(*addr_lines))
    return control_lines


@block
def bit_switch(control_lines, *data):
    assert len(control_lines) >= len(data)
    return Or(*[And(c, d) for c, d in zip(control_lines, data)])


@block
def bit_mux(address, *data):
    assert 2**len(address) >= len(data)
    control_lines = address_decode(address)
    return bit_switch(control_lines, *data)


@block
def word_switch(control_lines, *data):
    output = []
    for data_lines in zip(*data):
        output.append(bit_switch(control_lines, *data_lines))
    return output


@block
def word_mux(address, *data):
    control_lines = address_decode(address)<commit_msg>refactor address decode<commit_after>from __future__ import unicode_literals, division, absolute_import

from gatesym.gates import And, Or, Not, block


@block
def equals(value, lines):
    matches = []
    for j, line in enumerate(lines):
        if value & 2**j:
            matches.append(line)
        else:
            matches.append(Not(line))
    return And(*matches)


@block
def address_decode(address):
    return [equals(i, address) for i in range(2**len(address))]


@block
def bit_switch(control_lines, *data):
    assert len(control_lines) >= len(data)
    return Or(*[And(c, d) for c, d in zip(control_lines, data)])


@block
def bit_mux(address, *data):
    assert 2**len(address) >= len(data)
    control_lines = address_decode(address)
    return bit_switch(control_lines, *data)


@block
def word_switch(control_lines, *data):
    output = []
    for data_lines in zip(*data):
        output.append(bit_switch(control_lines, *data_lines))
    return output


@block
def word_mux(address, *data):
    control_lines = address_decode(address)
{'fraction_non_alphanumeric': 0.11608391608391608, 'fraction_numerical': 0.002797202797202797, 'mean_word_length': 3.6550976138828633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6097078', 'n_tokens_mistral': 698, 'n_tokens_neox': 675, 'n_words': 172}