RecursiveArrayTools.jl icon indicating copy to clipboard operation
RecursiveArrayTools.jl copied to clipboard

Broadcasted assignment fails for `VectorOfArray(Array{<:SVector{1}})`

Open jlchan opened this issue 1 year ago • 1 comments

Describe the bug 🐞 Expected behavior

Broadcasting fails for VectorOfArray(Array{<:SVector{1}}). This is specific to parent arrays with element type <:SVector{1}; it works fine if <:SVector{N} where N > 1.

Minimal Reproducible Example 👇

using RecursiveArrayTools
using StaticArrays

# works for SVector{N} where N > 1
u = [SVector(0, 1) for _ in 1:2]
u_voa = VectorOfArray(u)
v_voa = copy(u_voa)
@. v_voa = u_voa

# doesn't work for SVector{1}
u = [SVector(0) for _ in 1:2]
u_voa = VectorOfArray(u)
v_voa = copy(u_voa)
@. v_voa = u_voa

Error & Stacktrace ⚠️

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

Closest candidates are:
  convert(::Type{T}, ::T) where T<:Number
   @ Base number.jl:6
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84
  convert(::Type{T}, ::AbstractChar) where T<:Number
   @ Base char.jl:185
  ...

Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/StaticArraysCore/P6PH7/src/StaticArraysCore.jl:88 [inlined]
  [2] convert_ntuple
    @ ~/.julia/packages/StaticArraysCore/P6PH7/src/StaticArraysCore.jl:84 [inlined]
  [3] SVector{1, Int64}(x::Tuple{SVector{1, Int64}})
    @ StaticArraysCore ~/.julia/packages/StaticArraysCore/P6PH7/src/StaticArraysCore.jl:120
  [4] macro expansion
    @ StaticArrays ~/.julia/packages/StaticArrays/YN0oL/src/arraymath.jl:52 [inlined]
  [5] _fill
    @ StaticArrays ~/.julia/packages/StaticArrays/YN0oL/src/arraymath.jl:40 [inlined]
  [6] fill
    @ StaticArrays ~/.julia/packages/StaticArrays/YN0oL/src/arraymath.jl:39 [inlined]
  [7] copyto!
    @ RecursiveArrayTools ~/.julia/dev/RecursiveArrayTools/src/vector_of_array.jl:895 [inlined]
  [8] materialize!
    @ Base.Broadcast ./broadcast.jl:914 [inlined]
  [9] materialize!(dest::VectorOfArray{…}, bc::Base.Broadcast.Broadcasted{…})
    @ Base.Broadcast ./broadcast.jl:911
 [10] top-level scope
    @ Untitled-1:14
Some type information was truncated. Use `show(err)` to see complete types.

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
julia> using Pkg; Pkg.status()
Status `~/.julia/dev/RecursiveArrayTools/run/Project.toml`
  [731186ca] RecursiveArrayTools v3.19.0 `~/.julia/dev/RecursiveArrayTools`
  [90137ffa] StaticArrays v1.9.4
  • Output of using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
julia> using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
Status `~/.julia/dev/RecursiveArrayTools/run/Manifest.toml`
  [7d9f7c33] Accessors v0.1.36
  [79e6a3ab] Adapt v4.0.4
  [4fba245c] ArrayInterface v7.10.0
  [a33af91c] CompositionsBase v0.1.2
  [187b0558] ConstructionBase v1.5.5
  [9a962f9c] DataAPI v1.16.0
  [e2d170a0] DataValueInterfaces v1.0.0
  [ffbed154] DocStringExtensions v0.9.3
  [e2ba6199] ExprTools v0.1.10
  [46192b85] GPUArraysCore v0.1.6
  [3587e190] InverseFunctions v0.1.14
  [82899510] IteratorInterfaceExtensions v1.0.0
  [1914dd2f] MacroTools v0.5.13
  [bac558e1] OrderedCollections v1.6.3
  [aea7be01] PrecompileTools v1.2.1
  [21216c6a] Preferences v1.4.3
  [3cdcf5f2] RecipesBase v1.3.4
  [731186ca] RecursiveArrayTools v3.19.0 `~/.julia/dev/RecursiveArrayTools`
  [ae029012] Requires v1.3.0
  [7e49a35a] RuntimeGeneratedFunctions v0.5.13
  [90137ffa] StaticArrays v1.9.4
  [1e83bf80] StaticArraysCore v1.4.2
  [2efcf032] SymbolicIndexingInterface v0.3.21
  [3783bdb8] TableTraits v1.0.1
  [bd369af6] Tables v1.11.1
  [56f22d72] Artifacts
  [2a0f44e3] Base64
  [ade2ca70] Dates
  [b77e0a4c] InteractiveUtils
  [76f85450] LibGit2
  [8f399da3] Libdl
  [37e2e46d] LinearAlgebra
  [56ddb016] Logging
  [d6f4376e] Markdown
  [ca575930] NetworkOptions v1.2.0
  [de0858da] Printf
  [9a3f8284] Random
  [ea8e919c] SHA v0.7.0
  [9e88b42a] Serialization
  [2f01184e] SparseArrays v1.10.0
  [10745b16] Statistics v1.10.0
  [4607b0f0] SuiteSparse
  [fa267f1f] TOML v1.0.3
  [8dfed614] Test
  [cf7118a7] UUIDs
  [4ec0a83e] Unicode
  [e66e0078] CompilerSupportLibraries_jll v1.0.5+1
  [e37daf67] LibGit2_jll v1.6.4+0
  [29816b5a] LibSSH2_jll v1.11.0+1
  [c8ffd9c3] MbedTLS_jll v2.28.2+1
  [4536629a] OpenBLAS_jll v0.3.23+2
  [bea87d4a] SuiteSparse_jll v7.2.1+1
  [8e850b90] libblastrampoline_jll v5.8.0+1
  • Output of versioninfo()
julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 12 × Apple M2 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 1

Additional context

This comes up when trying to use VectorOfArray in an explicit OrdinaryDiffEq.jl solver.

jlchan avatar May 22 '24 05:05 jlchan

Probably just overload copyto! to handle this?

ChrisRackauckas avatar May 23 '24 12:05 ChrisRackauckas

This issue stops my work https://github.com/trixi-framework/Trixi.jl/issues/2108 and I am helping Jesse to resolve this.

huiyuxie avatar Oct 28 '24 03:10 huiyuxie

Thanks @huiyuxie!

jlchan avatar Oct 28 '24 03:10 jlchan