# Path: commpy/utilities.py
# def dec2bitarray(in_number, bit_width):
#     """
#     Converts a positive integer or an array-like of positive integers to NumPy array of the specified size containing
#     bits (0 and 1).
# 
#     Parameters
#     ----------
#     in_number : int or array-like of int
#         Positive integer to be converted to a bit array.
# 
#     bit_width : int
#         Size of the output bit array.
# 
#     Returns
#     -------
#     bitarray : 1D ndarray of numpy.int8
#         Array containing the binary representation of all the input decimal(s).
# 
#     """
# 
#     if isinstance(in_number, (np.integer, int)):
#         return decimal2bitarray(in_number, bit_width).copy()
#     result = np.zeros(bit_width * len(in_number), np.int8)
#     for pox, number in enumerate(in_number):
#         result[pox * bit_width:(pox + 1) * bit_width] = decimal2bitarray(number, bit_width).copy()
#     return result
# 
# def bitarray2dec(in_bitarray):
#     """
#     Converts an input NumPy array of bits (0 and 1) to a decimal integer.
# 
#     Parameters
#     ----------
#     in_bitarray : 1D ndarray of ints
#         Input NumPy array of bits.
# 
#     Returns
#     -------
#     number : int
#         Integer representation of input bit array.
#     """
# 
#     number = 0
# 
#     for i in range(len(in_bitarray)):
#         number = number + in_bitarray[i] * pow(2, len(in_bitarray) - 1 - i)
# 
#     return number
# 
# def hamming_dist(in_bitarray_1, in_bitarray_2):
#     """
#     Computes the Hamming distance between two NumPy arrays of bits (0 and 1).
# 
#     Parameters
#     ----------
#     in_bit_array_1 : 1D ndarray of ints
#         NumPy array of bits.
# 
#     in_bit_array_2 : 1D ndarray of ints
#         NumPy array of bits.
# 
#     Returns
#     -------
#     distance : int
#         Hamming distance between input bit arrays.
#     """
# 
#     distance = np.bitwise_xor(in_bitarray_1, in_bitarray_2).sum()
# 
#     return distance
# 
# def euclid_dist(in_array1, in_array2):
#     """
#     Computes the squared euclidean distance between two NumPy arrays
# 
#     Parameters
#     ----------
#     in_array1 : 1D ndarray of floats
#         NumPy array of real values.
# 
#     in_array2 : 1D ndarray of floats
#         NumPy array of real values.
# 
#     Returns
#     -------
#     distance : float
#         Squared Euclidean distance between two input arrays.
#     """
#     distance = ((in_array1 - in_array2) * (in_array1 - in_array2)).sum()
# 
#     return distance


import functools
import math
import matplotlib.colors as mcolors
import matplotlib.patches as mpatches
import matplotlib.path as mpath
import matplotlib.pyplot as plt
import numpy as np
from warnings import warn
from matplotlib.collections import PatchCollection
from commpy.utilities import dec2bitarray, bitarray2dec, hamming_dist, euclid_dist
            number_inbits = number_message_bits
            number_outbits = int((number_inbits + k * total_memory)/rate)
        else:
            number_inbits = number_message_bits + total_memory + total_memory % k
            inbits = np.zeros(number_inbits, 'int')
            # Pad the input bits with M zeros (L-th terminated truncation)
            inbits[0:number_message_bits] = message_bits
            number_outbits = int(number_inbits/rate)

    outbits = np.zeros(number_outbits, 'int')
    if puncture_matrix is not None:
        p_outbits = np.zeros(number_outbits, 'int')
    else:
        p_outbits = np.zeros(int(number_outbits*
            puncture_matrix[0:].sum()/np.size(puncture_matrix, 1)), 'int')
    next_state_table = trellis.next_state_table
    output_table = trellis.output_table

    # Encoding process - Each iteration of the loop represents one clock cycle
    current_state = 0
    j = 0

    for i in range(int(number_inbits/k)): # Loop through all input bits
        current_input = bitarray2dec(inbits[i*k:(i+1)*k])
        current_output = output_table[current_state][current_input]
        outbits[j*n:(j+1)*n] = dec2bitarray(current_output, n)
        current_state = next_state_table[current_state][current_input]
        j += 1

    if code_type == 'rsc' and termination == 'term':

