auto-sync
This commit is contained in:
parent
415c273138
commit
37e4721ce5
|
@ -23,7 +23,7 @@ int needInterpolationLogging = true;
|
||||||
|
|
||||||
Logging * logger;
|
Logging * logger;
|
||||||
|
|
||||||
#if BINARY_PERF
|
#if BINARY_PERF && ! EFI_UNIT_TEST
|
||||||
|
|
||||||
#define COUNT 10000
|
#define COUNT 10000
|
||||||
|
|
||||||
|
@ -207,10 +207,12 @@ float interpolate2d(float value, float bin[], float values[], int size) {
|
||||||
return interpolateMsg("2d", bin[index], values[index], bin[index + 1], values[index + 1], value);
|
return interpolateMsg("2d", bin[index], values[index], bin[index + 1], values[index + 1], value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef float (*getTableValue_t)(int x, int y, void *table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Two-dimensional table lookup with linear interpolation
|
* @brief Two-dimensional table lookup with linear interpolation
|
||||||
*/
|
*/
|
||||||
float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, float* map[]) {
|
float interpolate3d_g(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, void* map, getTableValue_t getTableValue) {
|
||||||
if (cisnan(x)) {
|
if (cisnan(x)) {
|
||||||
warning(OBD_PCM_Processor_Fault, "%f: x is NaN in interpolate3d", x);
|
warning(OBD_PCM_Processor_Fault, "%f: x is NaN in interpolate3d", x);
|
||||||
return NAN;
|
return NAN;
|
||||||
|
@ -231,7 +233,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
if (needInterpolationLogging)
|
if (needInterpolationLogging)
|
||||||
printf("X and Y are smaller than smallest cell in table: %d\r\n", xIndex);
|
printf("X and Y are smaller than smallest cell in table: %d\r\n", xIndex);
|
||||||
#endif
|
#endif
|
||||||
return map[0][0];
|
return getTableValue(0, 0, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xIndex < 0) {
|
if (xIndex < 0) {
|
||||||
|
@ -240,11 +242,11 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
printf("X is smaller than smallest cell in table: %dr\n", xIndex);
|
printf("X is smaller than smallest cell in table: %dr\n", xIndex);
|
||||||
#endif
|
#endif
|
||||||
if (yIndex == yBinSize - 1)
|
if (yIndex == yBinSize - 1)
|
||||||
return map[0][yIndex];
|
return getTableValue(0, yIndex, map);
|
||||||
float keyMin = yBin[yIndex];
|
float keyMin = yBin[yIndex];
|
||||||
float keyMax = yBin[yIndex + 1];
|
float keyMax = yBin[yIndex + 1];
|
||||||
float rpmMinValue = map[0][yIndex];
|
float rpmMinValue = getTableValue(0, yIndex, map);
|
||||||
float rpmMaxValue = map[0][yIndex + 1];
|
float rpmMaxValue = getTableValue(0, yIndex + 1, map);
|
||||||
|
|
||||||
return interpolateMsg("3d", keyMin, rpmMinValue, keyMax, rpmMaxValue, y);
|
return interpolateMsg("3d", keyMin, rpmMinValue, keyMax, rpmMaxValue, y);
|
||||||
}
|
}
|
||||||
|
@ -255,7 +257,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
printf("Y is smaller than smallest cell in table: %d\r\n", yIndex);
|
printf("Y is smaller than smallest cell in table: %d\r\n", yIndex);
|
||||||
#endif
|
#endif
|
||||||
// no interpolation should be fine here.
|
// no interpolation should be fine here.
|
||||||
return map[xIndex][0];
|
return getTableValue(xIndex, 0, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xIndex == xBinSize - 1 && yIndex == yBinSize - 1) {
|
if (xIndex == xBinSize - 1 && yIndex == yBinSize - 1) {
|
||||||
|
@ -263,7 +265,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
if (needInterpolationLogging)
|
if (needInterpolationLogging)
|
||||||
printf("X and Y are larger than largest cell in table: %d %d\r\n", xIndex, yIndex);
|
printf("X and Y are larger than largest cell in table: %d %d\r\n", xIndex, yIndex);
|
||||||
#endif
|
#endif
|
||||||
return map[xBinSize - 1][yBinSize - 1];
|
return getTableValue(xBinSize - 1, yBinSize - 1, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xIndex == xBinSize - 1) {
|
if (xIndex == xBinSize - 1) {
|
||||||
|
@ -272,7 +274,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
printf("TODO BETTER LOGGING x overflow %d\r\n", yIndex);
|
printf("TODO BETTER LOGGING x overflow %d\r\n", yIndex);
|
||||||
#endif
|
#endif
|
||||||
// todo: implement better handling - y interpolation
|
// todo: implement better handling - y interpolation
|
||||||
return map[xBinSize - 1][yIndex];
|
return getTableValue(xBinSize - 1, yIndex, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yIndex == yBinSize - 1) {
|
if (yIndex == yBinSize - 1) {
|
||||||
|
@ -281,7 +283,7 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
printf("Y is larger than largest cell in table: %d\r\n", yIndex);
|
printf("Y is larger than largest cell in table: %d\r\n", yIndex);
|
||||||
#endif
|
#endif
|
||||||
// todo: implement better handling - x interpolation
|
// todo: implement better handling - x interpolation
|
||||||
return map[xIndex][yBinSize - 1];
|
return getTableValue(xIndex, yBinSize - 1, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -291,8 +293,8 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
|
|
||||||
float xMin = xBin[xIndex];
|
float xMin = xBin[xIndex];
|
||||||
float xMax = xBin[xIndex + 1];
|
float xMax = xBin[xIndex + 1];
|
||||||
float rpmMinKeyMinValue = map[xIndex][yIndex];
|
float rpmMinKeyMinValue = getTableValue(xIndex, yIndex, map);
|
||||||
float rpmMaxKeyMinValue = map[xIndex + 1][yIndex];
|
float rpmMaxKeyMinValue = getTableValue(xIndex + 1, yIndex, map);
|
||||||
|
|
||||||
float keyMinValue = interpolate(xMin, rpmMinKeyMinValue, xMax, rpmMaxKeyMinValue, x);
|
float keyMinValue = interpolate(xMin, rpmMinKeyMinValue, xMax, rpmMaxKeyMinValue, x);
|
||||||
|
|
||||||
|
@ -306,8 +308,8 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
int keyMaxIndex = yIndex + 1;
|
int keyMaxIndex = yIndex + 1;
|
||||||
float keyMin = yBin[yIndex];
|
float keyMin = yBin[yIndex];
|
||||||
float keyMax = yBin[keyMaxIndex];
|
float keyMax = yBin[keyMaxIndex];
|
||||||
float rpmMinKeyMaxValue = map[xIndex][keyMaxIndex];
|
float rpmMinKeyMaxValue = getTableValue(xIndex, keyMaxIndex, map);
|
||||||
float rpmMaxKeyMaxValue = map[rpmMaxIndex][keyMaxIndex];
|
float rpmMaxKeyMaxValue = getTableValue(rpmMaxIndex, keyMaxIndex, map);
|
||||||
|
|
||||||
float keyMaxValue = interpolateMsg("3d", xMin, rpmMinKeyMaxValue, xMax, rpmMaxKeyMaxValue, x);
|
float keyMaxValue = interpolateMsg("3d", xMin, rpmMinKeyMaxValue, xMax, rpmMaxKeyMaxValue, x);
|
||||||
|
|
||||||
|
@ -322,6 +324,17 @@ float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[],
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float getFloatTableValue(int x, int y, void* pointer) {
|
||||||
|
float** map = (float**)pointer;
|
||||||
|
return map[x][y];
|
||||||
|
}
|
||||||
|
|
||||||
|
float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, float* map[]) {
|
||||||
|
|
||||||
|
return interpolate3d_g(x, xBin, xBinSize, y, yBin, yBinSize, map, getFloatTableValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void setTableValue(float bins[], float values[], int size, float key, float value) {
|
void setTableValue(float bins[], float values[], int size, float key, float value) {
|
||||||
int index = findIndex(bins, size, key);
|
int index = findIndex(bins, size, key);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
|
|
Loading…
Reference in New Issue