Skip to content

Commit ac396ae

Browse files
committed
Fix broadcasting into DistributedArray
1 parent f28343c commit ac396ae

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributedArrays"
22
uuid = "aaf54ef3-cdf8-58ed-94cc-d582ad619b94"
3-
version = "0.6.8"
3+
version = "0.6.9"
44

55
[deps]
66
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"

src/broadcast.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# We define a custom ArrayStyle here since we need to keep track of
66
# the fact that it is Distributed and what kind of underlying broadcast behaviour
77
# we will encounter.
8-
struct DArrayStyle{Style <: BroadcastStyle} <: Broadcast.AbstractArrayStyle{Any} end
8+
struct DArrayStyle{Style <: Union{Nothing,BroadcastStyle}} <: Broadcast.AbstractArrayStyle{Any} end
99
DArrayStyle(::S) where {S} = DArrayStyle{S}()
1010
DArrayStyle(::S, ::Val{N}) where {S,N} = DArrayStyle(S(Val(N)))
1111
DArrayStyle(::Val{N}) where N = DArrayStyle{Broadcast.DefaultArrayStyle{N}}()
@@ -50,6 +50,8 @@ function Base.similar(bc::Broadcasted{<:DArrayStyle{Style}}, ::Type{ElType}) whe
5050
end
5151

5252
##
53+
# Ref https://docs.julialang.org/en/v1/manual/interfaces/#extending-in-place-broadcast-2
54+
#
5355
# We purposefully only specialise `copyto!`,
5456
# Broadcast implementation that defers to the underlying BroadcastStyle. We can't
5557
# assume that `getindex` is fast, furthermore we can't assume that the distribution of
@@ -119,7 +121,7 @@ end
119121

120122
# Distribute broadcast
121123
# TODO: How to decide on cuts
122-
@inline bcdistribute(bc::Broadcasted{Style}) where Style = Broadcasted{DArrayStyle{Style}}(bc.f, bcdistribute_args(bc.args), bc.axes)
124+
@inline bcdistribute(bc::Broadcasted{Style}) where Style<:Union{Nothing,BroadcastStyle} = Broadcasted{DArrayStyle{Style}}(bc.f, bcdistribute_args(bc.args), bc.axes)
123125
@inline bcdistribute(bc::Broadcasted{Style}) where Style<:DArrayStyle = Broadcasted{Style}(bc.f, bcdistribute_args(bc.args), bc.axes)
124126

125127
# ask BroadcastStyle to decide if argument is in need of being distributed
@@ -135,7 +137,7 @@ bcdistribute_args(args::Tuple{Any}) = (bcdistribute(args[1]),)
135137
bcdistribute_args(args::Tuple{}) = ()
136138

137139
# dropping axes here since recomputing is easier
138-
@inline bclocal(bc::Broadcasted{DArrayStyle{Style}}, idxs) where Style = Broadcasted{Style}(bc.f, bclocal_args(_bcview(axes(bc), idxs), bc.args))
140+
@inline bclocal(bc::Broadcasted{DArrayStyle{Style}}, idxs) where Style<:Union{Nothing,BroadcastStyle} = Broadcasted{Style}(bc.f, bclocal_args(_bcview(axes(bc), idxs), bc.args))
139141

140142
# bclocal will do a view of the data and the copy it over
141143
# except when the data already is local

test/darray.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,13 @@ check_leaks()
897897
@test Array(g) == Array(a) .- Array(m) .* sin.(Array(c))
898898
end
899899

900+
@testset "Broadcasting into DArray" begin
901+
a .= ones(nrows, ncols)
902+
@test all(isone, a)
903+
a .= 3 .+ abs2.(@view(zeros(nrows, ncols + 5)[:, 6:end]))
904+
@test all(x -> x == 3, a)
905+
end
906+
900907
# @testset "lazy wrapped broadcast" begin
901908
# l = similar(a)
902909
# l[1:10, :] .= view(a, 1:10, : )

0 commit comments

Comments
 (0)