From 1c9453e7b75b6facb6f0ca715ec932bb37771ce2 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 3 Jan 2021 10:24:16 -0800 Subject: [PATCH] remove manual memory management of nnIdx in mingle Related to #1832. --- lib/mingle/nearest_neighbor_graph_ann.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/mingle/nearest_neighbor_graph_ann.cpp b/lib/mingle/nearest_neighbor_graph_ann.cpp index 4c32566d3..c6e6d7f9f 100644 --- a/lib/mingle/nearest_neighbor_graph_ann.cpp +++ b/lib/mingle/nearest_neighbor_graph_ann.cpp @@ -16,6 +16,7 @@ //---------------------------------------------------------------------- #include // ANN declarations +#include int dim = 4; // dimension @@ -87,7 +88,6 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x, */ ANNpointArray dataPts; // data points - ANNidxArray nnIdx; // near neighbor indices ANNdistArray dists; // near neighbor distances ANNkd_tree* kdTree; // search structure @@ -102,7 +102,7 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x, dataPts = annAllocPts(nPts, dim); // allocate data points - nnIdx = new ANNidx[k]; // allocate near neighbor indices + std::vector nnIdx(k); // allocate near neighbor indices dists = new ANNdist[k]; // allocate near neighbor dists for (int i = 0; i < nPts; i++){ @@ -121,7 +121,7 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x, kdTree->annkSearch( // search dataPts[ip], // query point k, // number of near neighbors - nnIdx, // nearest neighbors (returned) + nnIdx.data(), // nearest neighbors (returned) dists, // distance (returned) eps); // error bound @@ -149,7 +149,7 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x, kdTree->annkSearch( // search dataPts[ip], // query point k, // number of near neighbors - nnIdx, // nearest neighbors (returned) + nnIdx.data(), // nearest neighbors (returned) dists, // distance (returned) eps); // error bound @@ -162,8 +162,7 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x, } } - delete [] nnIdx; // clean things up - delete [] dists; + delete [] dists; // clean things up delete kdTree; *nz0 = nz; -- 2.40.0