comparison mupdf-source/thirdparty/tesseract/src/lstm/generate_lut.py @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 #!/usr/bin/env python3
2
3 # Create C/C++ code for two lookup tables.
4
5 import math
6
7 # kTableSize and kScaleFactor must match the values in functions.h.
8
9 # Size of static tables.
10 kTableSize = 4096
11 # Scale factor for float arg to int index.
12 kScaleFactor = 256.0
13
14 print("// Generated code with lookup tables (see generate_lut.py)")
15 print('#include "functions.h"')
16 print("namespace tesseract {")
17
18 print("const TFloat TanhTable[] = {")
19 for i in range(kTableSize):
20 print(" %a," % math.tanh(i / kScaleFactor))
21 print("};")
22
23 print("const TFloat LogisticTable[] = {")
24 for i in range(kTableSize):
25 print(" %a," % (1 / (1 + math.exp(-i / kScaleFactor))))
26 print("};")
27 print("} // namespace tesseract.")