<commit_before># <NAME> <<EMAIL>>

##__________________________________________________________________||
import numpy as np

##__________________________________________________________________||
class Sum(object):
    def __init__(self, initial_val = (0, )):
        self._results = { }
        self.initial_val = initial_val

    def add(self, key, val, weight = 1):
        self.add_key(key)
        self._results[key] = self._results[key] + np.array(val*weight)

    def add_key(self, key):
        if key not in self._results:
            self._results[key] = np.array(self.initial_val)

    def keys(self):
        return self._results.keys()

    def copy_from(self, src):
        self._results.clear()
        self._results.update(src._counts)

    def results(self):
        return self._results

    def __add__(self, other):
        ret = Count()
        results = {k: v.copy() for k, v in self._results.iteritems()}
        if not other == 0: # other is 0 when e.g. sum([obj1, obj2])
            self._add_results_inplace(results, other._results)
        ret._results.clear()
        ret._results.update(results)
        return ret

    def __iadd__(self, other):
        self._add_results_inplace(self._results, other._results)
        return self

    def __radd__(self, other):
        return self.__add__(other)

    def _add_results_inplace(self, res1, res2):
        # res1 += res2, modify res1<commit_msg>fix a bug in Sum.copy_from()<commit_after># <NAME> <<EMAIL>>

##__________________________________________________________________||
import numpy as np

##__________________________________________________________________||
class Sum(object):
    def __init__(self, initial_val = (0, )):
        self._results = { }
        self.initial_val = initial_val

    def add(self, key, val, weight = 1):
        self.add_key(key)
        self._results[key] = self._results[key] + np.array(val*weight)

    def add_key(self, key):
        if key not in self._results:
            self._results[key] = np.array(self.initial_val)

    def keys(self):
        return self._results.keys()

    def copy_from(self, src):
        self._results.clear()
        self._results.update(src._results)

    def results(self):
        return self._results

    def __add__(self, other):
        ret = Count()
        results = {k: v.copy() for k, v in self._results.iteritems()}
        if not other == 0: # other is 0 when e.g. sum([obj1, obj2])
            self._add_results_inplace(results, other._results)
        ret._results.clear()
        ret._results.update(results)
        return ret

    def __iadd__(self, other):
        self._add_results_inplace(self._results, other._results)
        return self

    def __radd__(self, other):
        return self.__add__(other)

    def _add_results_inplace(self, res1, res2):
        # res1 += res2, modify res1
{'fraction_non_alphanumeric': 0.11549197487787857, 'fraction_numerical': 0.007676203768318213, 'mean_word_length': 2.782321899736148, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5770846', 'n_tokens_mistral': 855, 'n_tokens_neox': 832, 'n_words': 201}