<jupyter_start><jupyter_text>Experiment 1 - Memory effeciency of commSignal Refs: [1] https://ipython-books.github.io/45-understanding-the-internals-of-numpy-to-avoid-unnecessary-array-copying/ The goal of this experiment is to verify that the commSignal object is memory effecient. Ineffencies may occur when the internal signal storage is copied everytime it is being used. To verify that the same array is being used the following functions are defined, courtesy of [1]<jupyter_code>import numpy as np

def get_data_base(arr):
    """For a given NumPy array, find the base array
    that owns the actual data."""
    base = arr
    while isinstance(base.base, np.ndarray):
        base = base.base
    return base


def arrays_share_data(x, y):
    return get_data_base(x) is get_data_base(y)

a = np.array(range(100))
print(arrays_share_data(a, a.copy()))
print(arrays_share_data(a, a[:1]))<jupyter_output>False
True<jupyter_text>In the constructor we expect the signal to be copied so as to preserve a copy within the object, the following result shows this is true.<jupyter_code>class test:
    def __init__(self, sig):
        self.__sig = np.array(sig)
        print(arrays_share_data(self.__sig, sig))
        
test(a)<jupyter_output>False<jupyter_text>Next we test what happens when we return the signal, is it copied then aswell? We see that it isn't being copied again. This is what we want, everytime we return the signal we dont want it to be copied again and again, which will lead to unnecessary delays<jupyter_code>class test:
    def __init__(self, sig):
        self.__sig = np.array(sig)
        print(arrays_share_data(self.__sig, self.getsig))
        print(arrays_share_data(self.getgetsig, self.getsig))
    @property
    def getsig(self):
        return self.__sig
    @property
    def getgetsig(self):
        return self.getsig
    
test(a)<jupyter_output>True
True
{'fraction_non_alphanumeric': 0.08399366085578447, 'fraction_numerical': 0.004754358161648178, 'mean_word_length': 4.023872679045093, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 1, '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}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '179315', 'license': 'MIT', 'n_tokens_mistral': 599, 'n_tokens_neox': 581, 'n_words': 202, 'path': 'experiments/.ipynb_checkpoints/Experiment 1 - Memory effeciency of commSignal-checkpoint.ipynb', 'repo_name': 'ramantehlan/DirectDemod', 'size': '1893'}