<commit_before>import numpy as np


def stack_1d_on_left(x, y):
    return np.hstack((np.asarray(x).reshape(len(x), 1),
                      np.asarray(y)))


def banded_jacobian(y, x, ml, mu):
    """
    Calculates a banded version of the jacobian

    Compatible with the format requested by
    scipy.integrate.ode
    """
    ny = len(y)
    nx = len(x)
    packed = np.zeros((mu+ml+1, nx), dtype=object)

    def set(ri, ci, val):
        packed[ri-ci+mu, ci] = val

    for ri in range(ny):
        for ci in range(max(0, ri-ml), min(nx, ri+mu+1)):
            set(ri, ci, y[ri].diff(x[ci]))
    return packed


def transform_exprs_dep(fw, bw, dep_exprs, check=True):
    if len(fw) != len(dep_exprs) or \
       len(fw) != len(bw):
        raise ValueError("Incompatible lengths")
    dep, exprs = zip(*dep_exprs)
    if check:
        for f, b, y in zip(fw, bw, dep):
            if f.subs(y, b) - y != 0:
                raise ValueError('Incorrect (did you set real=True?) fw: %s'
                                 % str(f))
            if b.subs(y, f) - y != 0:
                raise ValueError('Incorrect (did you set real=True?) bw: %s'
                                 % str(b))
    bw_subs = zip(dep, bw)
    return [(e*f.diff(y)).subs(bw_subs) for f, y, e in zip(fw, dep, exprs)]


def transform_exprs_indep(fw, bw, dep_exprs, indep, check=True):
    if check:
        if fw.subs(indep, bw) - indep != 0:
                raise ValueError('Incorrect (did you set real=True?) fw: %s'
                                 % str(fw))
        if bw.subs(indep, fw) - indep != 0:
            raise ValueError('Incorrect (did you set real=True?) bw: %s'
                             % str(bw))
    dep, exprs = zip(*dep_exprs)<commit_msg>Refactored check_transforms (useful outside pyodesys)<commit_after>import numpy as np


def stack_1d_on_left(x, y):
    return np.hstack((np.asarray(x).reshape(len(x), 1),
                      np.asarray(y)))


def banded_jacobian(y, x, ml, mu):
    """
    Calculates a banded version of the jacobian

    Compatible with the format requested by
    scipy.integrate.ode
    """
    ny = len(y)
    nx = len(x)
    packed = np.zeros((mu+ml+1, nx), dtype=object)

    def set(ri, ci, val):
        packed[ri-ci+mu, ci] = val

    for ri in range(ny):
        for ci in range(max(0, ri-ml), min(nx, ri+mu+1)):
            set(ri, ci, y[ri].diff(x[ci]))
    return packed


def check_transforms(fw, bw, symbs):
    for f, b, y in zip(fw, bw, symbs):
        if f.subs(y, b) - y != 0:
            raise ValueError('Incorrect (did you set real=True?) fw: %s'
                             % str(f))
        if b.subs(y, f) - y != 0:
            raise ValueError('Incorrect (did you set real=True?) bw: %s'
                             % str(b))


def transform_exprs_dep(fw, bw, dep_exprs, check=True):
    if len(fw) != len(dep_exprs) or \
       len(fw) != len(bw):
        raise ValueError("Incompatible lengths")
    dep, exprs = zip(*dep_exprs)
    if check:
        check_transforms(fw, bw, dep)
    bw_subs = zip(dep, bw)
    return [(e*f.diff(y)).subs(bw_subs) for f, y, e in zip(fw, dep, exprs)]


def transform_exprs_indep(fw, bw, dep_exprs, indep, check=True):
    if check:
        if fw.subs(indep, bw) - indep != 0:
                raise ValueError('Incorrect (did you set real=True?) fw: %s'
                                 % str(fw))
        if bw.subs(indep, fw) - indep != 0:
            raise ValueError('Incorrect (did you set real=True?) bw: %s'
                             % str(bw))
    dep, exprs = zip(*dep_exprs)
{'fraction_non_alphanumeric': 0.14333612740989102, 'fraction_numerical': 0.005029337803855826, 'mean_word_length': 1.998324958123953, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5169309', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1303, 'n_words': 346}