Repository navigation
Plain C API: tld.h is the source, ai module inside, ai_nearest - #5
Merged
Merged
Conversation
No public macro returns, jumps or exits any more. RUN, ASSERT, ERROR_MSG and the MMALLOC family leave the public API (the implementation keeps them as TLD__RUN, TLD__ASSERT, ...); tld_error prints and does nothing else, and tld_galloc is an expression that returns TLD_OK or TLD_FAIL. OK/FAIL become TLD_OK/TLD_FAIL, the *_MSG macros become tld_log, tld_warn, tld_debug, tld_section, tld_kv and tld_success, and galloc/gfree become tld_galloc/tld_gfree. - names: fails when a public macro returns, jumps or exits, even through a macro it uses - misuse-rejected: an unchecked tld_galloc is rejected with -Wall -Werror - tests keep their jumping checks as TEST_RUN, TEST_ASSERT and TEST_FAIL in tests/test.h - tools/migrate.py renames the old names and rewrites each jumping macro to plain C that keeps the program's ERROR: labels - tld_doc.h: the rule for names without '_' had nothing left to apply to and is removed; the corpus is regenerated (180 records) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
tld.h was generated from the module files in src/ by tools/amalgamate.py, and a test checked that the two agreed. It is now the file that is edited. The code is the same: the preprocessed text of the new tld.h equals that of the generated one, apart from line numbers. - tld.h reads top to bottom: the top comment, the declarations of every module, then the implementation in the same order, each module under a "---- name ----" banner in both halves; one include block per half - json types, json memory and json are one module, json; stats, quantile and auc are one module, stats (17 modules, no symbol changed) - new MODULES section in the top comment; docs-current fails when it and the banners differ - tld-dev compiles tld.h once and brings its directory as include directory - unit-hash and regress-sort-cmp define TLD_IMPLEMENTATION themselves - tools/migrate.py turns an include of a module header into tld.h - single-header-current is removed (74 tests) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
One header and one implementation macro: TLD_IMPLEMENTATION compiles
everything, AI_IMPLEMENTATION is gone, and tld_ai.h and docs/tld_ai.md are
removed. The names keep their prefix, ai_ and AI_.
- ai_defaults and ai_fill return TLD_OK or TLD_FAIL (was 0 or -1)
- AI_CHOICE and AI_SCALE define name_name(i) and name_count, so a program no
longer builds the label-name table itself
- TLD_VERSION "0.5.0" replaces AI_VERSION
- the ai module comes in 13 parts ("ai: embeddings", ...), the sections
tld_ai.h had; the manual and the corpus show a part as a module of its own
- the top comment of tld.h holds the sections of tld_ai.h's top comment
- docs/tld_card.md: the rules of tld.h on one page, generated from the top
comment and checked by docs-current
- the declarations for an implementation included after system headers are
removed with their test: tld.h comes first in its file
- names checks the ai module; its implementation-only macros are #undef'd
- tld_doc.h: the corpus covers one header (177 records)
- doc-examples runs the tld.h examples with the mock server; 73 tests
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Measured on 20,000 random unit vectors, the k-d tree beats comparing every point up to about 8 dimensions, is slower from 16 and visits every point at 768. A tree does not help with embeddings, and the header now says so. - kdtree: the module comment says the tree is for points of few dimensions and names ai_nearest for embeddings; the code is unchanged - ai_nearest computes the length of the query once instead of once per row - ai_cosine and ai_nearest add vectors of 32 or more floats in 32 partial sums of floats: one query against 20,000 vectors of 768 floats takes 1.7 ms (was 16 ms); shorter vectors keep the sum in double - the values are within 1e-6 of the sums in double they replace, never outside [-1, 1], and a score of ai_nearest equals ai_cosine of that row - new test ai-nearest: both functions against sums in double on 16 vector lengths from 1 to 4096 (74 tests) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
TimoLassmann
added a commit
that referenced
this pull request
Nov 29, 2026
…ers once Both workflows failed on main after #5. - misuse-rejected failed on every gcc job: check.sh used -fsyntax-only, and gcc reports an unused warn_unused_result value only when it generates code, so warn_galloc_unchecked.c compiled. check.sh now compiles each case with -c -o /dev/null; tld_galloc itself was right. - oom-tld timed out under MemorySanitizer: with the ai module in tld.h the manual has 177 entries, and tld__doc_entry allocated 4 string buffers per entry, so the doc_manual sweep grew from 360 to 1439 allocations, each rerunning the whole manual (54 s under MSan locally, was 2.9 s). tld__doc_entry now takes work buffers that tld_doc_manual and tld__doc_render allocate once: 26 allocations, 0.7 s. The text is unchanged (docs-unchanged passes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merges feature/plain-c-api into main.
🤖 Generated with Claude Code