<commit_before>#!/bin/env python

from collections import deque as Deque
import itertools
    
# https://github.com/tyarkoni/transitions

def pairwise(iterable):
    a, b = itertools.tee(iterable)
    next(b, None)
    return zip(a, b)

def weird_range(min, max):
    for index, element in enumerate(range(min, max +1)):
        yield (index, None if (min + 5) < element and element < (max - 5) else element)
    
class Ring(object):

    def __init__(self, size):
        self.__deque = Deque(maxlen=size)
    
    def add(self, element):
        self.__deque.append(element)
    
    def last_added(self):
        return self.__deque[len(self.__deque) - 1]
    
    def clear(self):
        self.__deque.clear()
    
    def __iter__(self):
        yield from self.__deque

    def __len__(self):
        return len(self.__deque)

    def __getitem__(self, index):
        return self.__deque[index]

    def __repr__(self):
        return repr(self.__deque)

    def add_all(self, elements):
        for element in elements:
            self.add(element)
    
class Interpolate(object):

    def __init__(self, before_size, interpolatable_size, after_size):
        ring_size = before_size + interpolatable_size + after_size
        
        self.__before_size = before_size
        self.__interpolatable_size = interpolatable_size
        self.__after_size = after_size
        
        self.__ring = Ring(size=ring_size)
    
    def __partition_ring(self):
        def is_boundary(one_element, other_element):
            return one_element is None and other_element is not None or one_element is not None and other_element is None
        
        if len(self.__ring) == 1:
            return [[self.__ring[0]]]

        partitions = []
        partition = []
        first_pair = True
        for left_pair, right_pair in pairwise(filter(lambda pair: pair is not None, self.__ring)):
            left_index, left_element = left_pair
            right_index, right_element = right_pair
            
            # Deal with first partition
            if first_pair:
                partition.append(left_pair)
                first_pair = False
            
            if is_boundary(left_element, right_element):
                partitions.append(partition)
                partition = []
            
            partition.append(right_pair)
        
        # Deal with last partition
        if partition:
            partitions.append(partition)
        
        return partitions
    
    def __interpolate(self, pairs):
        #def linear_interpolator(a, b):
        #    x_a, y_a = a
        #    x_b, y_b = b
        #    def f(x):
        #        return (x_b - x) / (x_b - x_a) * y_a + (x - x_a) / (x_b - x_a) * y_b
        #    return f
        before, between, after = self.__partition_ring()
        #print(before)
        #print(between)
        #print(after)
        #a = before[-1]
        #b = after[0]
        #f = linear_interpolator(a, b)
        from scipy.interpolate import InterpolatedUnivariateSpline<commit_msg>Let's give to Anaconda another chance...<commit_after>#!/bin/env python

from collections import deque as Deque
import itertools
from scipy.interpolate import InterpolatedUnivariateSpline
 
# https://github.com/tyarkoni/transitions

def pairwise(iterable):
    a, b = itertools.tee(iterable)
    next(b, None)
    return zip(a, b)

def weird_range(min, max):
    for index, element in enumerate(range(min, max +1)):
        yield (index, None if (min + 5) < element and element < (max - 5) else element)
    
class Ring(object):

    def __init__(self, size):
        self.__deque = Deque(maxlen=size)
    
    def add(self, element):
        self.__deque.append(element)
    
    def last_added(self):
        return self.__deque[len(self.__deque) - 1]
    
    def clear(self):
        self.__deque.clear()
    
    def __iter__(self):
        yield from self.__deque

    def __len__(self):
        return len(self.__deque)

    def __getitem__(self, index):
        return self.__deque[index]

    def __repr__(self):
        return repr(self.__deque)

    def add_all(self, elements):
        for element in elements:
            self.add(element)
    
class Interpolate(object):

    def __init__(self, before_size, interpolatable_size, after_size):
        ring_size = before_size + interpolatable_size + after_size
        
        self.__before_size = before_size
        self.__interpolatable_size = interpolatable_size
        self.__after_size = after_size
        
        self.__ring = Ring(size=ring_size)
    
    def __partition_ring(self):
        def is_boundary(one_element, other_element):
            return one_element is None and other_element is not None or one_element is not None and other_element is None
        
        if len(self.__ring) == 1:
            return [[self.__ring[0]]]

        partitions = []
        partition = []
        first_pair = True
        for left_pair, right_pair in pairwise(filter(lambda pair: pair is not None, self.__ring)):
            left_index, left_element = left_pair
            right_index, right_element = right_pair
            
            # Deal with first partition
            if first_pair:
                partition.append(left_pair)
                first_pair = False
            
            if is_boundary(left_element, right_element):
                partitions.append(partition)
                partition = []
            
            partition.append(right_pair)
        
        # Deal with last partition
        if partition:
            partitions.append(partition)
        
        return partitions
    
    def __interpolate(self, pairs):
        #def linear_interpolator(a, b):
        #    x_a, y_a = a
        #    x_b, y_b = b
        #    def f(x):
        #        return (x_b - x) / (x_b - x_a) * y_a + (x - x_a) / (x_b - x_a) * y_b
        #    return f
        before, between, after = self.__partition_ring()
        #print(before)
        #print(between)
        #print(after)
        #a = before[-1]
        #b = after[0]
        #f = linear_interpolator(a, b)
{'fraction_non_alphanumeric': 0.09034369885433716, 'fraction_numerical': 0.002618657937806874, 'mean_word_length': 1.98388671875, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2190833', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1817, 'n_words': 456}