<commit_before>import math
import torch


def find_event(interp_fn, sign0, t0, t1, event_fn, tol):
    with torch.no_grad():

        # Num iterations for the secant method until tolerance is within target.
        nitrs = torch.ceil(torch.log((t1 - t0) / tol) / math.log(2.0))

        for _ in range(nitrs.long()):
            t_mid = (t1 + t0) / 2.0
            y_mid = interp_fn(t_mid)
            sign_mid = torch.sign(event_fn(t_mid, y_mid))
            same_as_sign0 = (sign0 * sign_mid) / 2.0 + 0.5
            t0 = t_mid * same_as_sign0 + t0 * (1.0 - same_as_sign0)
            t1 = t_mid * (1.0 - same_as_sign0) + t1 * same_as_sign0
        event_t = (t0 + t1) / 2.0

    return event_t, interp_fn(event_t)<commit_msg>account for 0 sign<commit_after>import math
import torch


def find_event(interp_fn, sign0, t0, t1, event_fn, tol):
    with torch.no_grad():

        # Num iterations for the secant method until tolerance is within target.
        nitrs = torch.ceil(torch.log((t1 - t0) / tol) / math.log(2.0))

        for _ in range(nitrs.long()):
            t_mid = (t1 + t0) / 2.0
            y_mid = interp_fn(t_mid)
            sign_mid = torch.sign(event_fn(t_mid, y_mid))
            same_as_sign0 = (sign0 == sign_mid)
            t0 = torch.where(same_as_sign0, t_mid, t0)
            t1 = torch.where(same_as_sign0, t1, t_mid)
        event_t = (t0 + t1) / 2.0

    return event_t, interp_fn(event_t)
{'fraction_non_alphanumeric': 0.11867977528089887, 'fraction_numerical': 0.04002808988764045, 'mean_word_length': 2.202247191011236, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5268756', 'n_tokens_mistral': 567, 'n_tokens_neox': 550, 'n_words': 126}