Skip to content

Fix recursivefill! for VectorOfArray{<:StaticArray} - #261

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
jipolanco:jip/recursivefill
Apr 28, 2023
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
jipolanco:jip/recursivefill

Conversation

@jipolanco

Copy link
Copy Markdown
Contributor

This PR fixes recursivefill! when attempting to fill a VectorOfArray in which the element type is some sort of StaticArray.

Here is a minimal example:

using RecursiveArrayTools
using StaticArrays

A = VectorOfArray([randn(SVector{3, Float64}, i) for i ∈ 1:4])   # A[i] is a Vector{SVector{...}}

B = recursivecopy(A)
recursivefill!(B, zero(eltype(B)))

C = recursivecopy(A)
recursivefill!(C, false)

In the current master, the calls to recursivefill! respectively fail with:

1. ERROR: MethodError: Cannot `convert` an object of type Float64 to an object of type SVector{3, Float64}                                                                                                           

2. ERROR: MethodError: no method matching fill(::Bool, ::Type{Vector{SVector{3, Float64}}})

This is because, in the called recursivefill! variants, it is assumed that B[i] isa eltype(B), which is generally the case for AbstractArrays. This condition is however violated by VectorOfArray (since in this case B[i] is an AbstractVector{eltype(B)}).

This is fixed in this PR by adding specialisations of recursivefill! for AbstractVectorOfArray{<:StaticArray}.

@ChrisRackauckas
ChrisRackauckas merged commit ba33df7 into SciML:master Apr 28, 2023
@jipolanco
jipolanco deleted the jip/recursivefill branch May 2, 2023 06:24
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