Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcasting causes StackOverflowError in combination with Tuple #573

Open
abraemer opened this issue Oct 21, 2024 · 0 comments
Open

Broadcasting causes StackOverflowError in combination with Tuple #573

abraemer opened this issue Oct 21, 2024 · 0 comments

Comments

@abraemer
Copy link
Contributor

abraemer commented Oct 21, 2024

By chance I found a strange corner case with regard to broadcasting:
MWE:

using SparseArrays
v1 = spzeros(5); v2 = spzeros(5);
v1 .= .*(v1, (1,))
v1 .= .*(v2, (1,)) # works
v1 .= .*(v1, v2, Ref(1)) # works
v1 .= .*(v1, v2, (1,)) # ERROR: StackOverflowError:
v1 .= .*(v1, v2, (1,2,3,4,5)) # ERROR: StackOverflowError:

Note that the specific function, here *, is unimportant. This issue occurred with a package originally. Somehow if the function has more than 2 arguments and one of them is a tuple, an infinite recursion happens. Interestingly, a Ref works in-place of the single-element tuple.

Stacktrace:

ERROR: StackOverflowError:
Stacktrace:
      [1] materialize!(dest::SparseVector{…}, bc::Base.Broadcast.Broadcasted{…})
        @ Base.Broadcast .\broadcast.jl:910
      [2] broadcast!
        @ .\broadcast.jl:880 [inlined]
      [3] copyto!
        @ C:\Users\bradr\.julia\juliaup\julia-1.10.3+0.x64.w64.mingw32\share\julia\stdlib\v1.10\SparseArrays\src\higherorderfns.jl:1175 [inlined]
      [4] materialize!
        @ .\broadcast.jl:914 [inlined]
      [5] materialize!(dest::SparseVector{…}, bc::Base.Broadcast.Broadcasted{…})
        @ Base.Broadcast .\broadcast.jl:911
--- the last 4 lines are repeated 29019 more times ---
 [116082] broadcast!
        @ .\broadcast.jl:880 [inlined]
 [116083] copyto!
        @ C:\Users\bradr\.julia\juliaup\julia-1.10.3+0.x64.w64.mingw32\share\julia\stdlib\v1.10\SparseArrays\src\higherorderfns.jl:1175 [inlined]
 [116084] materialize!
        @ .\broadcast.jl:914 [inlined]
Some type information was truncated. Use `show(err)` to see complete types.

I observed this on 1.11.1, 1.10.5, 1.9 and 1.6.

ref Jutho/VectorInterface.jl#19

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

No branches or pull requests

1 participant