Fix empty StridedView broadcasting#50
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 6 files with indirect coverage changes 🚀 New features to boost your workflow:
|
lkdvos
approved these changes
Mar 12, 2026
Member
lkdvos
left a comment
There was a problem hiding this comment.
Thanks for the report and fix! (And added tests, greatly appreciated)
mtfishman
added a commit
to ITensor/TensorAlgebra.jl
that referenced
this pull request
May 7, 2026
#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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a bug I came across when broadcasting empty StridedViews. Without this change, I see the following:
Other codepaths like
map[!]seem to already have this kind of check for the empty case (before calling_mapreduce_fuse!).