Skip to content

Specialize Base.similar for VectorOfArray with multidimensional parent - #359

Merged
ChrisRackauckas merged 10 commits into
SciML:masterfrom
jlchan:jc/VectorOfArray_multidim_helper
Feb 22, 2024
Merged

ChrisRackauckas merged 10 commits into
SciML:masterfrom
jlchan:jc/VectorOfArray_multidim_helper

Conversation

@jlchan

@jlchan jlchan commented Feb 21, 2024

Copy link
Copy Markdown
Contributor

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

jlchan commented Feb 21, 2024

Copy link
Copy Markdown
Contributor Author

@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())

Comment thread src/vector_of_array.jl Outdated
@ChrisRackauckas

Copy link
Copy Markdown
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]>
Comment thread src/vector_of_array.jl Outdated
Comment thread test/downstream/odesolve.jl
@ChrisRackauckas
ChrisRackauckas merged commit b10cddb into SciML:master Feb 22, 2024
@ranocha

ranocha commented Feb 22, 2024

Copy link
Copy Markdown
Member

@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