This commit is contained in:
Frederik Beimgraben 2025-01-17 21:21:11 +01:00
parent ecba669e3d
commit d3051a9371

117
diff.txt
View File

@ -15,98 +15,91 @@
> memcpy(dst, src, len * sizeof(int)); > memcpy(dst, src, len * sizeof(int));
> } > }
> >
230,231c245,251 216c231
< // First find the old minimum < * $ pdOut_i = pdIn_i *dFactor + (dMin - min(pdIn)) $.
< double dOldMin = pdIn[0];
--- ---
> // Rescale the array > * $ pdOut_i = (pdIn_i + min(pdIn)) * dFactor + dMin $.
> for (int i = 0; i < iLen; i++) { 218c233
> pdOut[i] = pdIn[i] * dFactor; < void rescaleDoubleArray(
> }
>
> // First find the minimum
> double dOldMin = pdOut[0];
233,234c253,254
< if (pdIn[i] < dOldMin)
< dOldMin = pdIn[i];
--- ---
> if (pdOut[i] < dOldMin) > void rescaleDoubleArray(
> dOldMin = pdOut[i]; 237,243c252
239a260,264 < // Calculate the offset
> // Move the values to the new minimum < double dOffset = dMin - dOldMin;
> for (int i = 0; i < iLen; i++) {
> pdOut[i] += dOffset;
> }
>
244,248d268
< <
< // Rescale the array < #ifdef _DEBUG
< for (int i = 0; i < iLen; i++) { < _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] * dFactor + dOffset;
< } ---
252c272 > 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 value, so that the values
--- ---
> * Generate an array of `iNumValues` double values, so that the values > * Generate an array of `iNumValues` double values, so that the values
283c303 283c292
< if (iNumValues == 0) < if (iNumValues == 0)
--- ---
> if (iNumValues == 0) { > if (iNumValues == 0) {
288a309,310 288a298,299
> return NULL; > return NULL;
> } > }
333c355 333c344
< _warn("writeDoubleArray: iLen is 0."); < _warn("writeDoubleArray: iLen is 0.");
--- ---
> _warn("writeDoubleArray: iLen is 0."); > _warn("writeDoubleArray: iLen is 0.");
435,437c457 435,437c446
< for (int i = 0; i < pexIn->iNumLocalExtrema; i++) { < for (int i = 0; i < pexIn->iNumLocalExtrema; i++) {
< localExtrema->piLocalExtremaPos[i] = pexIn->piLocalExtremaPos[i]; < localExtrema->piLocalExtremaPos[i] = pexIn->piLocalExtremaPos[i];
< } < }
--- ---
> _copy_int_array(localExtrema->piLocalExtremaPos, pexIn->piLocalExtremaPos, pexIn->iNumLocalExtrema); > _copy_int_array(localExtrema->piLocalExtremaPos, pexIn->piLocalExtremaPos, pexIn->iNumLocalExtrema);
474,476c494 474,476c483
< for (int i = 0; i < pmmsIn->iNumValues; i++) { < for (int i = 0; i < pmmsIn->iNumValues; i++) {
< signal->pdValues[i] = pmmsIn->pdValues[i]; < signal->pdValues[i] = pmmsIn->pdValues[i];
< } < }
--- ---
> _copy_double_array(signal->pdValues, pmmsIn->pdValues, pmmsIn->iNumValues); > _copy_double_array(signal->pdValues, pmmsIn->pdValues, pmmsIn->iNumValues);
479c497 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);
--- ---
> _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,537c553 535,537c542
< for (int i = 0; i < iArrayLen; i++) { < for (int i = 0; i < iArrayLen; i++) {
< signal->pdValues[i] = pdIn[i]; < signal->pdValues[i] = pdIn[i];
< } < }
--- ---
> _copy_double_array(signal->pdValues, pdIn, iArrayLen); > _copy_double_array(signal->pdValues, pdIn, iArrayLen);
553d568 553d557
< signal->pdValues = NULL; < signal->pdValues = NULL;
687,688c702,703 687,688c691,692
< int val_a = * ( (double*) a ); < int val_a = * ( (double*) a );
< int val_b = * ( (double*) b ); < int val_b = * ( (double*) b );
--- ---
> double val_a = * ( (double*) a ); > double val_a = * ( (double*) a );
> double val_b = * ( (double*) b ); > double val_b = * ( (double*) b );
710,711d724 710,711d713
< double *pdInSorted = NULL; < double *pdInSorted = NULL;
< pdInSorted = (double*) malloc(sizeof(double) *iLen); < pdInSorted = (double*) malloc(sizeof(double) *iLen);
717a731,733 717a720,722
> double *pdInSorted = NULL; > double *pdInSorted = NULL;
> pdInSorted = (double*) malloc(sizeof(double) * iLen); > pdInSorted = (double*) malloc(sizeof(double) * iLen);
> >
721,723c737 721,723c726
< for (int i = 0; i < iLen; i++) { < for (int i = 0; i < iLen; i++) {
< pdInSorted[i] = pdIn[i]; < pdInSorted[i] = pdIn[i];
< } < }
--- ---
> _copy_double_array(pdInSorted, pdIn, iLen); > _copy_double_array(pdInSorted, pdIn, iLen);
744c758 744c747
< LocalExtrema *initLocalExtrema(int *piInPos, int iLen) { < LocalExtrema *initLocalExtrema(int *piInPos, int iLen) {
--- ---
> LocalExtrema *createLocalExtrema() { > LocalExtrema *createLocalExtrema() {
749,756c763,764 749,756c752,753
< localExtrema->iNumLocalExtrema = iLen; < localExtrema->iNumLocalExtrema = iLen;
< localExtrema->piLocalExtremaPos = (int*) malloc(sizeof(int) *iLen); < localExtrema->piLocalExtremaPos = (int*) malloc(sizeof(int) *iLen);
< if (localExtrema->piLocalExtremaPos == NULL) < if (localExtrema->piLocalExtremaPos == NULL)
@ -118,7 +111,7 @@
--- ---
> localExtrema->iNumLocalExtrema = 0; > localExtrema->iNumLocalExtrema = 0;
> localExtrema->piLocalExtremaPos = NULL; > localExtrema->piLocalExtremaPos = NULL;
789,792c797,804 789,792c786,793
< int iNumLocalMax = 0; < int iNumLocalMax = 0;
< int iNumLocalMin = 0; < int iNumLocalMin = 0;
< int *piLocalMaxPos = NULL; < int *piLocalMaxPos = NULL;
@ -132,63 +125,63 @@
> int **ppiLocalMinPos = &pexLocalMin->piLocalExtremaPos; > int **ppiLocalMinPos = &pexLocalMin->piLocalExtremaPos;
> int *iNumLocalMax = &pexLocalMax->iNumLocalExtrema; > int *iNumLocalMax = &pexLocalMax->iNumLocalExtrema;
> int *iNumLocalMin = &pexLocalMin->iNumLocalExtrema; > int *iNumLocalMin = &pexLocalMin->iNumLocalExtrema;
796c808 796c797
< iNumLocalMax++; < iNumLocalMax++;
--- ---
> (*iNumLocalMax)++; > (*iNumLocalMax)++;
802,803c814,815 802,803c803,804
< if (piLocalMaxPos == NULL) < if (piLocalMaxPos == NULL)
< piLocalMaxPos = (int*) malloc(sizeof(int) *iNumLocalMax); < piLocalMaxPos = (int*) malloc(sizeof(int) *iNumLocalMax);
--- ---
> if (*ppiLocalMaxPos == NULL) > if (*ppiLocalMaxPos == NULL)
> *ppiLocalMaxPos = (int*) malloc(sizeof(int) * (*iNumLocalMax)); > *ppiLocalMaxPos = (int*) malloc(sizeof(int) * (*iNumLocalMax));
805c817 805c806
< piLocalMaxPos = (int*) realloc(piLocalMaxPos, sizeof(int) *iNumLocalMax); < piLocalMaxPos = (int*) realloc(piLocalMaxPos, sizeof(int) *iNumLocalMax);
--- ---
> *ppiLocalMaxPos = (int*) realloc(*ppiLocalMaxPos, sizeof(int) * (*iNumLocalMax)); > *ppiLocalMaxPos = (int*) realloc(*ppiLocalMaxPos, sizeof(int) * (*iNumLocalMax));
807c819 807c808
< if (piLocalMaxPos == NULL) < if (piLocalMaxPos == NULL)
--- ---
> if (*ppiLocalMaxPos == NULL) > if (*ppiLocalMaxPos == NULL)
810c822 810c811
< piLocalMaxPos[iNumLocalMax-1] = i; < piLocalMaxPos[iNumLocalMax-1] = i;
--- ---
> *ppiLocalMaxPos[(*iNumLocalMax)-1] = i; > *ppiLocalMaxPos[(*iNumLocalMax)-1] = i;
814c826 814c815
< iNumLocalMin++; < iNumLocalMin++;
--- ---
> (*iNumLocalMin)++; > (*iNumLocalMin)++;
820,821c832,833 820,821c821,822
< if (piLocalMinPos == NULL) < if (piLocalMinPos == NULL)
< piLocalMinPos = (int*) malloc(sizeof(int) *iNumLocalMin); < piLocalMinPos = (int*) malloc(sizeof(int) *iNumLocalMin);
--- ---
> if (*ppiLocalMinPos == NULL) > if (*ppiLocalMinPos == NULL)
> *ppiLocalMinPos = (int*) malloc(sizeof(int) * (*iNumLocalMin)); > *ppiLocalMinPos = (int*) malloc(sizeof(int) * (*iNumLocalMin));
823c835 823c824
< piLocalMinPos = (int*) realloc(piLocalMinPos, sizeof(int) *iNumLocalMin); < piLocalMinPos = (int*) realloc(piLocalMinPos, sizeof(int) *iNumLocalMin);
--- ---
> *ppiLocalMinPos = (int*) realloc(*ppiLocalMinPos, sizeof(int) * (*iNumLocalMin)); > *ppiLocalMinPos = (int*) realloc(*ppiLocalMinPos, sizeof(int) * (*iNumLocalMin));
825c837 825c826
< if (piLocalMinPos == NULL) < if (piLocalMinPos == NULL)
--- ---
> if (*ppiLocalMinPos == NULL) > if (*ppiLocalMinPos == NULL)
828c840 828c829
< piLocalMinPos[iNumLocalMin-1] = i; < piLocalMinPos[iNumLocalMin-1] = i;
--- ---
> *ppiLocalMinPos[(*iNumLocalMin)-1] = i; > *ppiLocalMinPos[(*iNumLocalMin)-1] = i;
833,834c845,846 833,834c834,835
< _debug("findLocalExtremaFromArray: Found %d local maxima", iNumLocalMax); < _debug("findLocalExtremaFromArray: Found %d local maxima", iNumLocalMax);
< _debug("findLocalExtremaFromArray: Found %d local minima", iNumLocalMin); < _debug("findLocalExtremaFromArray: Found %d local minima", iNumLocalMin);
--- ---
> _debug("findLocalExtremaFromArray: Found %d local maxima", *iNumLocalMax); > _debug("findLocalExtremaFromArray: Found %d local maxima", *iNumLocalMax);
> _debug("findLocalExtremaFromArray: Found %d local minima", *iNumLocalMin); > _debug("findLocalExtremaFromArray: Found %d local minima", *iNumLocalMin);
837,838c849,850 837,838c838,839
< *ppexLocalMax = initLocalExtrema(piLocalMaxPos, iNumLocalMax); < *ppexLocalMax = initLocalExtrema(piLocalMaxPos, iNumLocalMax);
< *ppexLocalMin = initLocalExtrema(piLocalMinPos, iNumLocalMin); < *ppexLocalMin = initLocalExtrema(piLocalMinPos, iNumLocalMin);
--- ---
> *ppexLocalMax = pexLocalMax; > *ppexLocalMax = pexLocalMax;
> *ppexLocalMin = pexLocalMin; > *ppexLocalMin = pexLocalMin;
898,908c910,913 898,908c899,902
< if (iLen == 0) < if (iLen == 0)
< _warn("initHistogram: iLen is 0"); < _warn("initHistogram: iLen is 0");
< <
@ -205,9 +198,9 @@
> getMinMaxPos(pdIn, iLen, &minPos, &maxPos); > getMinMaxPos(pdIn, iLen, &minPos, &maxPos);
> histogram->dIntervalMin = pdIn[minPos]; > histogram->dIntervalMin = pdIn[minPos];
> histogram->dIntervalMax = pdIn[maxPos]; > histogram->dIntervalMax = pdIn[maxPos];
924a930 924a919
> histogram->pdBinValues = NULL; // FIXME: This should be added in the final version > histogram->pdBinValues = NULL; // FIXME: This should be added in the final version
1000,1002c1006,1008 1000,1002c995,997
< double *pdOut = (double*) malloc(sizeof(double) *iOutLen); < double *pdOut = (double*) malloc(sizeof(double) *iOutLen);
< if (pdOut == NULL) < if (pdOut == NULL)
< _mem_error("convoluteSignals: Failed to allocate memory for pdOut"); < _mem_error("convoluteSignals: Failed to allocate memory for pdOut");
@ -215,25 +208,25 @@
> // Create the output signal to write directly to the destination > // Create the output signal to write directly to the destination
> MMSignal *signal = createSignalWithDefault(iOutLen, 0); > MMSignal *signal = createSignalWithDefault(iOutLen, 0);
> double *pdOut = signal->pdValues; > double *pdOut = signal->pdValues;
1014c1020 1014c1009
< MMSignal *signal = createSignalFromDoubleArray(iOutLen, pdOut); < MMSignal *signal = createSignalFromDoubleArray(iOutLen, pdOut);
--- ---
> // Initialize the features of the signal > // Initialize the features of the signal
1028,1029c1034,1036 1028,1029c1023,1025
< double *pdValues = NULL; < double *pdValues = NULL;
< pdValues = (double*) malloc(sizeof(double) * iLinenum); < pdValues = (double*) malloc(sizeof(double) * iLinenum);
--- ---
> MMSignal *signal = createSignalWithDefault(iLinenum, 1); > MMSignal *signal = createSignalWithDefault(iLinenum, 1);
> double *pdValues = signal->pdValues; > double *pdValues = signal->pdValues;
> >
1034d1040 1034d1029
< pdValues[i] = 1; < pdValues[i] = 1;
1036c1042 1036c1031
< pdValues[j] = pdValues[j] + pdValues[j-1]; < pdValues[j] = pdValues[j] + pdValues[j-1];
--- ---
> pdValues[j] += pdValues[j-1]; > pdValues[j] += pdValues[j-1];
1040d1045 1040d1034
< MMSignal *signal = createSignalFromDoubleArray(iLinenum, pdValues); < MMSignal *signal = createSignalFromDoubleArray(iLinenum, pdValues);
1042,1043d1046 1042,1043d1035
< <
< free(pdValues); < free(pdValues);