Skip to content

Commit 534dd36

Browse files
danmcleranclaude
andcommitted
Add lookup-table unit tests for activation tables and getValue
Closes a high-leverage coverage gap: every fixed-point activation in the library reads from precomputed sigmoid/tanh/exp/log/sin/cos tables, but none of them were directly tested. New suite has three layers: - Branch coverage on LookupTable<Q>::getValue (clamp lo/hi, knot match, flat-region short-circuit, linear interpolation). - Bit-exact verification that each table entry matches the generator output for Q8.8 and Q16.16 across all six functions, catching silent corruption of lookupTables.cpp. - Structural invariants (monotonicity, range, sigmoid complement, tanh antisymmetry, sin oddness, cos evenness, endpoint values) and an end-to-end accuracy sweep against std:: math with tolerances derived from the LSB plus the linear-interpolation chord-error bound. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 63eeaf1 commit 534dd36

3 files changed

Lines changed: 484 additions & 0 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ check :
55
cd unit_test/nn && make clean && make && make run && cd -
66
cd unit_test/qformat && make clean && make && make run && cd -
77
cd unit_test/qlearn && make clean && make && make run && cd -
8+
cd unit_test/lookuptable && make clean && make && make run && cd -
89
cd examples/xor && make clean && make && make release && cd -
910
cd examples/maze && make clean && make && make release && cd -
1011
cd examples/dqn_maze && make clean && make && make release && cd -

unit_test/lookuptable/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Simple Makefile for the lookup-table unit tests.
2+
# Compiles cpp/lookupTables.cpp with TINYMIND_USE_* macros enabling every
3+
# (function, Q-format) pair the test exercises.
4+
MKDIR=mkdir -p ./output
5+
CC=g++
6+
WARN=-Wall -Wextra -Werror -Wpedantic
7+
SOURCES=lookuptable_unit_test.cpp ../../cpp/lookupTables.cpp
8+
DEFINES=-DTINYMIND_ENABLE_OSTREAMS=1 \
9+
-DTINYMIND_USE_SIGMOID_8_8=1 -DTINYMIND_USE_SIGMOID_16_16=1 \
10+
-DTINYMIND_USE_TANH_8_8=1 -DTINYMIND_USE_TANH_16_16=1 \
11+
-DTINYMIND_USE_EXP_8_8=1 -DTINYMIND_USE_EXP_16_16=1 \
12+
-DTINYMIND_USE_LOG_8_8=1 -DTINYMIND_USE_LOG_16_16=1 \
13+
-DTINYMIND_USE_SIN_8_8=1 -DTINYMIND_USE_SIN_16_16=1 \
14+
-DTINYMIND_USE_COS_8_8=1 -DTINYMIND_USE_COS_16_16=1
15+
INCLUDES=-I../../include -I../../cpp -I${BOOST_HOME}
16+
OUT=./output/lookuptable_unit_test
17+
18+
lookuptable_unit_test:
19+
$(MKDIR)
20+
$(CC) -g $(WARN) -o $(OUT) $(SOURCES) $(DEFINES) $(INCLUDES)
21+
22+
run:
23+
cd ./output && ./lookuptable_unit_test && cd ../
24+
25+
clean:
26+
rm -f ./output/*

0 commit comments

Comments
 (0)