Skip to content

getindex with slice breaks on size 1 arrays #354

@lxvm

Description

@lxvm

MWE:

julia> using SciMLBase

julia> EnsembleSolution(ones(2), 0.0, false, nothing)[:]
2-element Vector{Float64}:
 1.0
 1.0

julia> EnsembleSolution(ones(1), 0.0, false, nothing)[:]
ERROR: MethodError: no method matching reshape(::Float64, ::Int64)

Closest candidates are:
  reshape(::RecursiveArrayTools.AbstractVectorOfArray, ::Any...)
   @ RecursiveArrayTools ~/.julia/packages/RecursiveArrayTools/kqKNI/src/vector_of_array.jl:687
  reshape(::FillArrays.AbstractFill, ::Union{Colon, Integer}...)
   @ FillArrays ~/.julia/packages/FillArrays/oXkMk/src/FillArrays.jl:260
  reshape(::AbstractArray, ::Int64...)
   @ Base reshapedarray.jl:117
  ...

Stacktrace:
 [1] _getindex
   @ ~/.julia/packages/RecursiveArrayTools/kqKNI/src/vector_of_array.jl:278 [inlined]
 [2] getindex(::EnsembleSolution{Float64, 1, Vector{Float64}}, ::Function)
   @ RecursiveArrayTools ~/.julia/packages/RecursiveArrayTools/kqKNI/src/vector_of_array.jl:393
 [3] top-level scope
   @ REPL[13]:1

This is because in the following line reduce(hcat, vecs) is not type stable:

reshape(reduce(hcat, vecs), size(A.u[1])..., length(A.u)))

However, Array seems to work fine:

julia> Array(EnsembleSolution(ones(1), 0.0, false, nothing))
1-element Vector{Float64}:
 1.0

so the getindex(A, ::Colon...) method should probably get replaced with Array

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions