tables support non-integer-scaled scaled_channel (#3708)

* support dividers

* float

* format
This commit is contained in:
Matthew Kennedy 2021-12-20 21:59:07 -08:00 committed by GitHub
parent 7b0179aaa3
commit b6a8bed429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 29 deletions

View File

@ -30,7 +30,7 @@ class Map3D : public ValueProvider3D {
public: public:
template <typename TValueInit, typename TRowInit, typename TColumnInit> template <typename TValueInit, typename TRowInit, typename TColumnInit>
void init(TValueInit (&table)[TRowNum][TColNum], void init(TValueInit (&table)[TRowNum][TColNum],
const TRowInit (&rowBins)[TRowNum], const TColumnInit (&columnBins)[TColNum]) { const TRowInit (&rowBins)[TRowNum], const TColumnInit (&columnBins)[TColNum]) {
// This splits out here so that we don't need one overload of init per possible combination of table/rows/columns types/dimensions // This splits out here so that we don't need one overload of init per possible combination of table/rows/columns types/dimensions
// Overload resolution figures out the correct versions of the functions below to call, some of which have assertions about what's allowed // Overload resolution figures out the correct versions of the functions below to call, some of which have assertions about what's allowed
initValues(table); initValues(table);
@ -44,19 +44,19 @@ public:
return 0; return 0;
} }
return interpolate3d(*m_values, return interpolate3d(*m_values,
*m_rowBins, yRow * m_rowMult, *m_rowBins, yRow * m_rowMult,
*m_columnBins, xColumn * m_colMult) * *m_columnBins, xColumn * m_colMult) *
TValueMultiplier::asFloat(); TValueMultiplier::asFloat();
} }
void setAll(TValue value) { void setAll(TValue value) {
efiAssertVoid(CUSTOM_ERR_6573, m_values, "map not initialized"); efiAssertVoid(CUSTOM_ERR_6573, m_values, "map not initialized");
for (size_t r = 0; r < TRowNum; r++) { for (size_t r = 0; r < TRowNum; r++) {
for (size_t c = 0; c < TColNum; c++) { for (size_t c = 0; c < TColNum; c++) {
(*m_values)[r][c] = value / TValueMultiplier::asFloat(); (*m_values)[r][c] = value / TValueMultiplier::asFloat();
} }
} }
} }
@ -69,28 +69,28 @@ private:
m_values = reinterpret_cast<TValue (*)[TRowNum][TColNum]>(&table); m_values = reinterpret_cast<TValue (*)[TRowNum][TColNum]>(&table);
} }
void initValues(TValue (&table)[TRowNum][TColNum]) { void initValues(TValue (&table)[TRowNum][TColNum]) {
m_values = &table; m_values = &table;
} }
template <int TRowMult> template <int TRowMult, int TRowDiv>
void initRows(const scaled_channel<TRow, TRowMult> (&rowBins)[TRowNum]) { void initRows(const scaled_channel<TRow, TRowMult, TRowDiv> (&rowBins)[TRowNum]) {
m_rowBins = reinterpret_cast<const TRow (*)[TRowNum]>(&rowBins); m_rowBins = reinterpret_cast<const TRow (*)[TRowNum]>(&rowBins);
m_rowMult = TRowMult; m_rowMult = (float)TRowMult / TRowDiv;
} }
void initRows(const TRow (&rowBins)[TRowNum]) { void initRows(const TRow (&rowBins)[TRowNum]) {
m_rowBins = &rowBins; m_rowBins = &rowBins;
m_rowMult = 1; m_rowMult = 1;
} }
template <int TColMult> template <int TColMult, int TColDiv>
void initCols(const scaled_channel<TColumn, TColMult> (&columnBins)[TColNum]) { void initCols(const scaled_channel<TColumn, TColMult, TColDiv> (&columnBins)[TColNum]) {
m_columnBins = reinterpret_cast<const TColumn (*)[TColNum]>(&columnBins); m_columnBins = reinterpret_cast<const TColumn (*)[TColNum]>(&columnBins);
m_colMult = TColMult; m_colMult = (float)TColMult / TColDiv;
} }
void initCols(const TColumn (&columnBins)[TColNum]) { void initCols(const TColumn (&columnBins)[TColNum]) {
m_columnBins = &columnBins; m_columnBins = &columnBins;
m_colMult = 1; m_colMult = 1;
} }
@ -108,10 +108,10 @@ private:
} }
// TODO: should be const // TODO: should be const
/*const*/ TValue (*m_values)[TRowNum][TColNum] = nullptr; /*const*/ TValue (*m_values)[TRowNum][TColNum] = nullptr;
const TRow (*m_rowBins)[TRowNum] = nullptr; const TRow (*m_rowBins)[TRowNum] = nullptr;
const TColumn (*m_columnBins)[TColNum] = nullptr; const TColumn (*m_columnBins)[TColNum] = nullptr;
float m_rowMult = 1; float m_rowMult = 1;
float m_colMult = 1; float m_colMult = 1;

View File

@ -45,20 +45,17 @@ static float getValue(float rpm, float maf) {
float result3 = x3.getValue(rpm, maf); float result3 = x3.getValue(rpm, maf);
EXPECT_NEAR_M4(result1, result3); EXPECT_NEAR_M4(result1, result3);
/*
are we missing something in Map3D?
Map3D<5, 4, float, uint8_t, float> x4; Map3D<5, 4, float, uint8_t, float> x4;
x4.init(map, mafBins, rpmBinsScaledByte); x4.init(map, mafBins, rpmBinsScaledByte);
float result4 = x4.getValue(rpm, maf); float result4 = x4.getValue(rpm, maf);
EXPECT_NEAR_M4(result1, result4); EXPECT_NEAR_M4(result1, result4);
*/
float result4 = interpolate3d( float result5 = interpolate3d(
map, map,
mafBinsScaledInt, maf, mafBinsScaledInt, maf,
rpmBinsScaledByte, rpm rpmBinsScaledByte, rpm
); );
EXPECT_NEAR_M4(result1, result4); EXPECT_NEAR_M4(result1, result5);
return result1; return result1;
} }