This commit is contained in:
Frederik Beimgraben 2025-01-17 20:27:53 +01:00
parent c1d08e3044
commit 301383c006

239
diff.txt Normal file
View File

@ -0,0 +1,239 @@
17a18
> #include <string.h>
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));
> }
>
230,231c245,251
< // First find the old minimum
< double dOldMin = pdIn[0];
---
> // Rescale the array
> for (int i = 0; i < iLen; i++) {
> pdOut[i] = pdIn[i] * dFactor;
> }
>
> // First find the minimum
> double dOldMin = pdOut[0];
233,234c253,254
< if (pdIn[i] < dOldMin)
< dOldMin = pdIn[i];
---
> if (pdOut[i] < dOldMin)
> dOldMin = pdOut[i];
239a260,264
> // Move the values to the new minimum
> for (int i = 0; i < iLen; i++) {
> pdOut[i] += dOffset;
> }
>
244,248d268
<
< // Rescale the array
< for (int i = 0; i < iLen; i++) {
< pdOut[i] = pdIn[i] * dFactor + dOffset;
< }
252c272
< * Generate an array of `iNumValues` double value, so that the values
---
> * Generate an array of `iNumValues` double values, so that the values
283c303
< if (iNumValues == 0)
---
> if (iNumValues == 0) {
288a309,310
> return NULL;
> }
333c355
< _warn("writeDoubleArray: iLen is 0.");
---
> _warn("writeDoubleArray: iLen is 0.");
435,437c457
< for (int i = 0; i < pexIn->iNumLocalExtrema; i++) {
< localExtrema->piLocalExtremaPos[i] = pexIn->piLocalExtremaPos[i];
< }
---
> _copy_int_array(localExtrema->piLocalExtremaPos, pexIn->piLocalExtremaPos, pexIn->iNumLocalExtrema);
474,476c494
< for (int i = 0; i < pmmsIn->iNumValues; i++) {
< signal->pdValues[i] = pmmsIn->pdValues[i];
< }
---
> _copy_double_array(signal->pdValues, pmmsIn->pdValues, pmmsIn->iNumValues);
479c497
< _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
< for (int i = 0; i < iArrayLen; i++) {
< signal->pdValues[i] = pdIn[i];
< }
---
> _copy_double_array(signal->pdValues, pdIn, iArrayLen);
553d568
< signal->pdValues = NULL;
687,688c702,703
< int val_a = * ( (double*) a );
< int val_b = * ( (double*) b );
---
> double val_a = * ( (double*) a );
> double val_b = * ( (double*) b );
710,711d724
< double *pdInSorted = NULL;
< pdInSorted = (double*) malloc(sizeof(double) *iLen);
717a731,733
> double *pdInSorted = NULL;
> pdInSorted = (double*) malloc(sizeof(double) * iLen);
>
721,723c737
< for (int i = 0; i < iLen; i++) {
< pdInSorted[i] = pdIn[i];
< }
---
> _copy_double_array(pdInSorted, pdIn, iLen);
744c758
< LocalExtrema *initLocalExtrema(int *piInPos, int iLen) {
---
> LocalExtrema *createLocalExtrema() {
749,756c763,764
< 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,792c797,804
< 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;
796c808
< iNumLocalMax++;
---
> (*iNumLocalMax)++;
802,803c814,815
< if (piLocalMaxPos == NULL)
< piLocalMaxPos = (int*) malloc(sizeof(int) *iNumLocalMax);
---
> if (*ppiLocalMaxPos == NULL)
> *ppiLocalMaxPos = (int*) malloc(sizeof(int) * (*iNumLocalMax));
805c817
< piLocalMaxPos = (int*) realloc(piLocalMaxPos, sizeof(int) *iNumLocalMax);
---
> *ppiLocalMaxPos = (int*) realloc(*ppiLocalMaxPos, sizeof(int) * (*iNumLocalMax));
807c819
< if (piLocalMaxPos == NULL)
---
> if (*ppiLocalMaxPos == NULL)
810c822
< piLocalMaxPos[iNumLocalMax-1] = i;
---
> *ppiLocalMaxPos[(*iNumLocalMax)-1] = i;
814c826
< iNumLocalMin++;
---
> (*iNumLocalMin)++;
820,821c832,833
< if (piLocalMinPos == NULL)
< piLocalMinPos = (int*) malloc(sizeof(int) *iNumLocalMin);
---
> if (*ppiLocalMinPos == NULL)
> *ppiLocalMinPos = (int*) malloc(sizeof(int) * (*iNumLocalMin));
823c835
< piLocalMinPos = (int*) realloc(piLocalMinPos, sizeof(int) *iNumLocalMin);
---
> *ppiLocalMinPos = (int*) realloc(*ppiLocalMinPos, sizeof(int) * (*iNumLocalMin));
825c837
< if (piLocalMinPos == NULL)
---
> if (*ppiLocalMinPos == NULL)
828c840
< piLocalMinPos[iNumLocalMin-1] = i;
---
> *ppiLocalMinPos[(*iNumLocalMin)-1] = i;
833,834c845,846
< _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,838c849,850
< *ppexLocalMax = initLocalExtrema(piLocalMaxPos, iNumLocalMax);
< *ppexLocalMin = initLocalExtrema(piLocalMinPos, iNumLocalMin);
---
> *ppexLocalMax = pexLocalMax;
> *ppexLocalMin = pexLocalMin;
898,908c910,913
< 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];
924a930
> histogram->pdBinValues = NULL; // FIXME: This should be added in the final version
1000,1002c1006,1008
< 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;
1014c1020
< MMSignal *signal = createSignalFromDoubleArray(iOutLen, pdOut);
---
> // Initialize the features of the signal
1028,1029c1034,1036
< double *pdValues = NULL;
< pdValues = (double*) malloc(sizeof(double) * iLinenum);
---
> MMSignal *signal = createSignalWithDefault(iLinenum, 1);
> double *pdValues = signal->pdValues;
>
1034d1040
< pdValues[i] = 1;
1036c1042
< pdValues[j] = pdValues[j] + pdValues[j-1];
---
> pdValues[j] += pdValues[j-1];
1040d1045
< MMSignal *signal = createSignalFromDoubleArray(iLinenum, pdValues);
1042,1043d1046
<
< free(pdValues);