Skip to content

Audit and fix dimension label checking and inference (#255)#451

Closed
lukstafi wants to merge 2 commits intoahrefs:masterfrom
lukstafi:ludics/gh-ocannl-255-s5/root
Closed

Audit and fix dimension label checking and inference (#255)#451
lukstafi wants to merge 2 commits intoahrefs:masterfrom
lukstafi:ludics/gh-ocannl-255-s5/root

Conversation

@lukstafi
Copy link
Copy Markdown
Collaborator

Summary

  • Fix variable-mediated label loss in unify_dim: when a dim variable solved to an unlabeled dim is later unified with a labeled dim of the same size, the variable's stored value is upgraded to carry the label, so future conflicting labels are caught
  • Add label guard to unify_dim and dim_comparison_for_axis fast paths (defense-in-depth)
  • Add concat label consistency check: conflicting labels in solved concat components now raise Shape_error
  • Add affine/convolution label conflict check between stride and kernel dims
  • Propagate labels through stride/convolution arithmetic (4 branches in unify_dim)
  • Document intentional LUB broadcast semantics for conflicting labels
  • Add 19 focused test cases (9 DSL integration + 10 direct Row construction) that explicitly verify label strings

Test plan

  • dune build @check passes
  • OCANNL_BACKEND=sync_cc dune exec test/einsum/test_dimension_labels.exe — all 19 tests pass
  • OCANNL_BACKEND=sync_cc dune runtest — no new failures beyond pre-existing baseline

Closes #255

🤖 Generated with Claude Code

@lukstafi lukstafi force-pushed the ludics/gh-ocannl-255-s5/root branch from ea03bfc to f9438f8 Compare April 15, 2026 08:23
lukstafi and others added 2 commits April 15, 2026 10:23
- Fix variable-mediated label loss: when unify_dim sees Dim{label=None}
  vs Dim{label=Some l} with equal sizes, upgrade the variable that
  resolved to the unlabeled dim so the label persists in future checks
- Add label guard to unify_dim and dim_comparison_for_axis fast paths
- Add concat label consistency check in s_dim_one (conflicting labels raise)
- Add affine/convolution label conflict check in s_dim_one
- Propagate labels through stride/convolution arithmetic (4 branches)
- Document intentional LUB broadcast semantics for conflicting labels
- Add 18 focused test cases (8 DSL integration + 10 direct Row construction)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address reviewer feedback: tests that claim label preservation or
propagation now explicitly verify the label string (via row_to_labels
or Shape.to_labels), not just absence of exceptions.

Key changes:
- Add get_var_label helper using Row.row_to_labels to inspect labels
- Add test 5b: verifies variable label upgrade in the environment
- Tests 1, 3: verify label visible in result shape via Shape.to_labels
- Tests 9, 11: restructure concat tests to use variable components
  (triggers s_dim_one collapse), verify label="x" and d=5
- Tests 12, 14-17: verify label="x" on solved dims after affine/stride
  arithmetic, not just absence of errors
- Test 18: assert definite Shape_error for mutual inequality with
  conflicting labels, instead of accepting either outcome

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lukstafi lukstafi force-pushed the ludics/gh-ocannl-255-s5/root branch from f9438f8 to 8b9140b 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
Copy link
Copy Markdown
Collaborator Author

Closing: this PR was filed against the wrong repo due to a gh-resolved bug (see lukstafi/ludics#302). Ported to lukstafi#7.

@lukstafi lukstafi closed this Apr 15, 2026
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.

Audit and/or more extensively test dimension label (aka. basis) checking and inference

1 participant