Skip to content

Why doesn't recursivecopy! allow to copy a vector into a matrix? #589

Description

@albertomercurio

Is your feature request related to a problem? Please describe.

I need to copy the content of a vector into a matrix. This is handled in pure Julia through the copyto! function

x_mat = rand(10, 10)
y_mat = rand(100, 100)
y_vec = view(y_mat, :, 1)

copyto!(x_mat, y_vec)

but it is not supported by the recursivecopy! function

using RecursiveArrayTools

recursivecopy!(x_mat, y_vec)
ERROR: MethodError: no method matching recursivecopy!(::Matrix{Float64}, ::SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{…}, Int64}, true})
The function `recursivecopy!` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  recursivecopy!(::AbstractArray{T, N}, ::AbstractArray{T2, N}) where {T<:Number, T2<:Number, N}
   @ RecursiveArrayTools ~/.julia/packages/RecursiveArrayTools/9sjwU/src/utils.jl:73
  recursivecopy!(::AbstractVectorOfArray, ::AbstractVectorOfArray)
   @ RecursiveArrayTools ~/.julia/packages/RecursiveArrayTools/9sjwU/src/utils.jl:97
  recursivecopy!(::T, ::T) where T<:JumpProcesses.ExtendedJumpArray
   @ JumpProcesses ~/.julia/packages/JumpProcesses/MF0Pb/src/extended_jump_array.jl:143
  ...

Stacktrace:
 [1] top-level scope
   @ Untitled-1:41
Some type information was truncated. Use `show(err)` to see complete types.

Describe the solution you’d like

Perhaps changing the current method

function recursivecopy!(
        b::AbstractArray{T, N},
        a::AbstractArray{T2, N}
    ) where {T <: Number, T2 <: Number, N}
    return copyto!(b, a)
end

to

function recursivecopy!(
        b::AbstractArray{T, N},
        a::AbstractArray{T2, M}
    ) where {T <: Number, T2 <: Number, N, M}
    return copyto!(b, a)
end

I don't know if we can also change the other methods that do not have T <: Number.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions