Crates.io | tansig-lut |
lib.rs | tansig-lut |
version | |
source | src |
created_at | 2025-03-18 13:48:21.8393+00 |
updated_at | 2025-03-20 14:54:52.988944+00 |
description | CLI generation of a Look Up Tables for tansig function with fixed-point arithmetic |
homepage | |
repository | https://gitlab.com/filipriec/tansig-lut |
max_upload_size | |
id | 1596587 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
This tool generates lookup tables (LUT) for the hyperbolic tangent sigmoid (tansig
) transfer function, optimized for fixed-point arithmetic on microcontrollers. The generated LUT provides a fast approximation of the tansig
function, making it ideal for resource-constrained environments.
0
as the starting point.tanh(-x) = -tanh(x)
to minimize storage.cargo build --release
# Build, test, and generate the default LUT
make
# Just build the project
make build
The executable will be available at target/release/tansig-lut
.
tansig-lut <SCALING_FACTOR> [OPTIONS]
tansig-lut 512
tansig-lut 1024 --output my_lut
tansig-lut 256
<SCALING_FACTOR>
: Power-of-2 scaling factor for fixed-point conversion (≤ 32767 in int16
).-o, --output <DIR>
: Output directory (default: writes header to stdout).-h, --help
: Print help information.-v, --version
: Print version information.The Makefile provides convenient targets for common operations:
make # Build project, run tests, and generate default LUT
make build # Build the project
make test # Run the test suite
make run # Generate LUT with default parameters (scale=64)
make plot # Create plot from generated data
make clean # Remove generated files
make custom SCALE=256 # Generate with custom scaling factor
When using --output <DIR>
, the tool generates:
tansig_lut.h
- C header file containing:
FIXED_POINT_SCALE
and FIXED_POINT_SHIFT
defines.LUT_SIZE
constant.tansig_lut
array.output_float.data
- Floating-point (x, tansig(x))
pairs.
output_fixed.data
- Fixed-point (x, scaled_tansig(x))
pairs.
0
.fixed_value = round(tansig(x) × scaling_factor)
int16_t
for microcontroller compatibility.FIXED_POINT_SHIFT
(number of right shifts = log2(scale)
).The hyperbolic tangent sigmoid transfer function is defined as:
tansig(n) = \frac{2}{1 + e^{-2n}} - 1
(-∞, ∞)
(-1, 1)
tansig(-x) = -tansig(x)
The test suite verifies:
tansig
implementation accuracy.Run tests with:
cargo test
[1] MATLAB Neural Network Toolbox Transfer Functions: ResearchGate Link