Skip to content

Commit

Permalink
Merge pull request #7226 from stevengj/array_+_scalar
Browse files Browse the repository at this point in the history
restore broadcasting array±scalar operations
  • Loading branch information
JeffBezanson committed Jun 17, 2014
2 parents 987eb73 + 3046190 commit cd36048
Show file tree
Hide file tree
Showing 3 changed files with 12 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
10 changes: 10 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,16 @@ for f in (:.+, :.-, :.*, :./, :.\, :.%, :div, :mod, :rem, :&, :|, :$)
end
end

# familiar aliases for broadcasting operations of array ± scalar (#7226):
(+)(A::AbstractArray{Bool},x::Bool) = A .+ x
(+)(x::Bool,A::AbstractArray{Bool}) = x .+ A
(-)(A::AbstractArray{Bool},x::Bool) = A .- x
(-)(x::Bool,A::AbstractArray{Bool}) = x .- A
(+)(A::AbstractArray,x::Number) = A .+ x
(+)(x::Number,A::AbstractArray) = x .+ A
(-)(A::AbstractArray,x::Number) = A .- x
(-)(x::Number,A::AbstractArray) = 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 cd36048

Please sign in to comment.