]> granicus.if.org Git - graphviz/commitdiff
nearest_neighbor_graph_ann: take array parameters as vector instead of C arrays
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 8 Jan 2022 19:04:08 +0000 (11:04 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 11 Jan 2022 15:52:08 +0000 (07:52 -0800)
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
lib/mingle/nearest_neighbor_graph_ann.cpp
lib/mingle/nearest_neighbor_graph_ann.h

index 17690cfa734efa3eedf103bc67da5c65ab6c48ca..13d08d59626b56ca347d051aff2f338c3ad22cdd 100644 (file)
@@ -37,8 +37,7 @@ SparseMatrix nearest_neighbor_graph(int nPts, int num_neigbors, double *x, doubl
   std::vector<int> jcn(nPts * k * 2);
   std::vector<double> 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(),
index eb892d689b631ef4ecf18b05dccdf333f9cdc9f6..f2dd0b39df22f37748df338f60296213e16b3ccc 100644 (file)
@@ -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<int> &irn,
+                                std::vector<int> &jcn,
+                                std::vector<double> &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<ANNidx> nnIdx(k);                                                // allocate near neighbor indices
   std::vector<ANNdist> dists(k);                                       // allocate near neighbor dists
index 77660d9add33001d0c60198eb184ac810c8d3666..9d5e2c5cfeea21c42e091320fcb7fe35b288a04c 100644 (file)
@@ -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 <vector>
+
+void nearest_neighbor_graph_ann(int nPts, int k, double eps, double *x,
+                                int *nz0, std::vector<int> &irn,
+                                std::vector<int> &jcn,
+                                std::vector<double> &val);