17a18 > #include 120a122,135 > /* > * Copies an array of doubles *fast*. > */ > void _copy_double_array(double *dst, double *src, int len) { > memcpy(dst, src, len * sizeof(double)); > } > > /* > * Copies an array of integers *fast*. > */ > void _copy_int_array(int *dst, int *src, int len) { > memcpy(dst, src, len * sizeof(int)); > } > 216c231 < * $ pdOut_i = pdIn_i *dFactor + (dMin - min(pdIn)) $. --- > * $ pdOut_i = (pdIn_i + min(pdIn)) * dFactor + dMin $. 218c233 < void rescaleDoubleArray( --- > void rescaleDoubleArray( 237,243c252 < // Calculate the offset < double dOffset = dMin - dOldMin; < < #ifdef _DEBUG < _debug("rescaleDoubleArray: dOldMin = %lf", dOldMin); < _debug("rescaleDoubleArray: dOffset = %lf", dOffset); < #endif --- > _debug("dOldMin: %lf", dOldMin); 247c256 < pdOut[i] = pdIn[i] * dFactor + dOffset; --- > pdOut[i] = (pdIn[i] - dOldMin) * dFactor + dMin; 252c261 < * Generate an array of `iNumValues` double value, so that the values --- > * Generate an array of `iNumValues` double values, so that the values 283c292 < if (iNumValues == 0) --- > if (iNumValues == 0) { 288a298,299 > return NULL; > } 333c344 < _warn("writeDoubleArray: iLen is 0."); --- > _warn("writeDoubleArray: iLen is 0."); 435,437c446 < for (int i = 0; i < pexIn->iNumLocalExtrema; i++) { < localExtrema->piLocalExtremaPos[i] = pexIn->piLocalExtremaPos[i]; < } --- > _copy_int_array(localExtrema->piLocalExtremaPos, pexIn->piLocalExtremaPos, pexIn->iNumLocalExtrema); 474,476c483 < for (int i = 0; i < pmmsIn->iNumValues; i++) { < signal->pdValues[i] = pmmsIn->pdValues[i]; < } --- > _copy_double_array(signal->pdValues, pmmsIn->pdValues, pmmsIn->iNumValues); 479c486 < _error("createSignalFromSignal: pmmsIn->pdValues is NULL while pmmsIn->iNumValues is not %d", pmmsIn->iNumValues); --- > _error("createSignalFromSignal: pmmsIn->pdValues is NULL while pmmsIn->iNumValues is not %d", pmmsIn->iNumValues); 535,537c542 < for (int i = 0; i < iArrayLen; i++) { < signal->pdValues[i] = pdIn[i]; < } --- > _copy_double_array(signal->pdValues, pdIn, iArrayLen); 553d557 < signal->pdValues = NULL; 687,688c691,692 < int val_a = * ( (double*) a ); < int val_b = * ( (double*) b ); --- > double val_a = * ( (double*) a ); > double val_b = * ( (double*) b ); 710,711d713 < double *pdInSorted = NULL; < pdInSorted = (double*) malloc(sizeof(double) *iLen); 717a720,722 > double *pdInSorted = NULL; > pdInSorted = (double*) malloc(sizeof(double) * iLen); > 721,723c726 < for (int i = 0; i < iLen; i++) { < pdInSorted[i] = pdIn[i]; < } --- > _copy_double_array(pdInSorted, pdIn, iLen); 744c747 < LocalExtrema *initLocalExtrema(int *piInPos, int iLen) { --- > LocalExtrema *createLocalExtrema() { 749,756c752,753 < localExtrema->iNumLocalExtrema = iLen; < localExtrema->piLocalExtremaPos = (int*) malloc(sizeof(int) *iLen); < if (localExtrema->piLocalExtremaPos == NULL) < _mem_error("initLocalExtrema: Failed to allocate memory for localExtrema->piLocalExtremaPos"); < < for (int i = 0; i < iLen; i++) { < localExtrema->piLocalExtremaPos[i] = piInPos[i]; < } --- > localExtrema->iNumLocalExtrema = 0; > localExtrema->piLocalExtremaPos = NULL; 789,792c786,793 < int iNumLocalMax = 0; < int iNumLocalMin = 0; < int *piLocalMaxPos = NULL; < int *piLocalMinPos = NULL; --- > > LocalExtrema *pexLocalMax = createLocalExtrema(); > LocalExtrema *pexLocalMin = createLocalExtrema(); > > int **ppiLocalMaxPos = &pexLocalMax->piLocalExtremaPos; > int **ppiLocalMinPos = &pexLocalMin->piLocalExtremaPos; > int *iNumLocalMax = &pexLocalMax->iNumLocalExtrema; > int *iNumLocalMin = &pexLocalMin->iNumLocalExtrema; 796c797 < iNumLocalMax++; --- > (*iNumLocalMax)++; 802,803c803,804 < if (piLocalMaxPos == NULL) < piLocalMaxPos = (int*) malloc(sizeof(int) *iNumLocalMax); --- > if (*ppiLocalMaxPos == NULL) > *ppiLocalMaxPos = (int*) malloc(sizeof(int) * (*iNumLocalMax)); 805c806 < piLocalMaxPos = (int*) realloc(piLocalMaxPos, sizeof(int) *iNumLocalMax); --- > *ppiLocalMaxPos = (int*) realloc(*ppiLocalMaxPos, sizeof(int) * (*iNumLocalMax)); 807c808 < if (piLocalMaxPos == NULL) --- > if (*ppiLocalMaxPos == NULL) 810c811 < piLocalMaxPos[iNumLocalMax-1] = i; --- > *ppiLocalMaxPos[(*iNumLocalMax)-1] = i; 814c815 < iNumLocalMin++; --- > (*iNumLocalMin)++; 820,821c821,822 < if (piLocalMinPos == NULL) < piLocalMinPos = (int*) malloc(sizeof(int) *iNumLocalMin); --- > if (*ppiLocalMinPos == NULL) > *ppiLocalMinPos = (int*) malloc(sizeof(int) * (*iNumLocalMin)); 823c824 < piLocalMinPos = (int*) realloc(piLocalMinPos, sizeof(int) *iNumLocalMin); --- > *ppiLocalMinPos = (int*) realloc(*ppiLocalMinPos, sizeof(int) * (*iNumLocalMin)); 825c826 < if (piLocalMinPos == NULL) --- > if (*ppiLocalMinPos == NULL) 828c829 < piLocalMinPos[iNumLocalMin-1] = i; --- > *ppiLocalMinPos[(*iNumLocalMin)-1] = i; 833,834c834,835 < _debug("findLocalExtremaFromArray: Found %d local maxima", iNumLocalMax); < _debug("findLocalExtremaFromArray: Found %d local minima", iNumLocalMin); --- > _debug("findLocalExtremaFromArray: Found %d local maxima", *iNumLocalMax); > _debug("findLocalExtremaFromArray: Found %d local minima", *iNumLocalMin); 837,838c838,839 < *ppexLocalMax = initLocalExtrema(piLocalMaxPos, iNumLocalMax); < *ppexLocalMin = initLocalExtrema(piLocalMinPos, iNumLocalMin); --- > *ppexLocalMax = pexLocalMax; > *ppexLocalMin = pexLocalMin; 898,908c899,902 < if (iLen == 0) < _warn("initHistogram: iLen is 0"); < < histogram->dIntervalMin = pdIn[0]; < histogram->dIntervalMax = pdIn[0]; < for (int i = 0; i < iLen; i++) { < if (pdIn[i] < histogram->dIntervalMin) < histogram->dIntervalMin = pdIn[i]; < if (pdIn[i] > histogram->dIntervalMax) < histogram->dIntervalMax = pdIn[i]; < } --- > int minPos, maxPos; > getMinMaxPos(pdIn, iLen, &minPos, &maxPos); > histogram->dIntervalMin = pdIn[minPos]; > histogram->dIntervalMax = pdIn[maxPos]; 924a919 > histogram->pdBinValues = NULL; // FIXME: This should be added in the final version 1000,1002c995,997 < double *pdOut = (double*) malloc(sizeof(double) *iOutLen); < if (pdOut == NULL) < _mem_error("convoluteSignals: Failed to allocate memory for pdOut"); --- > // Create the output signal to write directly to the destination > MMSignal *signal = createSignalWithDefault(iOutLen, 0); > double *pdOut = signal->pdValues; 1014c1009 < MMSignal *signal = createSignalFromDoubleArray(iOutLen, pdOut); --- > // Initialize the features of the signal 1028,1029c1023,1025 < double *pdValues = NULL; < pdValues = (double*) malloc(sizeof(double) * iLinenum); --- > MMSignal *signal = createSignalWithDefault(iLinenum, 1); > double *pdValues = signal->pdValues; > 1034d1029 < pdValues[i] = 1; 1036c1031 < pdValues[j] = pdValues[j] + pdValues[j-1]; --- > pdValues[j] += pdValues[j-1]; 1040d1034 < MMSignal *signal = createSignalFromDoubleArray(iLinenum, pdValues); 1042,1043d1035 < < free(pdValues);