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

getindex with slice breaks on size 1 arrays #354

Closed
lxvm opened this issue Feb 19, 2024 · 0 comments · Fixed by #355
Closed

getindex with slice breaks on size 1 arrays #354

lxvm opened this issue Feb 19, 2024 · 0 comments · Fixed by #355
Labels

Comments

@lxvm
Copy link
Contributor

lxvm commented Feb 19, 2024

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

@lxvm lxvm added the bug label Feb 19, 2024
lxvm added a commit to lxvm/RecursiveArrayTools.jl that referenced this issue Feb 19, 2024
@lxvm lxvm mentioned this issue Feb 19, 2024
5 tasks
lxvm added a commit to lxvm/RecursiveArrayTools.jl that referenced this issue Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant