From 79c9c5f8269711ec07b6a4485e8f0d43d84791bd Mon Sep 17 00:00:00 2001 From: Apostolof Date: Wed, 24 Jan 2018 14:04:02 +0200 Subject: [PATCH] Fix memory allocations --- data/run_helper.txt | 12 +++---- mean_shift_serial/serial_declarations.c | 43 +++++++++++++------------ 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/data/run_helper.txt b/data/run_helper.txt index 98e4d12..7e27a49 100644 --- a/data/run_helper.txt +++ b/data/run_helper.txt @@ -1,9 +1,9 @@ Dataset X { int NUMBER_OF_POINTS = 600; int DIMENSIONS = 2; - char* POINTS_FILENAME = "data/X.bin"; + char* POINTS_FILENAME = "../data/X.bin"; - A good h is 1 + A good deviation is 1 For Processing script: float maxX = 17.124000; float minX = 3.402000; @@ -16,9 +16,9 @@ Dataset X { Dataset s1 { int NUMBER_OF_POINTS = 5000; int DIMENSIONS = 2; - char* POINTS_FILENAME = "data/s1"; + char* POINTS_FILENAME = "../data/s1"; - A good h is 30000 + A good deviation is 30000 For Processing script: float maxX = 961951; float minX = 19835; @@ -31,9 +31,9 @@ Dataset s1 { Dataset s4 { int NUMBER_OF_POINTS = 5000; int DIMENSIONS = 2; - char* POINTS_FILENAME = "data/s4"; + char* POINTS_FILENAME = "../data/s4"; - A good h is 30000-35000 + A good deviation is 30000-35000 For Processing script: float maxX = 932954; float minX = 89604; diff --git a/mean_shift_serial/serial_declarations.c b/mean_shift_serial/serial_declarations.c index 5e68d60..ce7da7f 100644 --- a/mean_shift_serial/serial_declarations.c +++ b/mean_shift_serial/serial_declarations.c @@ -90,27 +90,26 @@ void init(double ***vectors, char **labels, parameters *params){ int meanshift(double **original_points, double ***shifted_points, int deviation , parameters *opt){ static int iteration = 0; + static double **mean_shift_vector, **kernel_matrix, *denominator; // allocates memory and copies original points on first iteration if (iteration == 0 || (*shifted_points) == NULL){ - iteration = 0; (*shifted_points) = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS); duplicate(original_points, NUMBER_OF_POINTS, DIMENSIONS, shifted_points); - } - // allocates memory for mean shift vector - double **mean_shift_vector; - mean_shift_vector = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS); - // initializes elements of mean_shift_vector to inf - for (int i=0;i opt->epsilon) { ++iteration; - return meanshift(original_points, shifted_points, deviation, opt); + meanshift(original_points, shifted_points, deviation, opt); + } + + if (iteration == 0){ + // cleans up this iteration's allocations + free(mean_shift_vector[0]); + free(mean_shift_vector); + free(kernel_matrix[0]); + free(kernel_matrix); + free(denominator); } return iteration;