Skip to content

Commit d0cb1f0

Browse files
rafaqzasinghvi17
andauthored
only call sizeof on isbits types (#275)
* only call sizeof on isbits * test broadcast over strings * Update src/broadcast.jl Co-authored-by: Anshul Singhvi <anshulsinghvi@gmail.com> --------- Co-authored-by: Anshul Singhvi <anshulsinghvi@gmail.com>
1 parent d4bac43 commit d0cb1f0

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/broadcast.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,19 @@ function common_chunks(s, args...)
7070
all(ar -> isa(eachchunk(ar), GridChunks), chunkedarrays) ||
7171
error("Currently only chunks of type GridChunks can be merged by broadcast")
7272
if isempty(chunkedarrays)
73-
totalsize = sum(sizeof eltype, args)
74-
return estimate_chunksize(s, totalsize)
73+
# Estimate chunk size for isbits
74+
if all(map(isbits eltype, args))
75+
return estimate_chunksize(s)
76+
else # Otherwise just use one huge chunk, we dont know what the object is
77+
return GridChunks(s, s)
78+
end
7579
elseif length(chunkedarrays) == 1
7680
return eachchunk(only(chunkedarrays))
7781
else
7882
allchunks = collect(map(eachchunk, chunkedarrays))
7983
tt = ntuple(N) do n
8084
csnow = filter(allchunks) do cs
81-
ndims(cs) >= n && first(first(cs.chunks[n])) < last(last(cs.chunks[n]))
85+
ndims(cs) >= n && first(first(cs.chunks[n])) < last(last(cs.chunks[n]))
8286
end
8387
isempty(csnow) && return RegularChunks(1, 0, s[n])
8488

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,12 @@ end
11681168
@inferred DiskArrays.DiskIndex(a_view6, (1:1, 1:1, 1:1, 1:1, 1:1, 1:1), DiskArrays.NoBatch()) #DiskArrays.DiskIndex
11691169
end
11701170

1171+
1172+
@testset "test broadcast over strings" begin
1173+
a = UnchunkedDiskArray(["a", "b", "c"])
1174+
@test all(a .== ["a", "b", "c"])
1175+
end
1176+
11711177
@testset "mockchunks" begin
11721178
a =UnchunkedDiskArray(rand(10,10))
11731179
chunks = DiskArrays.RegularChunks.((5,5), (0,0), (10,10))

0 commit comments

Comments
 (0)