<commit_before>#!python
#cython: embedsignature=True
import cython
import numpy as np
cimport numpy as np
from scipy.linalg import toeplitz


#<EMAIL>(False)
@cython.cdivision(True)
@cython.wraparound(False)
@cython.nonecheck(False)
cpdef armatus(np.ndarray[np.double_t, ndim=2] Sseg, double gamma):
    """
    Input
    -----
    Sseg : 2d-array
        a segment-aggregated matrix
    gamma: float
        scaling factor

    Returns
    -------
    Sa : 2d-array
        S[i,j] is the rescaled score for segment [i,j) 
    Mu: 2d-array 
        Mu[i, j] is the average rescaled score for a segment of length j-i.

    """
    cdef int N = Sseg.shape[0] - 1
    cdef np.ndarray[np.double_t, ndim=2] denom = toeplitz(
        np.r_[1, np.arange(1, N+1)]**gamma)
    cdef np.ndarray[np.double_t, ndim=2] Sa = Sseg / denom

    cdef np.ndarray[np.double_t, ndim=1] mu = np.zeros(N+1, dtype=float)
    cdef np.ndarray[np.int_t, ndim=1] count = np.zeros(N+1, dtype=int)
    cdef int start, end, size
    for end in range(1, N+1):
        for start in range(end-1, -1, -1):
            size = end - start
            mu[size] = (count[size]*mu[size] + Sa[start, end]) / (count[size] + 1)
            count[size] += 1

    cdef np.ndarray[np.double_t, ndim=2] Mu = np.zeros((N+1, N+1), dtype=float)
    cdef int d, i
    for d in range(N+1):
        for i in range(0, N-d):
            Mu[i, d+i] = Mu[d+i, i] = mu[d]

    return Sa,  Mu


<EMAIL>(False)
@cython.cdivision(True)
@cython.wraparound(False)
@cython.nonecheck(False)
cpdef np.ndarray[np.double_t, ndim=2] arrowhead_up(
        np.ndarray[np.double_t, ndim=2] A):
    """
    Upstream Arrowhead matrix.

    ``A[i, i+d]`` gives the relative affinity that the **upstream** member <commit_msg>Fix off-by-one bug affecting edge of armatus score matrix<commit_after>#!python
#cython: embedsignature=True
import cython
import numpy as np
cimport numpy as np
from scipy.linalg import toeplitz


<EMAIL>(False)
@cython.cdivision(True)
@cython.wraparound(False)
@cython.nonecheck(False)
cpdef armatus(np.ndarray[np.double_t, ndim=2] Sseg, double gamma):
    """
    Input
    -----
    Sseg : 2d-array
        a segment-aggregated matrix
    gamma: float
        scaling factor

    Returns
    -------
    Sa : 2d-array
        S[i,j] is the rescaled score for segment [i,j) 
    Mu: 2d-array 
        Mu[i, j] is the average rescaled score for a segment of length j-i.

    """
    cdef int N = Sseg.shape[0] - 1
    cdef np.ndarray[np.double_t, ndim=2] denom = toeplitz(
        np.r_[1, np.arange(1, N+1)]**gamma)
    cdef np.ndarray[np.double_t, ndim=2] Sa = Sseg / denom

    cdef np.ndarray[np.double_t, ndim=1] mu = np.zeros(N+1, dtype=float)
    cdef np.ndarray[np.int_t, ndim=1] count = np.zeros(N+1, dtype=int)
    cdef int start, end, size
    for end in range(1, N+1):
        for start in range(end-1, -1, -1):
            size = end - start
            mu[size] = (count[size]*mu[size] + Sa[start, end]) / (count[size] + 1)
            count[size] += 1

    cdef np.ndarray[np.double_t, ndim=2] Mu = np.zeros((N+1, N+1), dtype=float)
    cdef int d, i
    for d in range(N+1):
        for i in range(0, N-d+1):
            Mu[i, d+i] = Mu[d+i, i] = mu[d]

    return Sa,  Mu


<EMAIL>(False)
@cython.cdivision(True)
@cython.wraparound(False)
@cython.nonecheck(False)
cpdef np.ndarray[np.double_t, ndim=2] arrowhead_up(
        np.ndarray[np.double_t, ndim=2] A):
    """
    Upstream Arrowhead matrix.

    ``A[i, i+d]`` gives the relative affinity that the **upstream** member 
{'fraction_non_alphanumeric': 0.14733276883996613, 'fraction_numerical': 0.016652554332486594, 'mean_word_length': 2.6955161626694473, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1973993', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1396, 'n_words': 354}