def __nn_filter_helper(R_data, R_indices, R_ptr, S, aggregate):
    'Nearest-neighbor filter helper function.\n\n    This is an internal function, not for use outside of the decompose module.\n\n    It applies the nearest-neighbor filter to S, assuming that the first index\n    corresponds to observations.\n\n    Parameters\n    ----------\n    R_data, R_indices, R_ptr : np.ndarrays\n        The `data`, `indices`, and `indptr` of a scipy.sparse matrix\n\n    S : np.ndarray\n        The observation data to filter\n\n    aggregate : callable\n        The aggregation operator\n\n\n    Returns\n    -------\n    S_out : np.ndarray like S\n        The filtered data array\n    '
    s_out = np.empty_like(S)
    for i in range((len(R_ptr) - 1)):
        targets = R_indices[R_ptr[i]:R_ptr[(i + 1)]]
        if (not len(targets)):
            s_out[i] = S[i]
            continue
        neighbors = np.take(S, targets, axis=0)
        if (aggregate is np.average):
            weights = R_data[R_ptr[i]:R_ptr[(i + 1)]]
            s_out[i] = aggregate(neighbors, axis=0, weights=weights)
        else:
            s_out[i] = aggregate(neighbors, axis=0)
    return s_out
Nearest-neighbor filter helper function.

This is an internal function, not for use outside of the decompose module.

It applies the nearest-neighbor filter to S, assuming that the first index
corresponds to observations.

Parameters
----------
R_data, R_indices, R_ptr : np.ndarrays
    The `data`, `indices`, and `indptr` of a scipy.sparse matrix

S : np.ndarray
    The observation data to filter

aggregate : callable
    The aggregation operator


Returns
-------
S_out : np.ndarray like S
    The filtered data array
def __nn_filter_helper(R_data, R_indices, R_ptr, S, aggregate):
    'Nearest-neighbor filter helper function.\n\n    This is an internal function, not for use outside of the decompose module.\n\n    It applies the nearest-neighbor filter to S, assuming that the first index\n    corresponds to observations.\n\n    Parameters\n    ----------\n    R_data, R_indices, R_ptr : np.ndarrays\n        The `data`, `indices`, and `indptr` of a scipy.sparse matrix\n\n    S : np.ndarray\n        The observation data to filter\n\n    aggregate : callable\n        The aggregation operator\n\n\n    Returns\n    -------\n    S_out : np.ndarray like S\n        The filtered data array\n    '
    s_out = np.empty_like(S)
    for i in range((len(R_ptr) - 1)):
        targets = R_indices[R_ptr[i]:R_ptr[(i + 1)]]
        if (not len(targets)):
            s_out[i] = S[i]
            continue
        neighbors = np.take(S, targets, axis=0)
        if (aggregate is np.average):
            weights = R_data[R_ptr[i]:R_ptr[(i + 1)]]
            s_out[i] = aggregate(neighbors, axis=0, weights=weights)
        else:
            s_out[i] = aggregate(neighbors, axis=0)
    return s_out