Skip to content

hcat/vcat/hvcat bug  #885

Closed
Closed
@andreasvarga

Description

@andreasvarga

The following simple matrix construction fails (joint finding with John Verzani #364):

julia> using LinearAlgebra

julia> [1 2; I]
ERROR: ArgumentError: number of columns of each array must match (got (2, 1))
Stacktrace:
 [1] _typed_vcat(#unused#::Type{Any}, A::Tuple{Matrix{Any}, Matrix{Any}})
   @ Base .\abstractarray.jl:1553
 [2] typed_vcat(::Type{Any}, ::Matrix{Any}, ::Matrix{Any})
   @ Base .\abstractarray.jl:1567
 [3] typed_hvcat(::Type{Any}, ::Tuple{Int64, Int64}, ::Int64, ::Vararg{Any, N} where N)
   @ Base .\abstractarray.jl:1957
 [4] hvcat(::Tuple{Int64, Int64}, ::Int64, ::Vararg{Any, N} where N)
   @ Base .\abstractarray.jl:1932
 [5] top-level scope
   @ REPL[9]:1

but [[1] [2]; I] and [[1 2]; I] work correctly:

julia> [[1] [2]; I]
3×2 Matrix{Int64}:
 1  2
 1  0
 0  1

julia>  [[1 2]; I]
3×2 Matrix{Int64}:
 1  2
 1  0
 0  1

I think, a simple fix would be to replace line 393 of LinearAlgebra.UniformScaling
promote_to_arrays_(n::Int, ::Type, a::Number) = a
with
promote_to_arrays_(n::Int, ::Type, a::Number) = [a]

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