supertensor: shape-aware tensor figure toolkit
Extracted from the tensor-formula-viz skill and rebuilt around the idea that the geometry rules should be enforced by construction rather than restated as prose an agent has to remember. - assets/supertensor.sty: faces, stacks, index faces, shared caption lanes, meaning box, signature. Macros take a declared axis and a declared role, so equal shapes get equal edges, a x a is square, a transpose swaps the face, and contracted axes share an edge length -- without any manual alignment. - scripts/preflight.sh: decide the TikZ/CJK path before drawing. - scripts/build.sh: compile and fail on silent corruption (missing CJK glyphs, overfull boxes, undeclared roles), then export pdf/svg/png/thumb. - scripts/test.sh: build every figure as a regression test for the package. - examples/: three golden figures (TP-FFN, causal MHA, MoE top-k gather) plus an anti-pattern gallery of figures that compile cleanly and still lie. - SKILL.md + references/: lean entry point, details loaded on demand.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
\documentclass[border=8pt]{standalone}
|
||||
\usepackage[cjk]{supertensor}
|
||||
|
||||
\stsetrole{x}{stTeal}
|
||||
\stsetrole{w}{stOrange}
|
||||
\stsetrole{h}{stViolet}
|
||||
|
||||
\stdim{m}{6}
|
||||
\stdim{k}{4}
|
||||
\stdim{n}{5}
|
||||
|
||||
\begin{document}
|
||||
\begin{tikzpicture}
|
||||
\stface[role=x, pattern=dense, bracket=true]{X}{(0,0)}{m}{k}
|
||||
\stcaption{X}{$\mathbf X$}{$m\times k$}
|
||||
|
||||
\node[st op, right=4mm of X] (mul) {$\times$};
|
||||
|
||||
\stface[role=w, pattern=dense, bracket=true]{W}{($(mul)+(1.6,0)$)}{k}{n}
|
||||
\stcaption{W}{$\mathbf W$}{$k\times n$}
|
||||
|
||||
\node[st op, right=4mm of W] (eq) {$=$};
|
||||
|
||||
\stface[role=h, pattern=dense, bracket=true]{H}{($(eq)+(1.8,0)$)}{m}{n}
|
||||
\stcaption{H}{$\mathbf H$}{$m\times n$}
|
||||
|
||||
\ststack[role=x, pattern=causal]{S}{($(H)+(3.4,0)$)}{k}{k}{3}
|
||||
\stcaption{S}{$\mathbf S$}{$b\times k\times k$}
|
||||
|
||||
\node[inner sep=0pt, fit=(X)(S)(H-shape)] (all) {};
|
||||
\stmeaningbox{mb}{13cm}{all}
|
||||
{$m$ 行、$k$ 收缩维、$n$ 输出维}
|
||||
{$\mathbf X$ 激活值,$\mathbf W$ 权重,$\mathbf S$ 因果分数}
|
||||
{$(m\times k)(k\times n)\rightarrow(m\times n)$}
|
||||
\stsignature{Smoke test}{mb}
|
||||
\end{tikzpicture}
|
||||
\end{document}
|
||||
Reference in New Issue
Block a user