Skip to content

Commit 668e445

Browse files
authored
Merge pull request #138 from jdeldre/je/broadcast-similar
Allow DefaultArrayStyle to be broadcast according to normal rules
2 parents 47943f4 + ffcbf5e commit 668e445

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/array_partition.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ _npartitions(args::Tuple{}) = 0
306306
# drop axes because it is easier to recompute
307307
@inline unpack(bc::Broadcast.Broadcasted{Style}, i) where Style = Broadcast.Broadcasted(bc.f, unpack_args(i, bc.args))
308308
@inline unpack(bc::Broadcast.Broadcasted{ArrayPartitionStyle{Style}}, i) where Style = Broadcast.Broadcasted(bc.f, unpack_args(i, bc.args))
309+
@inline unpack(bc::Broadcast.Broadcasted{Style}, i) where Style <: Broadcast.DefaultArrayStyle = Broadcast.Broadcasted{Style}(bc.f, unpack_args(i, bc.args))
310+
@inline unpack(bc::Broadcast.Broadcasted{ArrayPartitionStyle{Style}}, i) where Style <: Broadcast.DefaultArrayStyle = Broadcast.Broadcasted{Style}(bc.f, unpack_args(i, bc.args))
309311
unpack(x,::Any) = x
310312
unpack(x::ArrayPartition, i) = x.x[i]
311313

test/partitions_test.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ up = ap .+ 1
172172
up = 2 .* ap .+ 1
173173
@test typeof(ap) == typeof(up)
174174

175+
# Test that `zeros()` does not get screwed up
176+
ap = ArrayPartition(zeros(),[1.0])
177+
up = ap .+ 1
178+
@test typeof(ap) == typeof(up)
179+
180+
up = 2 .* ap .+ 1
181+
@test typeof(ap) == typeof(up)
175182

176183
@testset "ArrayInterface.ismutable(ArrayPartition($a, $b)) == $r" for (a, b, r) in ((1,2, false), ([1], 2, false), ([1], [2], true))
177184
@test ArrayInterface.ismutable(ArrayPartition(a, b)) == r

0 commit comments

Comments
 (0)