Skip to content

Commit 19987f6

Browse files
committed
restore broadcasting array±scalar operations (removed in JuliaLang#5810)
1 parent 6b5462f commit 19987f6

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

NEWS.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,7 @@ Library improvements
216216
the same length. This generalizes and replaces `normfro` ([#6057]),
217217
and `norm` is now type-stable ([#6056]).
218218

219-
* `+` and `-` now require the sizes of the arrays to be the
220-
same: the operations no longer do broadcasting. New
221-
`UniformScaling` matrix type and identity `I` constant (#5810).
219+
* New `UniformScaling` matrix type and identity `I` constant (#5810).
222220

223221
* None of the concrete matrix factorization types are exported from Base
224222
by default anymore.

base/array.jl

+11
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,17 @@ for f in (:.+, :.-, :.*, :./, :.\, :.%, :div, :mod, :rem, :&, :|, :$)
767767
end
768768
end
769769

770+
# convenient and familiar aliases for broadcasting operations
771+
# of array ± scalar:
772+
(+)(A::StridedArray{Bool},x::Bool) = A .+ x
773+
(+)(x::Bool,A::StridedArray{Bool}) = x .+ A
774+
(-)(A::StridedArray{Bool},x::Bool) = A .- x
775+
(-)(x::Bool,A::StridedArray{Bool}) = x .- A
776+
(+)(A::StridedArray,x::Number) = A .+ x
777+
(+)(x::Number,A::StridedArray) = x .+ A
778+
(-)(A::StridedArray,x::Number) = A .- x
779+
(-)(x::Number,A::StridedArray) = x .- A
780+
770781
# functions that should give an Int result for Bool arrays
771782
for f in (:.+, :.-)
772783
@eval begin

base/deprecated.jl

+1-10
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,7 @@ end
185185
@deprecate svdfact(A,thin) svdfact(A,thin=thin)
186186
@deprecate svdfact!(A,thin) svdfact(A,thin=thin)
187187
@deprecate svd(A,thin) svd(A,thin=thin)
188-
# Note: These methods need a more helpfull error message than a `NoMethodError`,
189-
# when the deprecation is removed
190-
@deprecate (+)(A::Array{Bool},x::Bool) A .+ x
191-
@deprecate (+)(x::Bool,A::Array{Bool}) x .+ A
192-
@deprecate (-)(A::Array{Bool},x::Bool) A .- x
193-
@deprecate (-)(x::Bool,A::Array{Bool}) x .- A
194-
@deprecate (+)(A::Array,x::Number) A .+ x
195-
@deprecate (+)(x::Number,A::Array) x .+ A
196-
@deprecate (-)(A::Array,x::Number) A .- x
197-
@deprecate (-)(x::Number,A::Array) x .- A
188+
198189
@deprecate (/)(x::Number,A::Array) x ./ A
199190
@deprecate (\)(A::Array,x::Number) A .\ x
200191

0 commit comments

Comments
 (0)