def cosine_score_greedy(spec1, spec2, mass_shift, tol, min_intens=0, use_numba=True):
    'Calculate cosine score between spectrum1 and spectrum2.\n\n    If mass_shifted = True it will shift the spectra with respect to each other\n    by difference in their parentmasses.\n\n    Args:\n    ----\n    spec1: Spectrum peaks and intensities as numpy array.\n    spec2: Spectrum peaks and intensities as numpy array.\n    tol: float\n        Tolerance value to define how far two peaks can be apart to still count as match.\n    min_intens: float\n        Minimum intensity (relative to max.intensity peak in spectrum). Peaks with lower\n        intensity will be ignored --> higher min_intens is faster, but less precise.\n    '
    if ((spec1.shape[0] == 0) or (spec2.shape[0] == 0)):
        return (0.0, [])
    spec1[:, 1] = (spec1[:, 1] / max(spec1[:, 1]))
    spec2[:, 1] = (spec2[:, 1] / max(spec2[:, 1]))
    spec1 = spec1[(spec1[:, 1] > min_intens), :]
    spec2 = spec2[(spec2[:, 1] > min_intens), :]
    if use_numba:
        zero_pairs = find_pairs_numba(spec1, spec2, tol, shift=0.0)
    else:
        zero_pairs = find_pairs(spec1, spec2, tol, shift=0.0)
    if ((mass_shift is not None) and (mass_shift != 0.0)):
        if use_numba:
            nonzero_pairs = find_pairs_numba(spec1, spec2, tol, shift=mass_shift)
        else:
            nonzero_pairs = find_pairs(spec1, spec2, tol, shift=mass_shift)
        matching_pairs = (zero_pairs + nonzero_pairs)
    else:
        matching_pairs = zero_pairs
    matching_pairs = sorted(matching_pairs, key=(lambda x: x[2]), reverse=True)
    used1 = set()
    used2 = set()
    score = 0.0
    used_matches = []
    for m in matching_pairs:
        if ((not (m[0] in used1)) and (not (m[1] in used2))):
            score += m[2]
            used1.add(m[0])
            used2.add(m[1])
            used_matches.append(m)
    score = (score / max(np.sum((spec1[:, 1] ** 2)), np.sum((spec2[:, 1] ** 2))))
    return (score, used_matches)
Calculate cosine score between spectrum1 and spectrum2.

If mass_shifted = True it will shift the spectra with respect to each other
by difference in their parentmasses.

Args:
----
spec1: Spectrum peaks and intensities as numpy array.
spec2: Spectrum peaks and intensities as numpy array.
tol: float
    Tolerance value to define how far two peaks can be apart to still count as match.
min_intens: float
    Minimum intensity (relative to max.intensity peak in spectrum). Peaks with lower
    intensity will be ignored --> higher min_intens is faster, but less precise.
def cosine_score_greedy(spec1, spec2, mass_shift, tol, min_intens=0, use_numba=True):
    'Calculate cosine score between spectrum1 and spectrum2.\n\n    If mass_shifted = True it will shift the spectra with respect to each other\n    by difference in their parentmasses.\n\n    Args:\n    ----\n    spec1: Spectrum peaks and intensities as numpy array.\n    spec2: Spectrum peaks and intensities as numpy array.\n    tol: float\n        Tolerance value to define how far two peaks can be apart to still count as match.\n    min_intens: float\n        Minimum intensity (relative to max.intensity peak in spectrum). Peaks with lower\n        intensity will be ignored --> higher min_intens is faster, but less precise.\n    '
    if ((spec1.shape[0] == 0) or (spec2.shape[0] == 0)):
        return (0.0, [])
    spec1[:, 1] = (spec1[:, 1] / max(spec1[:, 1]))
    spec2[:, 1] = (spec2[:, 1] / max(spec2[:, 1]))
    spec1 = spec1[(spec1[:, 1] > min_intens), :]
    spec2 = spec2[(spec2[:, 1] > min_intens), :]
    if use_numba:
        zero_pairs = find_pairs_numba(spec1, spec2, tol, shift=0.0)
    else:
        zero_pairs = find_pairs(spec1, spec2, tol, shift=0.0)
    if ((mass_shift is not None) and (mass_shift != 0.0)):
        if use_numba:
            nonzero_pairs = find_pairs_numba(spec1, spec2, tol, shift=mass_shift)
        else:
            nonzero_pairs = find_pairs(spec1, spec2, tol, shift=mass_shift)
        matching_pairs = (zero_pairs + nonzero_pairs)
    else:
        matching_pairs = zero_pairs
    matching_pairs = sorted(matching_pairs, key=(lambda x: x[2]), reverse=True)
    used1 = set()
    used2 = set()
    score = 0.0
    used_matches = []
    for m in matching_pairs:
        if ((not (m[0] in used1)) and (not (m[1] in used2))):
            score += m[2]
            used1.add(m[0])
            used2.add(m[1])
            used_matches.append(m)
    score = (score / max(np.sum((spec1[:, 1] ** 2)), np.sum((spec2[:, 1] ** 2))))
    return (score, used_matches)