MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / pyKNNGraph

Method pyKNNGraph

include/bind.h:326–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324
325 template<class... Args>
326 pyKNNGraph(py::handle scope, const char *name, const Args &...args) :
327 Base(scope, signature(name, typeid(Index).name()).c_str(), args...) {
328 attr("__doc__") = "KNNGraph(index_type=dtype.uint32, device_ids=[], num_thread_per_worker=auto)"
329 R"(
330 K-nearest neighbor graphs.
331
332 Parameters:
333 index_type (dtype, optional): type of node indexes
334 device_ids (list of int, optional): GPU ids, [] for auto
335 num_thread_per_worker (int, optional): number of CPU thread per GPU
336 )";
337
338 // override instance name with template name
339 attr("__name__") = py::internal_str(name);
340 attr("__qualname__") = py::internal_str(name);
341
342 // data members
343 def_readonly("num_neighbor", &KNNGraph::num_neighbor);
344 def_readonly("perplexity", &KNNGraph::perplexity);
345 def_readonly("vector_normalization", &KNNGraph::vector_normalization);
346 def_readonly("num_worker", &KNNGraph::num_worker);
347 def_readonly("num_thread", &KNNGraph::num_thread);
348
349 // member functions
350 def(py::init<std::vector<int>, int>(), py::no_gil(),
351 py::arg("device_ids") = std::vector<int>(), py::arg("num_thread_per_worker") = graphvite::kAuto);
352
353 def("load", &KNNGraph::load_file, py::no_gil(),
354 py::arg("vector_file"), py::arg("num_neighbor") = 200, py::arg("perplexity") = 30,
355 py::arg("vector_normalization") = true, py::arg("delimiters") = " \t\r\n", py::arg("comment") = "#",
356 "load(*arg, **kwargs)"
357 R"(
358 Build a KNN graph from a vector list. Store the graph in an adjacency list.
359
360 This function has 2 overloads
361
362 .. function:: load(vector_file, num_neighbor=200, perplexity=30, vector_normalization=True, delimiters=' \\t\\r\\n', comment='#')
363 .. function:: load(vectors, num_neighbor=200, perplexity=30, vector_normalization=True)
364
365 Parameters:
366 file_name (str): file name
367 vectors (2D array_like): vector list
368 num_neighbor (int, optional): number of neighbors for each node
369 perplexity (int, optional): perplexity for the neighborhood of each node
370 vector_normalization (bool, optional): normalize the input vectors or not
371 delimiters (str, optional): string of delimiter characters
372 comment (str, optional): prefix of comment strings
373 )");
374
375 def("load", &KNNGraph::load_numpy, py::no_gil(),
376 py::arg("vectors"), py::arg("num_neighbor") = 200, py::arg("perplexity") = 30,
377 py::arg("vector_normalization") = true);
378
379 def("__repr__", &KNNGraph::info, py::no_gil());
380 }
381};
382
383template<size_t dim, class Float = float, class Index = size_t>

Callers

nothing calls this directly

Calls 2

signatureFunction · 0.70
nameMethod · 0.45

Tested by

no test coverage detected