Commit 8dc3bf1
Preserve torch autograd in the batched cov path
The generic `cov` implementation called `xp.asarray(m)` on its input. For
torch this detaches gradients and mutates the caller's tensor in place, so
`cov` on a batched tensor (ndim > 2, which routes to the generic path) with
`requires_grad=True` returned a detached result and silently zeroed the
input's grad.
The call is unnecessary: the delegation layer already guarantees `m` is an
array (it calls `array_namespace(m)` and reads `m.ndim`). Drop it, and add
a torch autograd regression test.1 parent 8d1989c commit 8dc3bf1
2 files changed
Lines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
274 | 276 | | |
275 | 277 | | |
276 | 278 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
801 | 801 | | |
802 | 802 | | |
803 | 803 | | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
804 | 820 | | |
805 | 821 | | |
806 | 822 | | |
| |||
0 commit comments