Skip to content

Keep StructArray results when broadcasting over ArrayOfRDWaveforms - #55

Open
theHenks wants to merge 3 commits into
JuliaPhysics:mainfrom
theHenks:fix-structarray-broadcast
Open

Keep StructArray results when broadcasting over ArrayOfRDWaveforms#55
theHenks wants to merge 3 commits into
JuliaPhysics:mainfrom
theHenks:fix-structarray-broadcast

Conversation

@theHenks

@theHenks theHenks commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Since ArraysOfArrays v1, VectorOfArrays and ArrayOfSimilarArrays have their own
broadcast style (NestedArrayStyle), so an ArrayOfRDWaveforms with such a signal
column gets StructArrayStyle{NestedArrayStyle{1}}. StructArrays only builds a
StructArray result for a DefaultArrayStyle parent; otherwise it falls back to a plain
broadcast that returns a Vector of structs (column access like
signalstats.(wvfs, a, b).mean fails with a FieldError) and rebuilds elements with
convert to the declared element type, bypassing the getindex specialization for
StructArray{<:RDWaveform} (fails with a MethodError for lazily read waveforms).

using RadiationDetectorSignals, RadiationDetectorDSP, ArraysOfArrays, FillArrays, Unitful
wvfs = ArrayOfRDWaveforms((Fill((0:0.1:12.7)u"ns", 5), VectorOfSimilarVectors(rand(128, 5))))
bl_stats = signalstats.(wvfs, 0u"ns", 5u"ns")
typeof(bl_stats)   # Vector{@NamedTuple{...}}, was a StructArray with ArraysOfArrays < 1
bl_stats.sigma     # FieldError

This currently breaks the LegendDSP test suite (legend-exp/LegendDSP.jl).

  • StructArray{<:RDWaveform} gets broadcast style StructArrayStyle{DefaultArrayStyle{N},N}:
    StructArrays' native path regardless of the signal column type
  • array-valued broadcasts ((wf -> 2 .* wf.signal).(wvfs)): plain vector of vectors as with
    ArraysOfArrays < 1, no longer VectorOfArrays
  • general StructArrayStyle × NestedArrayStyle fix belongs in ArraysOfArrays; this
    method stays correct either way
  • StructArrays lower bound raised to 0.6.6: StructArrayStyle{S,N} exists since 0.6.5, and 0.6.6 fixes
    array-valued broadcasts over StructArrays on Julia 1.10 (Downgrade CI)

🤖 Generated with Claude Code

@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 13.15%. Comparing base (46beaac) to head (3b7e72c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #55      +/-   ##
==========================================
+ Coverage   12.38%   13.15%   +0.76%     
==========================================
  Files           4        4              
  Lines         113      114       +1     
==========================================
+ Hits           14       15       +1     
  Misses         99       99              

☔ 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.

An ArrayOfRDWaveforms whose signal column is an ArraysOfArrays type
inherits that column's broadcast style, and StructArrays only assembles
a StructArray result for a DefaultArrayStyle parent. Give StructArrays
of RDWaveform a StructArrayStyle{DefaultArrayStyle} so struct-valued
broadcasts (e.g. signalstats.(wvfs, ...)) return a StructArray with
column access, and so elements are read through the RDWaveform-specific
getindex rather than converted to the declared element type.
@theHenks
theHenks force-pushed the fix-structarray-broadcast branch 2 times, most recently from 6eaca37 to c38bf40 Compare September 12, 2026 13:52
@fhagemann

fhagemann commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

I had a similar issue with Unitful for the Downgrade tests in SolidStateDetectors.jl.
You might want to restrict the Unitful version in the Downgrade.yaml workflow file instead of the Project.toml.

See: JuliaPhysics/SolidStateDetectors.jl#637

Comment thread Project.toml Outdated
@theHenks

Copy link
Copy Markdown
Collaborator Author

I had a similar issue with Unitful for the Downgrade tests in SolidStateDetectors.jl. You might want to restrict the Unitful version in the Downgrade.yaml workflow file instead of the Project.toml.

See: JuliaPhysics/SolidStateDetectors.jl#637

Thanks 🙏🏻 I knew there was some fix for this....

The broadcast style of StructArray{<:RDWaveform} is expressed as
StructArrayStyle{S,N}, which exists in this form since StructArrays 0.6.5;
0.6.6 additionally keeps array-valued broadcast results out of StructArray
on Julia 1.10.
Unitful < 1.25.1 spells operator methods as `Base. *(...)`, which the
Julia 1.13 parser rejects, so the lower-bound resolution cannot load it.
@theHenks
theHenks force-pushed the fix-structarray-broadcast branch 2 times, most recently from c930d42 to 3b7e72c Compare September 13, 2026 12:14
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.

2 participants