Repository navigation
Conversation
slot_into_containers scored every token against every cell in pure Python, building a Rect and a dict for each pair and sorting each token's scores to find the best one. Compute the overlaps with numpy in chunks of at most ~1M pairs instead, so temporary memory stays linear in the cell count. structure_to_cells on a 120x12 table with 8,000 tokens drops from 11.9s to 0.15s. Assignments, scores and score order match the Rect implementation for Python and float64/int64 coordinates, including first-container tie breaking, zero-area containers holding every package, and zero-area packages going unscored. float32 coordinates are now scored in float64 and returned as Python floats. Co-authored-by: wtfyd-agent[bot] <328989958+wtfyd-agent[bot]@users.noreply.github.com>
This was referenced Oct 24, 2026
Contributor
Author
|
Combined effect of #530, #531, #532 and #533 merged together onto
|
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.
Summary
slot_into_containersscored every token against every cell in pure Python, building a newRectand a dict for each pair and fully sorting each token's scores just to find the best one.structure_to_cellscalls it twice per table, andrefine_rows/refine_columnscall it again throughnms_by_containment. On large tables it accounts for ~99% of table postprocessing time.This computes the overlaps with numpy in chunks of at most ~1M token-cell pairs, so temporary memory stays proportional to the number of cells rather than tokens × cells, the same way #521/#522 bound memory.
Overlaps with #527, which rewrites the same function. #527 keeps the per-pair Python loop and picks the first maximum in one pass instead of sorting. This PR vectorizes the pair scoring itself. Only one of the two should merge.
Performance
structure_to_cellson synthetic tables:Behavior preserved
For Python
int/floatand NumPyfloat64/int64coordinates the output is unchanged: the same assignments, scores and score order. That includes the edge-case behavior ofRect.intersect/Rect.get_area:1.0(Rect.intersectreplaces a zero-area self with the other rect).argmaxmatches the stable descending sort).floats.Known difference: NumPy
float32coordinates are now scored in float64 and returned as Pythonfloats instead ofnp.float32. In 2,000 random float32 cases no assignment changed, but a score that lands exactly onoverlap_thresholdcould in principle resolve differently.Verification
test_unstructured_inference/models/test_slot_into_containers.py:Rectreference across chunk sizesmake test: 402 passed, 1 skipped.ruff check/ruff format --checkclean.Version bumped to 1.6.17 with a CHANGELOG entry.