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

Fix broadcast assignment for VectorOfArray with StructArrays #426

Merged
merged 2 commits into from
Mar 15, 2025

Conversation

jlchan
Copy link
Contributor

@jlchan jlchan commented Mar 14, 2025

Attempt 2 to address SciML/OrdinaryDiffEq.jl#2625 (comment). I just applied the same approach taken in #425 for setindex! to broadcasted Base.copyto!.

I've verified that this also fixes the discrepancy in number of time-steps taken by an adaptive solver. The following MWE now results in the same number of accepted time-steps under this PR.

using OrdinaryDiffEqSSPRK, RecursiveArrayTools
using StaticArrays, StructArrays

function rhs!(du_voa, u_voa, params, t)
    du = parent(du_voa)
    u = parent(u_voa)
    du .= u
end

# StructArray storage
u = StructArray{SVector{1, Float64}}(ntuple(_ -> [1.0, 2.0], 1))
ode = ODEProblem(rhs!, VectorOfArray(u), (0, 0.7))
sol_SA = solve(ode, SSPRK43())
@show sol_SA.stats.naccept

# Vector{<:SVector} storage
u = SVector{1, Float64}.([1.0, 2.0])
ode = ODEProblem(rhs!, VectorOfArray(u), (0, 0.7))
sol_SV = solve(ode, SSPRK43())
@show sol_SV.stats.naccept

@jlchan
Copy link
Contributor Author

jlchan commented Mar 15, 2025

@ChrisRackauckas do you know if the integration CI failures are spurious? The error messages don't appear to involve StructArrays, but I'm not sure if inference failures like IntegrationTest / DiffEqBase.jl/Downstream/1 (pull_request) are related.

@ChrisRackauckas
Copy link
Member

Spurious, I need to work through those.

@ChrisRackauckas ChrisRackauckas merged commit fbf85bf into SciML:master Mar 15, 2025
18 of 27 checks passed
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