Skip to content

Commit

Permalink
restore broadcasting array±scalar operations (removed in JuliaLang#5810)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored and mauro3 committed Jun 19, 2014
1 parent 888dc04 commit cc53913
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 1 addition & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ Library improvements
the same length. This generalizes and replaces `normfro` ([#6057]),
and `norm` is now type-stable ([#6056]).

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

* None of the concrete matrix factorization types are exported from Base
by default anymore.
Expand Down
11 changes: 11 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,17 @@ for f in (:.+, :.-, :.*, :./, :.\, :.%, :div, :mod, :rem, :&, :|, :$)
end
end

# convenient and familiar aliases for broadcasting operations
# of array ± scalar:
(+)(A::StridedArray{Bool},x::Bool) = A .+ x
(+)(x::Bool,A::StridedArray{Bool}) = x .+ A
(-)(A::StridedArray{Bool},x::Bool) = A .- x
(-)(x::Bool,A::StridedArray{Bool}) = x .- A
(+)(A::StridedArray,x::Number) = A .+ x
(+)(x::Number,A::StridedArray) = x .+ A
(-)(A::StridedArray,x::Number) = A .- x
(-)(x::Number,A::StridedArray) = x .- A

# functions that should give an Int result for Bool arrays
for f in (:.+, :.-)
@eval begin
Expand Down
11 changes: 1 addition & 10 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,7 @@ end
@deprecate svdfact(A,thin) svdfact(A,thin=thin)
@deprecate svdfact!(A,thin) svdfact(A,thin=thin)
@deprecate svd(A,thin) svd(A,thin=thin)
# Note: These methods need a more helpfull error message than a `NoMethodError`,
# when the deprecation is removed
@deprecate (+)(A::Array{Bool},x::Bool) A .+ x
@deprecate (+)(x::Bool,A::Array{Bool}) x .+ A
@deprecate (-)(A::Array{Bool},x::Bool) A .- x
@deprecate (-)(x::Bool,A::Array{Bool}) x .- A
@deprecate (+)(A::Array,x::Number) A .+ x
@deprecate (+)(x::Number,A::Array) x .+ A
@deprecate (-)(A::Array,x::Number) A .- x
@deprecate (-)(x::Number,A::Array) x .- A

@deprecate (/)(x::Number,A::Array) x ./ A
@deprecate (\)(A::Array,x::Number) A .\ x

Expand Down

0 comments on commit cc53913

Please sign in to comment.