Commit 5a0dfab
Guard β=0 in 0-dim bipermutedimsopadd! and drop empty-array workaround (#173)
## Summary
- The 0-dim branch of `bipermutedimsopadd!` read `dest[]`
unconditionally (`β * dest[] + α * op(src[])`), even when `β = 0`. By
BLAS convention, `β = 0` means `dest` is treated as write-only — its
contents need not be defined. With element types whose `undef` storage
is unreadable, the unguarded read crashed:
`bipermutedimsopadd!(Array{BigFloat, 0}(undef), identity, src, (), (),
true, false)` threw `UndefRefError`, since the unassigned slot of a
0-dim array of mutable `BigFloat` cannot be read. This surfaced via
callers that allocate a 0-dim destination via `similar` and call into
`bipermutedimsopadd!` with `β = 0` (e.g. scalar contractions producing a
0-dim result).
- Adds an `iszero(β)` guard to the 0-dim branch to skip reading `dest`
in the write-only case. The 0-dim short-circuit itself is kept: it lets
downstream array types (e.g. `BlockSparseArray{T, 0}`) use direct
`dest[]`/`src[]` accesses instead of having to support `getindex` on a
0-dim `PermutedDimsArray` wrapper around their type.
- The companion `isempty(dest) && return dest` early return worked
around a `Strided.jl` broadcasting bug fixed by
[QuantumKitHub/Strided.jl#50](QuantumKitHub/Strided.jl#50),
released in `Strided` 2.3.5. Adds `Strided` to `[deps]` (with `using
Strided: Strided` so it isn't reported as stale) and a `Strided =
"2.3.5"` compat floor, then drops the workaround.
- Adds a regression test covering `Array{T, 0}` for `T ∈ {Float64,
BigFloat}` with both `β = 0` (write-only) and `β ≠ 0` (accumulating)
cases.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent b4f43b6 commit 5a0dfab
3 files changed
Lines changed: 37 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
56 | 61 | | |
57 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
58 | 67 | | |
59 | 68 | | |
60 | 69 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
50 | 70 | | |
51 | 71 | | |
52 | 72 | | |
| |||
0 commit comments