I noticed an inconsistency in the behavior of cat when concatenating values with vectors and arrays.
cat(1, [2 3], dims = 1) # vcat of a scalar to a 1脳2 array
#=
2脳2 Array{Int64,2}:
1 1
2 3
=#
cat(1, [2;3], dims = 2) # hcat of scalar to a vector
#=
ERROR: DimensionMismatch("mismatch in dimension 1 (expected 1 got 2)")
=#
cat(1, reshape([2;3], (2,1)), dims = 2) # hcat of scalar to a 2脳1 array
#=
ERROR: DimensionMismatch("mismatch in dimension 1 (expected 1 got 2)")
=#
cat(1, [2 3; 4 5], dims = 1)
#=
3脳2 Matrix{Int64}:
1 1
2 3
4 5
=#
cat(1, [2 3; 4 5], dims = 2)
#=
ERROR: DimensionMismatch("mismatch in dimension 1 (expected 1 got 2)")
=#
It appears that, generally speaking, A) cat can concatenate with a scalar when dims is lower than the dimensionality of the array; B) if dims is equal to the dimensionality, it can only concatenate the scalar if the array is extended along only that dimension; and C) if dims is greater than the dimensionality of the array, it always fails.
#34395
Coming from #34395, I think the following seem like valid uses of cat with scalars and should be preserved:
cat(1, 2, 3, dims = (1, 2, 3)) # [1 0 0; 0 0 0; 0 0 0;; 0 0 0; 0 2 0; 0 0 0;; 0 0 0; 0 0 0; 0 0 3]
cat(1, [2 3], dims = 2) # [1 2 3]
cat(1, reshape([2; 3], (2, 1)), dims = 1) # [1; 2; 3]
Another bugged case: [fill(1); rand(2, 2, 2)] hits some sort of non-terminating loop/recursion.
Edit: it's an infinite loop.
Another bugged case:
[fill(1); rand(2, 2, 2)]hits some sort of non-terminating loop/recursion.Edit: it's an infinite loop.
Looks like an issue with 0-dimensional arrays?