Skip to content

zml/tensor: respect tags in broad#643

Open
ousamabenyounes wants to merge 1 commit into
zml:masterfrom
ousamabenyounes:fix/issue-68-tagged-broad
Open

zml/tensor: respect tags in broad#643
ousamabenyounes wants to merge 1 commit into
zml:masterfrom
ousamabenyounes:fix/issue-68-tagged-broad

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Make Tensor.broad respect tags when both input and output shapes are fully tagged, and make Shape.canBroadcastTo reject fully tagged positional matches that do not map by tag.

Issues

Fix #68

Why

The issue case .{ .a = 8, .l = 1, .k = 16 }.broad(.{ .a = 8, .k = 16, .v = 16 }) was accepted by positional broadcasting even though the tags do not describe the same axes. Fully tagged shapes should match and broadcast by tag, not by position.

The implementation keeps the integer scalar broadcast compatibility hook ahead of tagged broadcasting and excludes rank-0 shapes from the tagged branch so backend compatibility behavior is preserved.

Test verification (RED -> GREEN)

Command: ./bazel.sh test //zml:test

RED with the production fix reverted while keeping the new tests:

53/142 shape.Shape.test.canBroadcastTo rejects fully tagged positional mismatch...FAIL (TestUnexpectedResult)
114/142 tensor.Tensor.test.Tensor.broad maps fully tagged axes by tag...thread ... panic: Can't broadcast Tensor({a=1,k=16,f32}) to {k=16,a=8,f32}
//zml:test                                                               FAILED in 23.5s
Executed 1 out of 1 test: 1 fails locally.

GREEN on the final branch:

INFO: Build completed successfully, 6 total actions
//zml:test                                                               PASSED in 7.5s
Executed 1 out of 1 test: 1 test passes.

@gwenzek

gwenzek commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

thanks, this is big change since it can break existing code. I'll try to re-prioritize this.

@ousamabenyounes
ousamabenyounes force-pushed the fix/issue-68-tagged-broad branch from 6cf3f26 to 3f7d618 Compare July 11, 2026 08:00
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.

Tensor.broad is too permissive

2 participants