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

vcat acts inconsistently when only some arguments are row vectors #48468

Open
nicholaskl97 opened this issue Jan 31, 2023 · 2 comments
Open

vcat acts inconsistently when only some arguments are row vectors #48468

nicholaskl97 opened this issue Jan 31, 2023 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@nicholaskl97
Copy link

If you mix row vectors and elements as arguments in vcat and all the row vectors are at the end, then it fills in the lone elements into full rows, but if any lone element comes after a row vector, then vcat throws a dimension mismatch error. Probably, vcat should either always throw the error or always fill in, regardless of argument order. I couldn't find anything in the documentation for vcat saying what behavior a user should expect in this case.

vcat("foo", ["bar" "hello" "world"]) outputs

2×3 Matrix{String}:
 "foo"  "foo"    "foo"
 "bar"  "hello"  "world"

but
vcat(["bar" "hello" "world"], "foo") throws an error:

ERROR: DimensionMismatch: mismatch in dimension 2 (expected 3 got 1)
Stacktrace:
  [1] _cs
    @ ./abstractarray.jl:1717 [inlined]
  [2] _cshp
    @ ./abstractarray.jl:1703 [inlined]
  [3] _cshp
    @ ./abstractarray.jl:1714 [inlined]
  [4] _cat_size_shape
    @ ./abstractarray.jl:1693 [inlined]
  [5] cat_size_shape(dims::Tuple{Bool}, X::Matrix{String}, tail::String)
    @ Base ./abstractarray.jl:1691
  [6] _cat_t(::Val{1}, ::Type{String}, ::Matrix{String}, ::Vararg{Any})
    @ Base ./abstractarray.jl:1732
  [7] _cat(::Val{1}, ::Matrix{String}, ::Vararg{Any})
    @ Base ./abstractarray.jl:1728
  [8] #cat#155
    @ ./abstractarray.jl:1916 [inlined]
  [9] vcat(::Matrix{String}, ::String)
    @ Base ./abstractarray.jl:1815
 [10] top-level scope
    @ REPL[15]:1

Above examples used strings, but the same is true with numbers:
vcat(1, 2, [3 4 5], [6 7 8]) outputs

4×3 Matrix{Int64}:
 1  1  1
 2  2  2
 3  4  5
 6  7  8

but vcat([3 4 5], [6 7 8], 9) throws an error:

ERROR: DimensionMismatch: mismatch in dimension 2 (expected 3 got 1)
Stacktrace:
 [1] _cs
   @ ./abstractarray.jl:1717 [inlined]
 [2] _cshp
   @ ./abstractarray.jl:1703 [inlined]
 [3] _cshp
   @ ./abstractarray.jl:1714 [inlined]
 [4] _cat_size_shape (repeats 2 times)
   @ ./abstractarray.jl:1693 [inlined]
 [5] cat_size_shape
   @ ./abstractarray.jl:1691 [inlined]
 [6] _cat_t
   @ ./abstractarray.jl:1732 [inlined]
 [7] typed_vcat(::Type{Int64}, ::Matrix{Int64}, ::Matrix{Int64}, ::Int64)
   @ Base ./abstractarray.jl:1880
 [8] vcat(::Matrix{Int64}, ::Matrix{Int64}, ::Int64)
   @ LinearAlgebra /opt/julia/julia-1.8.5/share/julia/stdlib/v1.8/LinearAlgebra/src/special.jl:419
 [9] top-level scope
   @ REPL[22]:1

versioninfo() outputs

Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 20 × 12th Gen Intel(R) Core(TM) i9-12900H
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, goldmont)
  Threads: 20 on 20 virtual cores
Environment:
  JULIA_NUM_THREADS = auto

I installed Julia via the official generic binaries, as on julialang.org.

@oscardssmith
Copy link
Member

wow, that's bad. These should all through.

@oscardssmith oscardssmith added the bug Indicates an unexpected problem or unintended behavior label Jan 31, 2023
@BioTurboNick
Copy link
Contributor

I previously documented this. #38019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants