Fix StructArrayStyle broadcast over separate arrays#3065
Open
oschulz wants to merge 2 commits into
Open
Conversation
…ay broadcasts elem_apply_via_while_loop allocated its own result via similar(Broadcasted(f, args), T_res) even when its callers in ReactantStructArraysExt already hold a correctly-typed destination. For struct-returning functions broadcast over plain Reactant arrays under a StructArray broadcast style (as done e.g. by PropertyFunctions.jl to broadcast over individual columns), that internal allocation fails, since similar on the plain Reactant broadcast style only supports primitive and TracedRNumber element types. Split out elem_apply_via_while_loop!(result, f, args...), which writes into a caller-provided destination, and use it in the StructArrays extension's copyto! methods. This also removes an allocate-then-copy round trip.
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #3065 +/- ##
===========================================
- Coverage 68.16% 44.64% -23.53%
===========================================
Files 109 224 +115
Lines 11779 31662 +19883
===========================================
+ Hits 8029 14134 +6105
- Misses 3750 17528 +13778 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Working on the test failures. |
On Julia 1.10/1.11, collecting args of mixed eltypes into a Vector widens the element type to a non-concrete TracedRArray via promote_typejoin, and the resulting convert call hits promote_to, which has no method for non-concrete targets. Keep the args as tuples (filter/map) so no such conversion ever happens. Fixes the CI failures of the mixed-eltype column broadcast test on Julia 1.10 and 1.11. Created by generative AI.
Contributor
Author
|
#3068 should hopefully fix the test failures here. |
Contributor
Author
|
@wsmoses remaining test failures should be unrelated to this PR (I think). |
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.
Ran into this why trying to make PropertyFunctions.jl Reactant-compatible:
This fixes
StructArrays.StructArrayStylebroadcasts where the input is not aStructArraybut one or several plain arrays.Limitation: struct-returning broadcasts over plain arrays, with no StructArrays involvement anywhere, (like a simple
broadcast((x,y) -> (s=x+y,), a, b)withoutStructArrayStyle) will still fail as before. Fixing that would requite Reactant depending on StructArrays.Claude Fable-5:
elem_apply_via_while_loop allocated its own result via similar(Broadcasted(f, args), T_res) even when its callers in ReactantStructArraysExt already hold a correctly-typed destination. For struct-returning functions broadcast over plain Reactant arrays under a StructArray broadcast style (as done e.g. by PropertyFunctions.jl to broadcast over individual columns), that internal allocation fails, since similar on the plain Reactant broadcast style only supports primitive and TracedRNumber element types.
Split out elem_apply_via_while_loop!(result, f, args...), which writes into a caller-provided destination, and use it in the StructArrays extension's copyto! methods. This also removes an allocate-then-copy round trip.