Project Templates์ถœ์ฒ˜: Show HN์กฐํšŒ์ˆ˜ 8

Show HN: ShapeGuard โ€“ Shape Contracts for NumPy and Jax

By jayendra13
2026๋…„ 2์›” 9์ผ
**Show HN: ShapeGuard โ€“ Shape Contracts for NumPy and Jax**

I built ShapeGuard because shape errors in numerical code are uniquely painful. They're silent (wrong shapes often produce garbage instead of crashing), late (errors surface deep in XLA, not where the bug is), and cryptic (shapes (3,4) and (5,3) not aligned โ€” but why should they match?). ShapeGuard lets you declare shape contracts on functions using symbolic dimensions: from shapeguard import Dim, expects, ensures n, m, k = Dim("n"), Dim("m"), Dim("k") @expects(a=(n, m), b=(m, k)) @ensures(result=(n, k)) def matmul(a, b): return a @ b When shapes don't match, the error traces bindings back to their source: ShapeGuardError: function: matmul argument: b expected: (m, k) actual: (5, 7) reason: dimension 'm' bound to 4 from a.shape[1], but got 5 from b.shape[0] bindings: {n=3 (from a[0]), m=4 (from a[1])} The key idea is unification โ€” the same Dim object used across arguments must resolve to the same integer. ShapeGuard tracks where each binding came from, so conflicts pinpoint the exact source. What it does: - @expects / @ensures / @contract โ€” input and output shape validation - Symbolic Dim with cross-argument unification - Batch() dims and .....

---

**[devsupporter ํ•ด์„ค]**

์ด ๊ธฐ์‚ฌ๋Š” Show HN์—์„œ ์ œ๊ณตํ•˜๋Š” ์ตœ์‹  ๊ฐœ๋ฐœ ๋™ํ–ฅ์ž…๋‹ˆ๋‹ค. ๊ด€๋ จ ๋„๊ตฌ๋‚˜ ๊ธฐ์ˆ ์— ๋Œ€ํ•ด ๋” ์•Œ์•„๋ณด์‹œ๋ ค๋ฉด ์›๋ณธ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.