Skip to content

Commit

Permalink
Add handling in cat for non-numeric element types
Browse files Browse the repository at this point in the history
  • Loading branch information
DrChainsaw committed Feb 21, 2021
1 parent 7bca709 commit 06724c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/fillcat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ function Base.cat_t(::Type{T}, fs::Fill...; dims) where T

# When dims is a tuple the output gets zero padded and we can't use a Fill unless it is all zeros
# There might be some cases when it does not get padded which are not considered here
allvals[] !== zero(T) && sum(catdims) > 1 && return Base._cat_t(dims, T, fs...)

if sum(catdims) > 1
allvals[] isa Number || return Base._cat_t(dims, T, fs...)
allvals[] !== zero(T) && return Base._cat_t(dims, T, fs...)
end

shape = cat_shape_fill(catdims, fs)
return Fill(convert(T, fs[1].value), shape)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,10 @@ end
@test res isa Fill
@test res == cat(fill(1.0, s), fill(1, s); dims=dims)

res = cat(Fill(:a, s), Fill(:a, s); dims=dims)
@test res isa Fill
@test res == cat(fill(:a, s), fill(:a, s);dims=dims)

@test cat(Fill(1, s), Fill(2, s);dims=dims) == cat(fill(1, s), fill(2, s);dims=dims)
end
@testset "Dim $dims" for dims in (
Expand Down

0 comments on commit 06724c6

Please sign in to comment.