def knn_search(K, x, y=None, min_dist=None, index=None, algorithm=None,
               return_indices=False, dist_double=False, **kwargs):
    N, dim = x.shape
    if y is not None:
        M, dim2 = y.shape
        if dim != dim2:
            raise TypeError("x and y must have same second dimension")

    if not is_integer(K) or K < 1:
        raise TypeError("K must be a positive integer")

    if index is None:
        if algorithm is None:
            algorithm = pick_flann_algorithm(dim)
        index = FLANNIndex(algorithm=algorithm, **kwargs)
        index.build_index(x if y is None else x)

    idx, dist = index.nn_index(x, K)

    if return_indices:
        idx = idx.astype(np.uint16)
    if dist_double:
        dist = np.asarray(dist, dtype=np.float64)
    np.sqrt(dist, out=dist)

    # protect against identical points
    if min_dist is None:
        min_dist = default_min_dist(dim)
    if min_dist > 0:
        np.maximum(min_dist, dist, out=dist)

    return (dist, idx) if return_indices else dist
Trait initializer.
dataset/ETHPy150Open dougalsutherland/py-sdm/sdm/knn_search.py/knn_search--crossover with--dataset/ETHPy150Open enthought/envisage/examples/MOTD/acme/motd/software_quotes/software_quotes_plugin.py/SoftwareQuotesPlugin._messages_default