Skip to content

The IndexCartesian branch of copyto! is broken as _unsetindex is undefined for CartesianIndex arguments #53098

@jishnub

Description

@jishnub

This is not a regression, but the situation may be improved. On julia nightly,

julia> M = Matrix{BigFloat}(undef, 2, 2)
2×2 Matrix{BigFloat}:
 #undef  #undef
 #undef  #undef

julia> copyto!(view(similar(M), axes(M)...), M)
ERROR: MethodError: no method matching _unsetindex!(::SubArray{BigFloat, 2, Matrix{BigFloat}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}, false}, ::CartesianIndex{2})

Closest candidates are:
  _unsetindex!(::AbstractArray, ::Integer)
   @ Base abstractarray.jl:1447

Stacktrace:
 [1] copyto_unaliased!(deststyle::IndexCartesian, dest::SubArray{BigFloat, 2, Matrix{…}, Tuple{…}, false}, srcstyle::IndexLinear, src::Matrix{BigFloat})
   @ Base ./abstractarray.jl:1115
 [2] copyto!(dest::SubArray{BigFloat, 2, Matrix{BigFloat}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}, false}, src::Matrix{BigFloat})
   @ Base ./abstractarray.jl:1058
 [3] top-level scope
   @ REPL[2]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> methods(Base._unsetindex!)
# 4 methods for generic function "_unsetindex!" from Base:
 [1] _unsetindex!(A::Array, i::Int64)
     @ array.jl:216
 [2] _unsetindex!(A::Memory, i::Int64)
     @ genericmemory.jl:33
 [3] _unsetindex!(A::AbstractArray, i::Integer)
     @ abstractarray.jl:1447
 [4] _unsetindex!(A::MemoryRef{T}) where T
     @ genericmemory.jl:34

The function _unsetindex! appears to be used in the IndexCartesian branch of copyto_unaliased!, but it's not defined for a CartesianIndex. Perhaps a new method should be added.

julia> versioninfo()
Julia Version 1.11.0-DEV.1397
Commit 0588cd40786 (2024-01-29 02:21 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, tigerlake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  LD_LIBRARY_PATH = :/usr/lib/x86_64-linux-gnu/gtk-3.0/modules
  JULIA_EDITOR = subl

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions