Changeset 1064 for cpp/frams/model/similarity/EMD/emd.c
 Timestamp:
 01/26/21 18:50:37 (2 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cpp/frams/model/similarity/EMD/emd.c
r1063 r1064 2 2 emd.c 3 3 4 Last update: 3/14/98 4 Last update: 3/14/98 (but see emd.h for a list newer changes) 5 5 6 6 An implementation of the Earth Movers Distance. … … 13 13 EMail: rubner@cs.stanford.edu URL: http://robotics.stanford.edu/~rubner/emd/default.htm 14 14 */ 15 16 // For a list of changes since 2020, see emd.h 15 17 16 18 #include <stdio.h> … … 98 100 { 99 101 int itr; 100 int max_n = (_n1 > _n2) ? _n1 : _n2;102 int max_n = max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have. 101 103 double totalCost; 102 104 float w; 103 105 node2_t *XP; 104 106 flow_t *FlowP; 105 node1_t U[max_n], V[max_n];107 node1_t *U=new node1_t[max_n], *V=new node1_t[max_n]; 106 108 /* THE COST MATRIX */ 107 109 float** _CM = new float*[_n1]; … … 189 191 delete[] _RowsX; 190 192 delete[] _ColsX; 193 194 delete[] U; 195 delete[] V; 191 196 192 197 /* RETURN THE NORMALIZED COST == EMD */ … … 206 211 { 207 212 int i, j; 208 int max_n = (_n1 > _n2) ? _n1 : _n2;213 int max_n = max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have. 209 214 double sSum, dSum, diff; 210 215 feature_t *P1, *P2; 211 double S[max_n], D[max_n];216 double *S=new double[max_n], *D=new double[max_n]; 212 217 213 218 … … 272 277 273 278 _EnterX = _EndX++; /* AN EMPTY SLOT (ONLY _n1+_n21 BASIC VARIABLES) */ 279 280 delete[] S; 281 delete[] D; 274 282 275 283 return sSum > dSum ? dSum : sSum; … … 465 473 static void newSol(int _n1, int _n2, node2_t * _XV, char **_IsX, node2_t **_RowsX, node2_t **_ColsX) 466 474 { 467 int i, j, k, max_n = (_n1 > _n2) ? _n1 : _n2; 475 int i, j, k; 476 int max_n = max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have. 468 477 double xMin; 469 478 int steps; 470 node2_t * Loop[2*max_n], *CurX, *LeaveX;479 node2_t **Loop=new node2_t*[2*max_n], *CurX, *LeaveX; 471 480 472 481 #if DEBUG_LEVEL > 3 … … 534 543 /* SET _EnterX TO BE THE NEW EMPTY SLOT */ 535 544 _EnterX = LeaveX; 545 546 delete[] Loop; 536 547 } 537 548 … … 543 554 static int findLoop(node2_t **Loop, int _n1, int _n2, node2_t *_XV, node2_t **_RowsX, node2_t **_ColsX) 544 555 { 545 int i, steps, max_n = (_n1 > _n2) ? _n1 : _n2; 556 int i, steps; 557 int max_n = max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have. 546 558 node2_t **CurX, *NewX; 547 char IsUsed[2*max_n];559 char *IsUsed=new char[2*max_n]; 548 560 549 561 for (i=0; i < _n1+_n2; i++) … … 627 639 #endif 628 640 641 delete[] IsUsed; 642 629 643 return steps; 630 644 } … … 637 651 static void russel(double *S, double *D, int _n1, int _n2, float **_CM, char **_IsX, node2_t **_RowsX, node2_t **_ColsX) 638 652 { 639 int i, j, found, minI, minJ, max_n = (_n1 > _n2) ? _n1 : _n2; 653 int i, j, found, minI, minJ; 654 int max_n = max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have. 640 655 double deltaMin, oldVal, diff; 641 656 double** Delta = new double*[_n1]; 642 657 for(int k = 0; k < _n1; ++k) 643 658 Delta[k] = new double[_n2]; 644 node1_t Ur[max_n], Vr[max_n];659 node1_t *Ur=new node1_t[max_n], *Vr=new node1_t[max_n]; 645 660 node1_t uHead, *CurU, *PrevU; 646 661 node1_t vHead, *CurV, *PrevV; … … 790 805 } 791 806 } while (uHead.Next != NULL  vHead.Next != NULL); 807 808 delete[] Ur; 809 delete[] Vr; 792 810 for(int k = 0; k < _n1; ++k) 793 811 delete[] Delta[k];
Note: See TracChangeset
for help on using the changeset viewer.