From b8d23ff68e7d14a6b12dc0b158518157aa005ecf Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 8 Jan 2022 11:04:08 -0800 Subject: [PATCH] nearest_neighbor_graph_ann: take array parameters as vector instead of C arrays Now that all calls to this function are in C++, there is no need to degrade to C data types when calling into it. Gitlab: #2154 --- lib/mingle/nearest_neighbor_graph.cpp | 3 +-- lib/mingle/nearest_neighbor_graph_ann.cpp | 10 ++++------ lib/mingle/nearest_neighbor_graph_ann.h | 7 ++++++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/mingle/nearest_neighbor_graph.cpp b/lib/mingle/nearest_neighbor_graph.cpp index 17690cfa7..13d08d596 100644 --- a/lib/mingle/nearest_neighbor_graph.cpp +++ b/lib/mingle/nearest_neighbor_graph.cpp @@ -37,8 +37,7 @@ SparseMatrix nearest_neighbor_graph(int nPts, int num_neigbors, double *x, doubl std::vector jcn(nPts * k * 2); std::vector val(nPts * k * 2); - nearest_neighbor_graph_ann(nPts, num_neigbors, eps, x, &nz, irn.data(), - jcn.data(), val.data()); + nearest_neighbor_graph_ann(nPts, num_neigbors, eps, x, &nz, irn, jcn, val); A = SparseMatrix_from_coordinate_arrays(nz, nPts, nPts, irn.data(), jcn.data(), val.data(), diff --git a/lib/mingle/nearest_neighbor_graph_ann.cpp b/lib/mingle/nearest_neighbor_graph_ann.cpp index eb892d689..f2dd0b39d 100644 --- a/lib/mingle/nearest_neighbor_graph_ann.cpp +++ b/lib/mingle/nearest_neighbor_graph_ann.cpp @@ -50,7 +50,10 @@ static void sortPtsY(int n, ANNpointArray pts){ } } -void nearest_neighbor_graph_ann(int nPts, int k, double eps, double *x, int *nz0, int *irn0, int *jcn0, double *val0){ +void nearest_neighbor_graph_ann(int nPts, int k, double eps, double *x, + int *nz0, std::vector &irn, + std::vector &jcn, + std::vector &val) { /* Gives a nearest neighbor graph is a list of dim-dimendional points. The connectivity is in irn/jcn, and the distance in val. @@ -66,11 +69,6 @@ void nearest_neighbor_graph_ann(int nPts, int k, double eps, double *x, int *nz0 note that there could be repeates */ - int *irn = irn0; - int *jcn = jcn0; - double *val = val0; - - ANNpointArray dataPts = annAllocPts(nPts, dim); // allocate data points std::vector nnIdx(k); // allocate near neighbor indices std::vector dists(k); // allocate near neighbor dists diff --git a/lib/mingle/nearest_neighbor_graph_ann.h b/lib/mingle/nearest_neighbor_graph_ann.h index 77660d9ad..9d5e2c5cf 100644 --- a/lib/mingle/nearest_neighbor_graph_ann.h +++ b/lib/mingle/nearest_neighbor_graph_ann.h @@ -10,4 +10,9 @@ #pragma once -void nearest_neighbor_graph_ann(int nPts, int k, double eps, double *x, int *nz0, int *irn0, int *jcn0, double *val0); +#include + +void nearest_neighbor_graph_ann(int nPts, int k, double eps, double *x, + int *nz0, std::vector &irn, + std::vector &jcn, + std::vector &val); -- 2.40.0