<commit_before>from stingray.utils import njit, prange
import numpy as np
import matplotlib.pyplot as plt
from astropy import log


try:
    from scipy.special import factorial
except ImportError:
    from scipy.misc import factorial


def r_in(td, r_0):
    """Calculate incident countrate given dead time and detected countrate."""
    tau = 1 / r_0
    return 1. / (tau - td)


def r_det(td, r_i):
    """Calculate detected countrate given dead time and incident countrate."""
    tau = 1 / r_i
    return 1. / (tau + td)


@njit()
def Gn(x, n):
    """Term in Eq. 34 in Zhang+95."""
    s = 0
    for l in range(0, n):
        s += (n - l) / factorial(l) * x**l
    return np.exp(-x) * s


@njit()
def heaviside(x):
    """Heaviside function. Returns 1 if x>0, and 0 otherwise.

    Examples
    --------
    >>> heaviside(2)
    1<commit_msg>Use a factorial function compatible with Numba<commit_after>from stingray.utils import njit, prange
import numpy as np
import matplotlib.pyplot as plt
from astropy import log


try:
    from scipy.special import factorial
except ImportError:
    from scipy.misc import factorial


__FACTORIALS = factorial(np.arange(160))


def r_in(td, r_0):
    """Calculate incident countrate given dead time and detected countrate."""
    tau = 1 / r_0
    return 1. / (tau - td)


def r_det(td, r_i):
    """Calculate detected countrate given dead time and incident countrate."""
    tau = 1 / r_i
    return 1. / (tau + td)


@njit()
def Gn(x, n):
    """Term in Eq. 34 in Zhang+95."""
    s = 0
    for l in range(0, n):
        s += (n - l) / __FACTORIALS[l] * x**l
    return np.exp(-x) * s


@njit()
def heaviside(x):
    """Heaviside function. Returns 1 if x>0, and 0 otherwise.

    Examples
    --------
    >>> heaviside(2)
    1
{'fraction_non_alphanumeric': 0.1263395375070502, 'fraction_numerical': 0.02086858432036097, 'mean_word_length': 2.6427104722792607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1432406', 'n_tokens_mistral': 668, 'n_tokens_neox': 616, 'n_words': 219}