tesseract v5.3.3.20231005
generate_lut.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# Create C/C++ code for two lookup tables.
4
5import math
6
7# kTableSize and kScaleFactor must match the values in functions.h.
8
9# Size of static tables.
10kTableSize = 4096
11# Scale factor for float arg to int index.
12kScaleFactor = 256.0
13
14print("// Generated code with lookup tables (see generate_lut.py)")
15print('#include "functions.h"')
16print("namespace tesseract {")
17
18print("const TFloat TanhTable[] = {")
19for i in range(kTableSize):
20 print(" %a," % math.tanh(i / kScaleFactor))
21print("};")
22
23print("const TFloat LogisticTable[] = {")
24for i in range(kTableSize):
25 print(" %a," % (1 / (1 + math.exp(-i / kScaleFactor))))
26print("};")
27print("} // namespace tesseract.")