# Path: commpy/utilities.py
# def dec2bitarray(in_number, bit_width):
#     """
#     Converts a positive integer or an array-like of positive integers to NumPy array of the specified size containing
#     bits (0 and 1).
# 
#     Parameters
#     ----------
#     in_number : int or array-like of int
#         Positive integer to be converted to a bit array.
# 
#     bit_width : int
#         Size of the output bit array.
# 
#     Returns
#     -------
#     bitarray : 1D ndarray of numpy.int8
#         Array containing the binary representation of all the input decimal(s).
# 
#     """
# 
#     if isinstance(in_number, (np.integer, int)):
#         return decimal2bitarray(in_number, bit_width).copy()
#     result = np.zeros(bit_width * len(in_number), np.int8)
#     for pox, number in enumerate(in_number):
#         result[pox * bit_width:(pox + 1) * bit_width] = decimal2bitarray(number, bit_width).copy()
#     return result
# 
# def bitarray2dec(in_bitarray):
#     """
#     Converts an input NumPy array of bits (0 and 1) to a decimal integer.
# 
#     Parameters
#     ----------
#     in_bitarray : 1D ndarray of ints
#         Input NumPy array of bits.
# 
#     Returns
#     -------
#     number : int
#         Integer representation of input bit array.
#     """
# 
#     number = 0
# 
#     for i in range(len(in_bitarray)):
#         number = number + in_bitarray[i] * pow(2, len(in_bitarray) - 1 - i)
# 
#     return number
# 
# def hamming_dist(in_bitarray_1, in_bitarray_2):
#     """
#     Computes the Hamming distance between two NumPy arrays of bits (0 and 1).
# 
#     Parameters
#     ----------
#     in_bit_array_1 : 1D ndarray of ints
#         NumPy array of bits.
# 
#     in_bit_array_2 : 1D ndarray of ints
#         NumPy array of bits.
# 
#     Returns
#     -------
#     distance : int
#         Hamming distance between input bit arrays.
#     """
# 
#     distance = np.bitwise_xor(in_bitarray_1, in_bitarray_2).sum()
# 
#     return distance
# 
# def euclid_dist(in_array1, in_array2):
#     """
#     Computes the squared euclidean distance between two NumPy arrays
# 
#     Parameters
#     ----------
#     in_array1 : 1D ndarray of floats
#         NumPy array of real values.
# 
#     in_array2 : 1D ndarray of floats
#         NumPy array of real values.
# 
#     Returns
#     -------
#     distance : float
#         Squared Euclidean distance between two input arrays.
#     """
#     distance = ((in_array1 - in_array2) * (in_array1 - in_array2)).sum()
# 
#     return distance


# Path: commpy/channelcoding/convcode.py
import functools
import math
import matplotlib.colors as mcolors
import matplotlib.patches as mpatches
import matplotlib.path as mpath
import matplotlib.pyplot as plt
import numpy as np
from warnings import warn
from matplotlib.collections import PatchCollection
from commpy.utilities import dec2bitarray, bitarray2dec, hamming_dist, euclid_dist

            number_inbits = number_message_bits
            number_outbits = int((number_inbits + k * total_memory)/rate)
        else:
            number_inbits = number_message_bits + total_memory + total_memory % k
            inbits = np.zeros(number_inbits, 'int')
            # Pad the input bits with M zeros (L-th terminated truncation)
            inbits[0:number_message_bits] = message_bits
            number_outbits = int(number_inbits/rate)

    outbits = np.zeros(number_outbits, 'int')
    if puncture_matrix is not None:
        p_outbits = np.zeros(number_outbits, 'int')
    else:
        p_outbits = np.zeros(int(number_outbits*
            puncture_matrix[0:].sum()/np.size(puncture_matrix, 1)), 'int')
    next_state_table = trellis.next_state_table
    output_table = trellis.output_table

    # Encoding process - Each iteration of the loop represents one clock cycle
    current_state = 0
    j = 0

    for i in range(int(number_inbits/k)): # Loop through all input bits
        current_input = bitarray2dec(inbits[i*k:(i+1)*k])
        current_output = output_table[current_state][current_input]
        outbits[j*n:(j+1)*n] = dec2bitarray(current_output, n)
        current_state = next_state_table[current_state][current_input]
        j += 1

    if code_type == 'rsc' and termination == 'term':

        term_bits = dec2bitarray(current_state, trellis.total_memory)