Add recursivecopyto! with copyto!-style semantics#591
Conversation
`recursivecopy!` requires `ndims(b) == ndims(a)` via dispatch, matching its `copy!` namesake — which errors on mismatched axes. `recursivecopyto!` is the `copyto!` counterpart: linear-index copy with no shape check, only requiring `length(b) >= length(a)`. This unblocks the `reinit(prob; u0 = vec)` use case from SciML#589 without weakening `recursivecopy!`'s contract. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
|
CI status (partial — 6 SciMLSensitivity / 1 RaggedArrays jobs still running): My added paths all pass (Core, ArrayPartitionAnyAll, RaggedArrays, ShorthandConstructors, nopre, all Julia versions; GPU; Documentation; SciMLBase/OrdinaryDiffEq/DelayDiffEq/DiffEqBase/DiffEqSensitivity/LabelledArrays integration; SciMLSensitivity Core4). 4 pre-existing master failures reproduce here, none caused by this PR:
Both being addressed in separate PRs so this one stays focused on |
|
Update: 30/37 jobs pass (Core1/Core5 SciMLSensitivity and RaggedArrays-lts still running).
Total pre-existing master failures reproducing on this branch: runic + Downstream ×3 + SciMLSensitivity Core6. All are SciMLSensitivity/dependency/CI hygiene issues unrelated to |
Note
Please ignore this PR until reviewed by @ChrisRackauckas.
Summary
Adds
recursivecopyto!as thecopyto!-style sibling ofrecursivecopy!. Closes the gap raised in #589.The distinction follows Base Julia exactly:
copy!recursivecopy!ndims/axescopyto!recursivecopyto!length(b) >= length(a)recursivecopy!'s signature(::AbstractArray{T,N}, ::AbstractArray{T2,N})already enforces matchingndimsvia dispatch, matching itscopy!namesake's contract. That's intentional and is preserved here — relaxing it would silently changerecursivecopy!tocopyto!semantics. Instead, this PR introduces a parallelrecursivecopyto!for callers that want the looser linear-fill behavior (e.g.reinit(prob; u0 = some_vec)whereprob.u0::Matrix).Changes
src/utils.jl: newrecursivecopyto!methods coveringAbstractArray(delegates tocopyto!),StaticArrayelement type, nestedAbstractArray/AbstractVectorOfArray, andAbstractVectorOfArraycontainers. Mirrors the body ofrecursivecopy!but drops theN-matching constraint and useszip(eachindex(b), eachindex(a))so different shapes are valid.src/array_partition.jl:recursivecopyto!(::ArrayPartition, ::ArrayPartition)and theVectorOfArray-of-partitions variant.src/RecursiveArrayTools.jl: export.docs/src/recursive_array_functions.md: docs entry.test/utils_test.jl: new@testset "recursivecopyto!"covering same-shape (parity withcopyto!), Matrix ← Vector (the Why doesn'trecursivecopy!allow to copy a vector into a matrix? #589 case), Vector ← Matrix, different-shape same-length matrices, dst-longer / dst-shorter, nested deep-copy semantics, leaf shape mismatches,StaticArrayleaves,ArrayPartition, andVectorOfArray. Also asserts the existingrecursivecopy!still throwsMethodErroron shape mismatch.Test plan
recursivecopyto!testset passes (15 assertions, run locally)recursivecopy!testset passes unchanged (9 assertions covering MVector/SVector/nested VoA, run locally as regression check)