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

Specialize Base.similar for VectorOfArray with multidimensional parent #359

Merged
merged 10 commits into from
Feb 22, 2024

Conversation

jlchan
Copy link
Contributor

@jlchan jlchan commented Feb 21, 2024

This PR specializes Base.similar for VectorOfArray with a homogeneous (e.g., all elements are the same type) multidimensional parent array (introduced in #357). This ensures that similar(VectorOfArray(array)).u is similar to array.u where array is a homogeneous multi-dimensional array.

This PR also adds Base.parent for VectorOfArray (parent(vec) just returns vec.u)

@jlchan
Copy link
Contributor Author

jlchan commented Feb 21, 2024

@ranocha I think with these changes, we can deal with multidimensional arrays of SVector

For example, the following works for me under this PR:

using StaticArrays
using RecursiveArrayTools
using OrdinaryDiffEq

function rhs!(duu::VectorOfArray, uu::VectorOfArray, p, t)
    du = parent(duu)
    u = parent(uu)
    du .= u
end

u = fill(SVector{2}(ones(2)), 2, 3)
ode = ODEProblem(rhs!, VectorOfArray(u), (0.0, 1.0))
sol = solve(ode, Tsit5())

@ChrisRackauckas
Copy link
Member

Add that as a regression test in the downstream portion (https://github.com/SciML/RecursiveArrayTools.jl/blob/master/test/upstream.jl which is for some reason named upstream we should fix that and move it to the other test group https://github.com/SciML/RecursiveArrayTools.jl/blob/master/test/runtests.jl#L63

Co-authored-by: Christopher Rackauckas <[email protected]>
@ChrisRackauckas ChrisRackauckas merged commit b10cddb into SciML:master Feb 22, 2024
21 of 24 checks passed
@ranocha
Copy link
Member

ranocha commented Feb 22, 2024

@ranocha I think with these changes, we can deal with multidimensional arrays of SVector

Nice 👍

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.

3 participants