Skip to content

Commit ef76d9c

Browse files
authored
Merge pull request #26891 from JuliaLang/mb-teh-jn-ajk/lazydotfuse
Customizable lazy fused broadcasting in pure Julia
2 parents f4349c1 + 18ad6a8 commit ef76d9c

30 files changed

+1447
-873
lines changed

NEWS.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,6 @@ This section lists changes that do not have deprecation warnings.
388388
Its return value has been removed. Use the `process_running` function
389389
to determine if a process has already exited.
390390

391-
* Broadcasting has been redesigned with an extensible public interface. The new API is
392-
documented at https://docs.julialang.org/en/latest/manual/interfaces/#Interfaces-1.
393-
`AbstractArray` types that specialized broadcasting using the old internal API will
394-
need to switch to the new API. ([#20740])
395-
396391
* The logging system has been redesigned - `info` and `warn` are deprecated
397392
and replaced with the logging macros `@info`, `@warn`, `@debug` and
398393
`@error`. The `logging` function is also deprecated and replaced with
@@ -418,6 +413,15 @@ This section lists changes that do not have deprecation warnings.
418413
* `findn(x::AbstractArray)` has been deprecated in favor of `findall(!iszero, x)`, which
419414
now returns cartesian indices for multidimensional arrays (see below, [#25532]).
420415

416+
* Broadcasting operations are no longer fused into a single operation by Julia's parser.
417+
Instead, a lazy `Broadcasted` object is created to represent the fused expression and
418+
then realized with `copy(bc::Broadcasted)` or `copyto!(dest, bc::Broadcasted)`
419+
to evaluate the wrapper. Consequently, package authors generally need to specialize
420+
`copy` and `copyto!` methods rather than `broadcast` and `broadcast!`. This also allows
421+
for more customization and control of fused broadcasts. See the
422+
[Interfaces chapter](https://docs.julialang.org/en/latest/manual/interfaces/#man-interfaces-broadcasting-1)
423+
for more information.
424+
421425
* `find` has been renamed to `findall`. `findall`, `findfirst`, `findlast`, `findnext`
422426
now take and/or return the same type of indices as `keys`/`pairs` for `AbstractArray`,
423427
`AbstractDict`, `AbstractString`, `Tuple` and `NamedTuple` objects ([#24774], [#25545]).

base/bitarray.jl

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,20 +1095,6 @@ function (-)(B::BitArray)
10951095
end
10961096
return A
10971097
end
1098-
broadcast(::typeof(sign), B::BitArray) = copy(B)
1099-
1100-
function broadcast(::typeof(~), B::BitArray)
1101-
C = similar(B)
1102-
Bc = B.chunks
1103-
if !isempty(Bc)
1104-
Cc = C.chunks
1105-
for i = 1:length(Bc)
1106-
Cc[i] = ~Bc[i]
1107-
end
1108-
Cc[end] &= _msk_end(B)
1109-
end
1110-
return C
1111-
end
11121098

11131099
"""
11141100
flipbits!(B::BitArray{N}) -> BitArray{N}
@@ -1166,33 +1152,6 @@ end
11661152
(/)(B::BitArray, x::Number) = (/)(Array(B), x)
11671153
(/)(x::Number, B::BitArray) = (/)(x, Array(B))
11681154

1169-
# broadcast specializations for &, |, and xor/⊻
1170-
broadcast(::typeof(&), B::BitArray, x::Bool) = x ? copy(B) : falses(size(B))
1171-
broadcast(::typeof(&), x::Bool, B::BitArray) = broadcast(&, B, x)
1172-
broadcast(::typeof(|), B::BitArray, x::Bool) = x ? trues(size(B)) : copy(B)
1173-
broadcast(::typeof(|), x::Bool, B::BitArray) = broadcast(|, B, x)
1174-
broadcast(::typeof(xor), B::BitArray, x::Bool) = x ? .~B : copy(B)
1175-
broadcast(::typeof(xor), x::Bool, B::BitArray) = broadcast(xor, B, x)
1176-
for f in (:&, :|, :xor)
1177-
@eval begin
1178-
function broadcast(::typeof($f), A::BitArray, B::BitArray)
1179-
F = BitArray(undef, promote_shape(size(A),size(B))...)
1180-
Fc = F.chunks
1181-
Ac = A.chunks
1182-
Bc = B.chunks
1183-
(isempty(Ac) || isempty(Bc)) && return F
1184-
for i = 1:length(Fc)
1185-
Fc[i] = ($f)(Ac[i], Bc[i])
1186-
end
1187-
Fc[end] &= _msk_end(F)
1188-
return F
1189-
end
1190-
broadcast(::typeof($f), A::DenseArray{Bool}, B::BitArray) = broadcast($f, BitArray(A), B)
1191-
broadcast(::typeof($f), B::BitArray, A::DenseArray{Bool}) = broadcast($f, B, BitArray(A))
1192-
end
1193-
end
1194-
1195-
11961155
## promotion to complex ##
11971156

11981157
# TODO?

0 commit comments

Comments
 (0)