<commit_before>from bitarray import bitarray
from bitarray import bitdiff
import random

"""
An Instruction. A binary string that can be mutated to change the outcome of the
instruction used in a program.
"""
class Instruction:

    # bits correspond to: mode + op + dest + src
    instructionSize = 1 + 3 + 3 + 24

    # offsets and sizes of segments
    slcMode = slice(0,1)
    slcOp = slice(1,4)
    slcDest = slice(4,7)
    slcSrc = slice(7,31)

    # modes
    mode0 = bitarray([0])
    mode1 = bitarray([1])

    # operations
    opSum  = bitarray([0,0,0])
    opDiff = bitarray([0,0,1])
    opProd = bitarray([0,1,0])
    opDiv  = bitarray([0,1,1])
    opCos  = bitarray([1,0,0])
    opLog  = bitarray([1,0,1])
    opExp  = bitarray([1,1,0])
    opCond = bitarray([1,1,1])

    def __init__(self, randInit=True, randSeed=0, inst=None):
        self.rand = random.Random()
        if randSeed == 0:
            self.rand.seed()
        else:
            self.rand.seed(randSeed)

        # recreate existing instruction
        if inst is not None:
            self.inst = bitarray([False]*Instruction.instructionSize)
            for i in inst.inst:
                self.inst[i] = i
            return

        if randInit: # random bits
            self.inst = bitarray([self.rand.choice([True,False])
                    for i in range(Instruction.instructionSize)])
        else: # all 0's
            self.inst = bitarray([False]*Instruction.instructionSize)

    """
    Gets a segment of the bitarray that makes up this instruction.
    Args:
        slc:
            (slice) From the static attributes of this class. Ex: slcMode.
    Returns:<commit_msg>mild speed up to instruction copying<commit_after>from bitarray import bitarray
from bitarray import bitdiff
import random

"""
An Instruction. A binary string that can be mutated to change the outcome of the
instruction used in a program.
"""
class Instruction:

    # bits correspond to: mode + op + dest + src
    instructionSize = 1 + 3 + 3 + 24

    # offsets and sizes of segments
    slcMode = slice(0,1)
    slcOp = slice(1,4)
    slcDest = slice(4,7)
    slcSrc = slice(7,31)

    # modes
    mode0 = bitarray([0])
    mode1 = bitarray([1])

    # operations
    opSum  = bitarray([0,0,0])
    opDiff = bitarray([0,0,1])
    opProd = bitarray([0,1,0])
    opDiv  = bitarray([0,1,1])
    opCos  = bitarray([1,0,0])
    opLog  = bitarray([1,0,1])
    opExp  = bitarray([1,1,0])
    opCond = bitarray([1,1,1])

    def __init__(self, randInit=True, randSeed=0, inst=None):
        self.rand = random.Random()
        if randSeed == 0:
            self.rand.seed()
        else:
            self.rand.seed(randSeed)

        # recreate existing instruction
        if inst is not None:
            self.inst = bitarray(inst.inst)
            return

        if randInit: # random bits
            self.inst = bitarray([self.rand.choice([True,False])
                    for i in range(Instruction.instructionSize)])
        else: # all 0's
            self.inst = bitarray([False]*Instruction.instructionSize)

    """
    Gets a segment of the bitarray that makes up this instruction.
    Args:
        slc:
            (slice) From the static attributes of this class. Ex: slcMode.
    Returns:
{'fraction_non_alphanumeric': 0.11284403669724771, 'fraction_numerical': 0.027522935779816515, 'mean_word_length': 2.3007063572149344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3054677', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1027, 'n_words': 294}