Skip to content

feat: block tensor literal syntax [ta; tb], (ta, tb), [|ta; tb|]#450

Open
lukstafi wants to merge 4 commits intoahrefs:masterfrom
lukstafi:ludics/task-fe1c593d-s4/root
Open

feat: block tensor literal syntax [ta; tb], (ta, tb), [|ta; tb|]#450
lukstafi wants to merge 4 commits intoahrefs:masterfrom
lukstafi:ludics/task-fe1c593d-s4/root

Conversation

@lukstafi
Copy link
Copy Markdown
Collaborator

@lukstafi lukstafi commented Apr 15, 2026

Summary

  • Add block tensor literal syntax to %op PPX: [ta; tb] (output axis), (ta, tb) (input axis), [|ta; tb|] (batch axis)
  • Support nesting: [[ta; tb]; [tc; td]] constructs 2x2 block matrices
  • Disambiguation via first-leaf heuristic: numeric literal leaves -> ndarray constant, tensor expression leaves -> block tensor
  • Add regression tests for ndarray constants, tuple-in-apply preservation, and gradient flow
  • Fix stale "upcoming"/"planned" wording in 4 doc files

Test plan

  • dune build @check passes
  • dune runtest passes (only pre-existing unrelated failures)
  • 12 tests in test_block_tensor.ml covering: list/array/tuple block tensors, 3-way, nesting, single-element, 2-way and 3-way gradient flow, ndarray constant regressions, tuple-in-apply preservation
  • Existing test_concat_graph, test_concat_ppx, small_literal_tensor pass unchanged

🤖 Generated with Claude Code

@lukstafi lukstafi force-pushed the ludics/task-fe1c593d-s4/root branch from e36082a to f3ace5b Compare April 15, 2026 08:22
lukstafi and others added 2 commits April 15, 2026 10:23
Add syntactic sugar for constructing block tensors from component tensors
using OCaml list/tuple/array notation inside %op blocks. Lists stack along
a new leading output axis, tuples along input axis (top-level only), and
arrays along batch axis.

Implementation: first-leaf disambiguation (numeric → ndarray constant,
non-numeric → block tensor), two-step unsqueeze via einsum1 + concat.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add Concat-Concat element-wise unification case to row.ml's unify_dim,
allowing the shape solver to equate structurally-matching Concat dimensions
from inner block tensor results when used in outer block tensors.

Update test and docs to demonstrate direct nesting (2x2 block matrix).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lukstafi lukstafi force-pushed the ludics/task-fe1c593d-s4/root branch from f3ace5b to 0406075 Compare April 15, 2026 08:23
@lukstafi
Copy link
Copy Markdown
Collaborator Author

@codex review Focus on bugs, correctness issues, and edge cases. Do not check adherence to a spec or plan.

lukstafi and others added 2 commits April 20, 2026 23:40
Add ndarray constant regressions (tuple, list, array) to pin the
first-leaf disambiguation heuristic, and a tuple-in-apply test to
lock Pexp_apply tuple preservation. Remove "upcoming"/"planned"
wording from syntax_extensions.md, migration_guide.md, and
slides-shapes_and_einsum.md.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The output-axis concat spec "bt0,...; bt1,..." dropped batch and input
rows, causing shape errors when list block tensor components had input
or batch axes. Use the full spec "...|...-> bt0,...; ..." to broadcast
batch/input rows through concatenation.

Add test 13 exercising list block tensors with input-dim components.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant