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 does not handle numbers correctly #383

Open
vtjnash opened this issue Apr 11, 2023 · 3 comments
Open

vcat does not handle numbers correctly #383

vtjnash opened this issue Apr 11, 2023 · 3 comments

Comments

@vtjnash
Copy link
Contributor

vtjnash commented Apr 11, 2023

julia> vcat(1, sparse([1 2]))
ERROR: DimensionMismatch: tried to assign 1-element array to 1×2 destination
Stacktrace:
  [1] throw_setindex_mismatch(X::SparseVector{Int64, Int64}, I::Tuple{Int64, Int64})
    @ Base ./indices.jl:193
  [2] setindex_shape_check
    @ ./indices.jl:248 [inlined]
  [3] setindex!(A::SparseMatrixCSC{Int64, Int64}, V::SparseVector{Int64, Int64}, Ix::UnitRange{Int64}, Jx::UnitRange{Int64})
    @ SparseArrays ~/julia/usr/share/julia/stdlib/v1.10/SparseArrays/src/sparsematrix.jl:3287
  [4] __cat_offset1!
    @ ./abstractarray.jl:1814 [inlined]
  [5] __cat_offset!
    @ ./abstractarray.jl:1804 [inlined]
  [6] __cat
    @ ./abstractarray.jl:1800 [inlined]
  [7] _cat_t
    @ ./abstractarray.jl:1793 [inlined]
  [8] _cat
    @ ~/julia/usr/share/julia/stdlib/v1.10/SparseArrays/src/sparsevector.jl:1205 [inlined]
  [9] cat
    @ ./abstractarray.jl:1982 [inlined]
 [10] vcat(::Int64, ::SparseMatrixCSC{Int64, Int64})
    @ SparseArrays ~/julia/usr/share/julia/stdlib/v1.10/SparseArrays/src/sparsevector.jl:1217
 [11] top-level scope
    @ REPL[5]:1

julia> vcat(1, [1 2])
2×2 Matrix{Int64}:
 1  1
 1  2
@dkarrasch
Copy link
Member

dkarrasch commented Apr 11, 2023

Seems like the other way around. Base isn't handling it correctly, is it? Why should a number be repeated implicitly? I'd expect to see the same as

julia> vcat([1;;], [1 2])
ERROR: ArgumentError: number of columns of each array must match (got (1, 2))

EDIT: I'm surprised to see that this implicit repetition mechanism is present since at least v1.0. I was not aware of this behavior, at all!

@dkarrasch
Copy link
Member

For the record: It started to change behavior in v1.8.

@dkarrasch
Copy link
Member

dkarrasch commented Apr 11, 2023

Honestly, I believe this is a very old "bug" in Julia Base. Guess the respective results!

julia> vcat(1, [1 2]) # works

julia> vcat([1 2], 3) # throws!

julia> vcat(1, [1 2], 3) # throws!

So, the "expansion" of numbers works only when the number is in the first place, and in no other!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants