Skip to content

feat: shape-agnostic graph with DimExpr (#651)#653

Merged
shinaoka merged 12 commits intomainfrom
codex/dimexpr-v2
Apr 7, 2026
Merged

feat: shape-agnostic graph with DimExpr (#651)#653
shinaoka merged 12 commits intomainfrom
codex/dimexpr-v2

Conversation

@shinaoka
Copy link
Copy Markdown
Member

@shinaoka shinaoka commented Apr 7, 2026

Summary

  • Uniformly convert all Vec<usize> shape fields in StdTensorOp to Vec<DimExpr>, enabling graph reuse across varying tensor sizes (e.g., bond dimension changes in DMRG/ALS)
  • Add DimExpr type with eval, remap, input_shape, and arithmetic helpers
  • Add SymDim user-facing API with operator overloading (sym_size, reshape_sym)
  • Change TracedTensor.shape to TracedTensor.rank (rank-only tracking at trace time)
  • Update all AD rules (structural, contraction, linalg) to use DimExpr::remap_all for backward ops
  • DimExpr evaluation deferred to execution time via resolve_tensor_shape_exprs

Known Limitations

  • Linalg AD rules (const_dim) require concrete DimExpr::Const values; symbolic InputDim will panic (documented)
  • shape_hint retained in TracedTensor for broadcast/linalg trace-time shape computation

Test plan

  • All existing tests pass (cargo test --workspace --release)
  • Oracle replay tests pass
  • New DimExpr unit tests (eval, remap, input_shape, hash/eq)
  • New SymDim integration tests (sym_size, reshape_sym, mixed arithmetic)
  • Graph reuse test: same graph executed with [2,3] and [4,5] tensors
  • cargo fmt --all --check
  • cargo doc --workspace --no-deps

Closes #651

🤖 Generated with Claude Code

@shinaoka shinaoka enabled auto-merge (squash) April 7, 2026 10:18
Add tests for Sub, Div, usize-lhs operators, and min/max methods
to bring sym_dim.rs coverage above 80%.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@shinaoka shinaoka merged commit c7589e3 into main Apr 7, 2026
5 checks passed
@shinaoka shinaoka deleted the codex/dimexpr-v2 branch April 7, 2026 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

design: shape-agnostic graph + N-ary einsum op for tensor network workloads

1 participant