view mupdf-source/thirdparty/tesseract/src/lstm/generate_lut.py @ 38:8934ac156ef5

Allow to build with the PyPI package "clang" instead of "libclang". 1. It seems to be maintained. 2. In the FreeBSD base system there is no pre-built libclang.so. If you need this library you have to install llvm from ports additionally. 2. On FreeBSD there is no pre-built wheel "libclang" with a packaged libclang.so.
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 23 Sep 2025 10:27:15 +0200
parents b50eed0cc0ef
children
line wrap: on
line source

#!/usr/bin/env python3

# Create C/C++ code for two lookup tables.

import math

# kTableSize and kScaleFactor must match the values in functions.h.

# Size of static tables.
kTableSize = 4096
# Scale factor for float arg to int index.
kScaleFactor = 256.0

print("// Generated code with lookup tables (see generate_lut.py)")
print('#include "functions.h"')
print("namespace tesseract {")

print("const TFloat TanhTable[] = {")
for i in range(kTableSize):
    print("    %a," % math.tanh(i / kScaleFactor))
print("};")

print("const TFloat LogisticTable[] = {")
for i in range(kTableSize):
    print("    %a," % (1 / (1 + math.exp(-i / kScaleFactor))))
print("};")
print("} // namespace tesseract.")