Commit 509d7fb
Convert AnonymousStruct shadow to NTuple in batch forward rules
The forward rules for batch width > 1 asserted
`shadow_result[1]::NTuple{W, T}` but `Enzyme.autodiff(Forward, …,
BatchDuplicated{T,W}, …)` returns the batch shadow wrapped in
`Enzyme.Compiler.AnonymousStruct` — a
`NamedTuple{(:1, :2, …), NTuple{W, T}}` (see
`Enzyme/src/compiler/utils.jl:480`).
The mismatch tripped the existing `Enzyme batch forward mode (width > 1)`
testset on `main` with:
```
TypeError: in typeassert, expected Tuple{Float64, Float64},
got a value of type @NamedTuple{1::Float64, 2::Float64}
```
Wrap the shadow in `Tuple(...)` before the type-assert so the rule's
return matches the `BatchDuplicated` shadow contract that Enzyme expects
from a forward rule. Applies to both `{false, true, W>1, …}`
(shadow-only) and `{true, true, W>1, …}` (ForwardWithPrimal) rules.
The existing testset (which was failing on `main`) now passes. Full
local test summary on Julia 1.11 + Enzyme v0.13.147:
```
FunctionWrappersWrappers.jl | 48 48
BigFloat support | 5 5
UnionAll return types | 2 2
Enzyme extension | 44 44
Mooncake extension | 13 13
```
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>1 parent a03f55f commit 509d7fb
1 file changed
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
| |||
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
76 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
77 | 84 | | |
78 | 85 | | |
79 | 86 | | |
| |||
0 commit comments