Skip to content

Commit

Permalink
Slightly improved SPTree constructor performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Paaso committed Sep 15, 2016
1 parent 8b36253 commit e599275
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions sptree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,30 @@ SPTree::SPTree(unsigned int D, double* inp_data, unsigned int N)
{

// Compute mean, width, and height of current map (boundaries of SPTree)
int nD = 0;
double* mean_Y = (double*) calloc(D, sizeof(double));
double* min_Y = (double*) malloc(D * sizeof(double)); for(unsigned int d = 0; d < D; d++) min_Y[d] = DBL_MAX;
double* max_Y = (double*) malloc(D * sizeof(double)); for(unsigned int d = 0; d < D; d++) max_Y[d] = -DBL_MAX;
for(unsigned int n = 0; n < N; n++) {
for(unsigned int d = 0; d < D; d++) {
mean_Y[d] += inp_data[n * D + d];
if(inp_data[nD + d] < min_Y[d]) min_Y[d] = inp_data[nD + d];
if(inp_data[nD + d] > max_Y[d]) max_Y[d] = inp_data[nD + d];
double* width = (double*) malloc(D * sizeof(double));
double min_Y, max_Y;
int nD;
for(unsigned int d = 0; d < D; d++) {
nD = 0;
min_Y = DBL_MAX;
max_Y = -DBL_MAX;
for(unsigned int n = 0; n < N; n++) {
mean_Y[d] += inp_data[nD + d];
if(inp_data[nD + d] < min_Y) min_Y = inp_data[nD + d];
if(inp_data[nD + d] > max_Y) max_Y = inp_data[nD + d];
nD += D;
}
nD += D;
mean_Y[d] /= (double) N;
width[d] = fmax(max_Y - mean_Y[d], mean_Y[d] - min_Y) + 1e-5;
}
for(int d = 0; d < D; d++) mean_Y[d] /= (double) N;

// Construct SPTree
double* width = (double*) malloc(D * sizeof(double));
for(int d = 0; d < D; d++) width[d] = fmax(max_Y[d] - mean_Y[d], mean_Y[d] - min_Y[d]) + 1e-5;
init(NULL, D, inp_data, mean_Y, width);
fill(N);

// Clean up memory
free(mean_Y);
free(max_Y);
free(min_Y);
free(width);
}

Expand Down

0 comments on commit e599275

Please sign in to comment.