Import cupy
and cuML's NearestNeighbors
estimator
import cupy
from cuml.neighbors import NearestNeighbors
Set up some variables and create some random data on GPU
k = 5
n_samples = 100
n_features = 100
X = cupy.random.random((n_samples, n_features))
Execute k-Nearest Neighbors to find neighborhoods
knn = NearestNeighbors(n_neighbors=k)
knn.fit(X)
distances, indices = knn.kneighbors(X)
Create symmetrized KNN graph from our output arrays
distances = distances.reshape(n_samples * k)
indices = indices.reshape(n_samples * k)
indptr = cupy.arange(0, (k*n_samples)+1, k)
knn_graph = cupy.sparse.csr_matrix((distances, indices, indptr), shape=(n_samples, n_samples)).get()
knn_graph_symmetrized = knn_graph.maximum(knn_graph.T)
Not working getting error : data indices and indptr should be 1-D. All the input arrays are n,1 shape, so cant figure out wheres the issue..