Skip to content

Commit c50c41c

Browse files
author
Andy Ferris
committed
Deprecate +/- methods for array+scalar etc
The elementwise definition is incorrect for linear algebra.
1 parent ae17198 commit c50c41c

26 files changed

+1327
-1302
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ Deprecated or removed
265265
* Calling `union` with no arguments is deprecated; construct an empty set with an appropriate
266266
element type using `Set{T}()` instead ([#23144]).
267267

268+
* Automatically broadcasted `+` and `-` for `array + scalar`, `scalar - array`, and so-on have
269+
been deprecated due to inconsistency with linear algebra. Use `.+` and `.-` for these operations
270+
instead.
271+
272+
268273
Julia v0.6.0 Release Notes
269274
==========================
270275

base/abstractarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ function _cat(A, shape::NTuple{N}, catdims, X...) where N
12561256
for x in X
12571257
for i = 1:N
12581258
if concat[i]
1259-
inds[i] = offsets[i] + cat_indices(x, i)
1259+
inds[i] = broadcast(+, offsets[i], cat_indices(x, i))
12601260
offsets[i] += cat_size(x, i)
12611261
else
12621262
inds[i] = 1:shape[i]

base/arraymath.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ for f in (:+, :-)
4040
end
4141
end
4242

43-
for f in (:/, :\, :*, :+, :-)
43+
for f in (:/, :\, :*)
4444
if f != :/
4545
@eval ($f)(A::Number, B::AbstractArray) = broadcast($f, A, B)
4646
end

base/dates/periods.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ GeneralPeriod = Union{Period, CompoundPeriod}
358358

359359
for op in (:+, :-)
360360
@eval begin
361-
($op)(x::GeneralPeriod, Y::StridedArray{<:GeneralPeriod}) = broadcast($op, x, Y)
362-
($op)(Y::StridedArray{<:GeneralPeriod}, x::GeneralPeriod) = broadcast($op, Y, x)
363361
($op)(X::StridedArray{<:GeneralPeriod}, Y::StridedArray{<:GeneralPeriod}) =
364362
reshape(CompoundPeriod[($op)(x, y) for (x, y) in zip(X, Y)], promote_shape(size(X), size(Y)))
365363
end

0 commit comments

Comments
 (0)