Skip to content

Fix StructArrayStyle broadcast over separate arrays#3065

Open
oschulz wants to merge 2 commits into
EnzymeAD:mainfrom
oschulz:structarray-broadcast-inplace
Open

Fix StructArrayStyle broadcast over separate arrays#3065
oschulz wants to merge 2 commits into
EnzymeAD:mainfrom
oschulz:structarray-broadcast-inplace

Conversation

@oschulz

@oschulz oschulz commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Ran into this why trying to make PropertyFunctions.jl Reactant-compatible:

This fixes StructArrays.StructArrayStyle broadcasts where the input is not a StructArray but 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) without StructArrayStyle) 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.

…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

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.64%. Comparing base (b39a1fc) to head (bf5b37f).
⚠️ Report is 1172 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (b39a1fc) and HEAD (bf5b37f). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (b39a1fc) HEAD (bf5b37f)
99 97
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oschulz

oschulz commented Jul 14, 2026

Copy link
Copy Markdown
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.
@oschulz

oschulz commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

#3068 should hopefully fix the test failures here.

@oschulz

oschulz commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@wsmoses remaining test failures should be unrelated to this PR (I think).

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

Successfully merging this pull request may close these issues.

1 participant