Demo: layout-aware relationalizer for scipy.sparse matrices#116
Open
sidprasad wants to merge 1 commit into
Open
Demo: layout-aware relationalizer for scipy.sparse matrices#116sidprasad wants to merge 1 commit into
sidprasad wants to merge 1 commit into
Conversation
Adds a demo + reusable relationalizer that visualizes the *physical* storage layout of sparse matrices (COO / CSR / CSC) and overlays the path an element access walks through it — "which indices do I touch across all the arrays to read A[i, j]?" - demos/sparse_layout.py: a priority-100 relationalizer for scipy.sparse. layout(A) draws the indptr/indices/data arrays; access(A, i, j) overlays the lookup (bound / scan / hit). Fixes diagram() on a raw sparse matrix, which otherwise RecursionErrors through the generic relationalizer (numpy arrays expose endlessly many array-valued attributes). - demos/06-sparse-matrices.ipynb: the narrative — the crash, COO triplets, CSR compression, the access path, and CSC (a different layout touches different indices). Directives are applied per-object, not as static class decorators: spytial-core rejects a selector naming a type with zero atoms, so a COO diagram can't carry CSR's group rules and vice versa. Verified each format's access against the dense ground truth and confirmed the diagrams render without error. Co-Authored-By: Claude Opus 4.8 <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.
What
A demo + reusable relationalizer that visualizes the physical storage layout of
scipy.sparsematrices (COO / CSR / CSC) and overlays the path an element-access walks through it — answering Rachit's question: which indices do I have to touch across all the data structures to readA[i, j]?demos/sparse_layout.py— a priority-100 relationalizer forscipy.sparse.layout(A)draws theindptr[] / indices[] / data[]arrays (CSR/CSC) or therow[] / col[] / data[]triplets (COO).access(A, i, j)overlays the lookup, colored by step: 🟠bound(read the two slice pointers) · ⚪scan(columns skipped) · 🟢hit(the match and its value).demos/06-sparse-matrices.ipynb— the narrative: the crash → COO triplets → CSR compression → the access path → CSC (a different layout touches different indices).Why
diagram(A)on a raw sparse matrix todayRecursionErrors: the generic relationalizer walks attributes withinspect.getmembers, and numpy arrays expose endlessly many array-valued properties (.T,.real, …). The interesting thing to see isn't the logical grid anyway — it's the array bundle and what an access costs.Notes
grouprules and vice versa (_decorated()builds the graph once and attaches only the rules whose types/relations are present).numpy+scipy(like the z3/protobuf demos, these are demo-only deps not inrequirements.txt).🤖 Generated with Claude Code