MCPcopy Create free account
hub / github.com/Derious/cuMPC / compute_with_lut

Method compute_with_lut

test/test_CORE/test_exp.cpp:69–89  ·  view source on GitHub ↗

使用查找表的量化指数计算

Source from the content-addressed store, hash-verified

67
68 // 使用查找表的量化指数计算
69 static uint8_t compute_with_lut(float x) {
70 // 输入截断
71 x = std::min(std::max(x, kXMin), kXMax);
72
73 // 在查找表中找到相邻的两个点
74 for (size_t i = 0; i < kTableSize - 1; ++i) {
75 if (x >= kLookupTable[i].x && x <= kLookupTable[i + 1].x) {
76 // 线性插值
77 float x0 = kLookupTable[i].x;
78 float x1 = kLookupTable[i + 1].x;
79 float q0 = kLookupTable[i].q;
80 float q1 = kLookupTable[i + 1].q;
81
82 float t = (x - x0) / (x1 - x0);
83 return static_cast<uint8_t>(std::round(q0 + t * (q1 - q0)));
84 }
85 }
86
87 // 如果x超出范围,返回边界值
88 return (x <= kXMin) ? kLookupTable[0].q : kLookupTable[kTableSize - 1].q;
89 }
90
91 // 使用直接计算的量化指数
92 static uint8_t compute_direct(float x) {

Callers

nothing calls this directly

Calls 1

roundFunction · 0.50

Tested by

no test coverage detected