Skip to content

Commit d057b36

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

23 files changed

+80
-82
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/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

base/deprecated.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,12 @@ function SymTridiagonal(dv::AbstractVector{T}, ev::AbstractVector{S}) where {T,S
16151615
SymTridiagonal(convert(Vector{R}, dv), convert(Vector{R}, ev))
16161616
end
16171617

1618+
# PR #22932
1619+
@deprecate +(a::Number, b::AbstractArray) a .+ b
1620+
@deprecate +(a::AbstractArray, b::Number) a .+ b
1621+
@deprecate -(a::Number, b::AbstractArray) a .- b
1622+
@deprecate -(a::AbstractArray, b::Number) a .- b
1623+
16181624
# END 0.7 deprecations
16191625

16201626
# BEGIN 1.0 deprecations

base/linalg/symmetric.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ A_mul_Bt(A::AbstractTriangular, B::RealHermSymComplexSym) = A*B
321321
Ac_mul_B(A::RealHermSymComplexHerm, B::AbstractTriangular) = A*B
322322
A_mul_Bc(A::AbstractTriangular, B::RealHermSymComplexHerm) = A*B
323323

324-
for T in (:Symmetric, :Hermitian), op in (:+, :-, :*, :/)
324+
for T in (:Symmetric, :Hermitian), op in (:*, :/)
325325
# Deal with an ambiguous case
326326
@eval ($op)(A::$T, x::Bool) = ($T)(($op)(A.data, x), Symbol(A.uplo))
327327
S = T == :Hermitian ? :Real : :Number

base/random.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ srand(r::MersenneTwister, n::Integer) = srand(r, make_seed(n))
275275

276276
function dsfmt_gv_srand()
277277
# Temporary fix for #8874 and #9124: update global RNG for Rmath
278-
dsfmt_gv_init_by_array(GLOBAL_RNG.seed+UInt32(1))
278+
dsfmt_gv_init_by_array(GLOBAL_RNG.seed .+ UInt32(1))
279279
return GLOBAL_RNG
280280
end
281281

base/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ function print_matrix(io::IO, X::AbstractVecOrMat,
15741574
print(io, i == first(rowsA) ? pre : presp)
15751575
print_matrix_row(io, X,Lalign,i,colsA[1:length(Lalign)],sep)
15761576
print(io, (i - first(rowsA)) % hmod == 0 ? hdots : repeat(" ", length(hdots)))
1577-
print_matrix_row(io, X,Ralign,i,n-length(Ralign)+colsA,sep)
1577+
print_matrix_row(io, X, Ralign, i, (n - length(Ralign)) .+ colsA, sep)
15781578
print(io, i == last(rowsA) ? post : postsp)
15791579
if i != last(rowsA); println(io); end
15801580
end

base/sparse/cholmod.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ end
811811
function get_perm(F::Factor)
812812
s = unsafe_load(pointer(F))
813813
p = unsafe_wrap(Array, s.Perm, s.n, false)
814-
p + 1
814+
p .+ 1
815815
end
816816
get_perm(FC::FactorComponent) = get_perm(Factor(FC))
817817

base/sparse/sparsevector.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ function sort(x::SparseVector{Tv,Ti}; kws...) where {Tv,Ti}
19131913
n,k = length(x),length(allvals)
19141914
z = findfirst(sinds,k)
19151915
newnzind = collect(Ti,1:k-1)
1916-
newnzind[z:end]+= n-k+1
1916+
newnzind[z:end] .+= n-k+1
19171917
newnzvals = allvals[deleteat!(sinds[1:k],z)]
19181918
SparseVector(n,newnzind,newnzvals)
19191919
end

test/arrayops.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,21 +1647,21 @@ end
16471647

16481648
@testset "binary ops on bool arrays" begin
16491649
A = Array(trues(5))
1650-
@test A + true == [2,2,2,2,2]
1650+
@test A .+ true == [2,2,2,2,2]
16511651
A = Array(trues(5))
1652-
@test A + false == [1,1,1,1,1]
1652+
@test A .+ false == [1,1,1,1,1]
16531653
A = Array(trues(5))
1654-
@test true + A == [2,2,2,2,2]
1654+
@test true .+ A == [2,2,2,2,2]
16551655
A = Array(trues(5))
1656-
@test false + A == [1,1,1,1,1]
1656+
@test false .+ A == [1,1,1,1,1]
16571657
A = Array(trues(5))
1658-
@test A - true == [0,0,0,0,0]
1658+
@test A .- true == [0,0,0,0,0]
16591659
A = Array(trues(5))
1660-
@test A - false == [1,1,1,1,1]
1660+
@test A .- false == [1,1,1,1,1]
16611661
A = Array(trues(5))
1662-
@test true - A == [0,0,0,0,0]
1662+
@test true .- A == [0,0,0,0,0]
16631663
A = Array(trues(5))
1664-
@test false - A == [-1,-1,-1,-1,-1]
1664+
@test false .- A == [-1,-1,-1,-1,-1]
16651665
end
16661666

16671667
@testset "simple transposes" begin
@@ -1717,8 +1717,8 @@ module RetTypeDecl
17171717
broadcast(::typeof(*), x::MeterUnits{T,1}, y::MeterUnits{T,1}) where {T} = MeterUnits{T,2}(x.val*y.val)
17181718
convert(::Type{MeterUnits{T,pow}}, y::Real) where {T,pow} = MeterUnits{T,pow}(convert(T,y))
17191719

1720-
@test @inferred(m+[m,m]) == [m+m,m+m]
1721-
@test @inferred([m,m]+m) == [m+m,m+m]
1720+
@test @inferred(m .+ [m,m]) == [m+m,m+m]
1721+
@test @inferred([m,m] .+ m) == [m+m,m+m]
17221722
@test @inferred(broadcast(*,m,[m,m])) == [m2,m2]
17231723
@test @inferred(broadcast(*,[m,m],m)) == [m2,m2]
17241724
@test @inferred([m 2m; m m]*[m,m]) == [3m2,2m2]
@@ -1824,7 +1824,7 @@ copy!(S, A)
18241824
@test flipdim(A, 1) == flipdim(B, 1) == flipdim(S, 2)
18251825
@test flipdim(A, 2) == flipdim(B, 2) == flipdim(S, 2)
18261826

1827-
@test A + 1 == B + 1 == S + 1
1827+
@test A .+ 1 == B .+ 1 == S .+ 1
18281828
@test 2*A == 2*B == 2*S
18291829
@test A/3 == B/3 == S/3
18301830

@@ -1929,7 +1929,7 @@ end
19291929

19301930
#issue #18336
19311931
@test cumsum([-0.0, -0.0])[1] === cumsum([-0.0, -0.0])[2] === -0.0
1932-
@test cumprod(-0.0im + (0:0))[1] === Complex(0.0, -0.0)
1932+
@test cumprod(-0.0im .+ (0:0))[1] === Complex(0.0, -0.0)
19331933

19341934
module TestNLoops15895
19351935

test/broadcast.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ let A = [sqrt(i)+j for i = 1:3, j=1:4]
216216
@test atan2.(log.(A), sum(A,1)) == broadcast(atan2, broadcast(log, A), sum(A, 1))
217217
end
218218
let x = sin.(1:10)
219-
@test atan2.((x->x+1).(x), (x->x+2).(x)) == broadcast(atan2, x+1, x+2) == broadcast(atan2, x.+1, x.+2)
220-
@test sin.(atan2.([x+1,x+2]...)) == sin.(atan2.(x+1,x+2)) == @. sin(atan2(x+1,x+2))
219+
@test atan2.((x->x+1).(x), (x->x+2).(x)) == broadcast(atan2, x.+1, x.+2)
220+
@test sin.(atan2.([x.+1,x.+2]...)) == sin.(atan2.(x.+1 ,x.+2)) == @. sin(atan2(x+1,x+2))
221221
@test sin.(atan2.(x, 3.7)) == broadcast(x -> sin(atan2(x,3.7)), x)
222222
@test atan2.(x, 3.7) == broadcast(x -> atan2(x,3.7), x) == broadcast(atan2, x, 3.7)
223223
end
@@ -406,7 +406,6 @@ end
406406
@test (-).(C_NULL, C_NULL)::UInt == 0
407407
@test (+).(1, Ref(2)) == fill(3)
408408
@test (+).(Ref(1), Ref(2)) == fill(3)
409-
@test (+).([[0,2], [1,3]], [1,-1]) == [[1,3], [0,2]]
410409
@test (+).([[0,2], [1,3]], Ref{Vector{Int}}([1,-1])) == [[1,1], [2,2]]
411410

412411
# Check that broadcast!(f, A) populates A via independent calls to f (#12277, #19722),

test/complex.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,8 @@ end
897897
@testset "round and float, PR #8291" begin
898898
@test round(Complex(1.125, 0.875), 2) == Complex(1.12, 0.88)
899899
@test round(Complex(1.5, 0.5), RoundDown, RoundUp) == Complex(1.0, 1.0)
900-
@test round.([1:5;] + im) == [1:5;] + im
901-
@test round.([1:5;] + 0.5im) == [1.0:5.0;]
900+
@test round.([1:5;] .+ im) == [1:5;] .+ im
901+
@test round.([1:5;] .+ 0.5im) == [1.0:5.0;]
902902

903903
@test float(Complex(1, 2)) == Complex(1.0, 2.0)
904904
@test round(float(Complex(π, e)),3) == Complex(3.142, 2.718)

test/dates/periods.jl

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929

3030
t = Dates.Year(1)
3131
t2 = Dates.Year(2)
32-
@test ([t, t, t, t, t] + Dates.Year(1)) == ([t2, t2, t2, t2, t2])
33-
@test (Dates.Year(1) + [t, t, t, t, t]) == ([t2, t2, t2, t2, t2])
34-
@test ([t2, t2, t2, t2, t2] - Dates.Year(1)) == ([t, t, t, t, t])
32+
@test ([t, t, t, t, t] .+ Dates.Year(1)) == ([t2, t2, t2, t2, t2])
33+
@test (Dates.Year(1) .+ [t, t, t, t, t]) == ([t2, t2, t2, t2, t2])
34+
@test ([t2, t2, t2, t2, t2] .- Dates.Year(1)) == ([t, t, t, t, t])
3535
@test_throws MethodError ([t, t, t, t, t] .* Dates.Year(1)) == ([t, t, t, t, t])
3636
@test ([t, t, t, t, t] * 1) == ([t, t, t, t, t])
3737
@test ([t, t, t, t, t] .% t2) == ([t, t, t, t, t])
@@ -352,15 +352,15 @@ cpa = [1y + 1s 1m + 1s 1w + 1s 1d + 1s; 1h + 1s 1mi + 1s 2m + 1s 1s + 1ms]
352352
@test cpa .+ 1y == [2y + 1s 1y + 1m + 1s 1y + 1w + 1s 1y + 1d + 1s; 1y + 1h + 1s 1y + 1mi + 1s 1y + 2m + 1s 1y + 1ms + 1s]
353353
@test cpa .+ (1y + 1m) == [2y + 1m + 1s 1y + 2m + 1s 1y + 1m + 1w + 1s 1y + 1m + 1d + 1s; 1y + 1m + 1h + 1s 1y + 1m + 1mi + 1s 1y + 3m + 1s 1y + 1m + 1s + 1ms]
354354

355-
@test 1y + pa == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
356-
@test (1y + 1m) + pa == [2y + 1m 1y + 2m 1y + 1m + 1w 1y + 1m + 1d; 1y + 1m + 1h 1y + 1m + 1mi 1y + 1m + 1s 1y + 1m + 1ms]
357-
@test pa + 1y == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
358-
@test pa + (1y + 1m) == [2y + 1m 1y + 2m 1y + 1m + 1w 1y + 1m + 1d; 1y + 1m + 1h 1y + 1m + 1mi 1y + 1m + 1s 1y + 1m + 1ms]
355+
@test 1y .+ pa == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
356+
@test (1y + 1m) .+ pa == [2y + 1m 1y + 2m 1y + 1m + 1w 1y + 1m + 1d; 1y + 1m + 1h 1y + 1m + 1mi 1y + 1m + 1s 1y + 1m + 1ms]
357+
@test pa .+ 1y == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
358+
@test pa .+ (1y + 1m) == [2y + 1m 1y + 2m 1y + 1m + 1w 1y + 1m + 1d; 1y + 1m + 1h 1y + 1m + 1mi 1y + 1m + 1s 1y + 1m + 1ms]
359359

360-
@test 1y + cpa == [2y + 1s 1y + 1m + 1s 1y + 1w + 1s 1y + 1d + 1s; 1y + 1h + 1s 1y + 1mi + 1s 1y + 2m + 1s 1y + 1ms + 1s]
361-
@test (1y + 1m) + cpa == [2y + 1m + 1s 1y + 2m + 1s 1y + 1m + 1w + 1s 1y + 1m + 1d + 1s; 1y + 1m + 1h + 1s 1y + 1m + 1mi + 1s 1y + 3m + 1s 1y + 1m + 1s + 1ms]
362-
@test cpa + 1y == [2y + 1s 1y + 1m + 1s 1y + 1w + 1s 1y + 1d + 1s; 1y + 1h + 1s 1y + 1mi + 1s 1y + 2m + 1s 1y + 1ms + 1s]
363-
@test cpa + (1y + 1m) == [2y + 1m + 1s 1y + 2m + 1s 1y + 1m + 1w + 1s 1y + 1m + 1d + 1s; 1y + 1m + 1h + 1s 1y + 1m + 1mi + 1s 1y + 3m + 1s 1y + 1m + 1s + 1ms]
360+
@test 1y .+ cpa == [2y + 1s 1y + 1m + 1s 1y + 1w + 1s 1y + 1d + 1s; 1y + 1h + 1s 1y + 1mi + 1s 1y + 2m + 1s 1y + 1ms + 1s]
361+
@test (1y + 1m) .+ cpa == [2y + 1m + 1s 1y + 2m + 1s 1y + 1m + 1w + 1s 1y + 1m + 1d + 1s; 1y + 1m + 1h + 1s 1y + 1m + 1mi + 1s 1y + 3m + 1s 1y + 1m + 1s + 1ms]
362+
@test cpa .+ 1y == [2y + 1s 1y + 1m + 1s 1y + 1w + 1s 1y + 1d + 1s; 1y + 1h + 1s 1y + 1mi + 1s 1y + 2m + 1s 1y + 1ms + 1s]
363+
@test cpa .+ (1y + 1m) == [2y + 1m + 1s 1y + 2m + 1s 1y + 1m + 1w + 1s 1y + 1m + 1d + 1s; 1y + 1m + 1h + 1s 1y + 1m + 1mi + 1s 1y + 3m + 1s 1y + 1m + 1s + 1ms]
364364

365365
@test 1y .- pa == [0y 1y-1m 1y-1w 1y-1d; 1y-1h 1y-1mi 1y-1s 1y-1ms]
366366
@test (1y + 1m) .- pa == [1m 1y 1y + 1m-1w 1y + 1m-1d; 1y + 1m-1h 1y + 1m-1mi 1y + 1m-1s 1y + 1m-1ms]
@@ -372,16 +372,6 @@ cpa = [1y + 1s 1m + 1s 1w + 1s 1d + 1s; 1h + 1s 1mi + 1s 2m + 1s 1s + 1ms]
372372
@test cpa .- 1y == [1s -1y + 1m + 1s -1y + 1w + 1s -1y + 1d + 1s; -1y + 1h + 1s -1y + 1mi + 1s -1y + 2m + 1s -1y + 1ms + 1s]
373373
@test cpa .- (1y + 1m) == [-1m + 1s -1y + 1s -1y-1m + 1w + 1s -1y-1m + 1d + 1s; -1y-1m + 1h + 1s -1y-1m + 1mi + 1s -1y + 1m + 1s -1y + -1m + 1s + 1ms]
374374

375-
@test 1y - pa == [0y 1y-1m 1y-1w 1y-1d; 1y-1h 1y-1mi 1y-1s 1y-1ms]
376-
@test (1y + 1m) - pa == [1m 1y 1y + 1m-1w 1y + 1m-1d; 1y + 1m-1h 1y + 1m-1mi 1y + 1m-1s 1y + 1m-1ms]
377-
@test pa - (1y + 1m) == [-1m -1y -1y-1m + 1w -1y-1m + 1d; -1y-1m + 1h -1y-1m + 1mi -1y-1m + 1s -1y-1m + 1ms]
378-
@test pa - 1y == [0y 1m-1y -1y + 1w -1y + 1d; -1y + 1h -1y + 1mi -1y + 1s -1y + 1ms]
379-
380-
@test 1y - cpa == [-1s 1y-1m-1s 1y-1w-1s 1y-1d-1s; 1y-1h-1s 1y-1mi-1s 1y-2m-1s 1y-1ms-1s]
381-
@test (1y + 1m) - cpa == [1m-1s 1y-1s 1y + 1m-1w-1s 1y + 1m-1d-1s; 1y + 1m-1h-1s 1y + 1m-1mi-1s 1y-1m-1s 1y + 1m-1s-1ms]
382-
@test cpa - 1y == [1s -1y + 1m + 1s -1y + 1w + 1s -1y + 1d + 1s; -1y + 1h + 1s -1y + 1mi + 1s -1y + 2m + 1s -1y + 1ms + 1s]
383-
@test cpa - (1y + 1m) == [-1m + 1s -1y + 1s -1y-1m + 1w + 1s -1y-1m + 1d + 1s; -1y-1m + 1h + 1s -1y-1m + 1mi + 1s -1y + 1m + 1s -1y + -1m + 1s + 1ms]
384-
385375
@test [1y 1m; 1w 1d] + [1h 1mi; 1s 1ms] == [1y + 1h 1m + 1mi; 1w + 1s 1d + 1ms]
386376
@test [1y 1m; 1w 1d] - [1h 1mi; 1s 1ms] == [1y-1h 1m-1mi; 1w-1s 1d-1ms]
387377
@test [1y 1m; 1w 1d] - [1h 1mi; 1s 1ms] - [1y-1h 1m-1mi; 1w-1s 1d-1ms] == [emptyperiod emptyperiod; emptyperiod emptyperiod]

test/hashing.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ types = Any[
88
]
99
vals = vcat(
1010
typemin(Int64),
11-
-Int64(maxintfloat(Float64))+Int64[-4:1;],
11+
-Int64(maxintfloat(Float64)) .+ Int64[-4:1;],
1212
typemin(Int32),
13-
-Integer(maxintfloat(Float32))+(-4:1),
13+
-Integer(maxintfloat(Float32)) .+ (-4:1),
1414
-2:2,
15-
Integer(maxintfloat(Float32))+(-1:4),
15+
Integer(maxintfloat(Float32)) .+ (-1:4),
1616
typemax(Int32),
17-
Int64(maxintfloat(Float64))+Int64[-1:4;],
17+
Int64(maxintfloat(Float64)) .+ Int64[-1:4;],
1818
typemax(Int64),
1919
)
2020

test/inference.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ tpara18457(::Type{A}) where {A<:AbstractMyType18457} = tpara18457(supertype(A))
537537
@test tpara18457(MyType18457{true}) === true
538538

539539
@testset "type inference error #19322" begin
540-
Y_19322 = reshape(round.(Int, abs.(randn(5*1000)))+1,1000,5)
540+
Y_19322 = reshape(round.(Int, abs.(randn(5*1000))) .+ 1, 1000, 5)
541541

542542
function FOO_19322(Y::AbstractMatrix; frac::Float64=0.3, nbins::Int=100, n_sims::Int=100)
543543
num_iters, num_chains = size(Y)

test/linalg/diagonal.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ end
271271
end
272272

273273
@testset "isposdef" begin
274-
@test isposdef(Diagonal(1.0 + rand(n)))
274+
@test isposdef(Diagonal(1.0 .+ rand(n)))
275275
@test !isposdef(Diagonal(-1.0 * rand(n)))
276276
end
277277

test/linalg/symmetric.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,12 @@ end
389389
@test Y - I == T([0 -1; -1 0])
390390
@test Y * I == Y
391391

392-
@test Y + 1 == T([2 0; 0 2])
393-
@test Y - 1 == T([0 -2; -2 0])
392+
@test Y .+ 1 == T([2 0; 0 2])
393+
@test Y .- 1 == T([0 -2; -2 0])
394394
@test Y * 2 == T([2 -2; -2 2])
395395
@test Y / 1 == Y
396396

397-
@test T([true false; false true]) + true == T([2 1; 1 2])
397+
@test T([true false; false true]) .+ true == T([2 1; 1 2])
398398
end
399399

400400
@test_throws ArgumentError Hermitian(X) + 2im*I
@@ -424,8 +424,8 @@ end
424424
@testset "inversion of Hilbert matrix" begin
425425
for T in (Float64, Complex128)
426426
H = T[1/(i + j - 1) for i in 1:8, j in 1:8]
427-
@test norm(inv(Symmetric(H))*(H*ones(8))-1) 0 atol = 1e-5
428-
@test norm(inv(Hermitian(H))*(H*ones(8))-1) 0 atol = 1e-5
427+
@test norm(inv(Symmetric(H))*(H*ones(8)) .- 1) 0 atol = 1e-5
428+
@test norm(inv(Hermitian(H))*(H*ones(8)) .- 1) 0 atol = 1e-5
429429
end
430430
end
431431

test/offsetarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ v = OffsetArray(rand(8), (-2,))
383383
@test flipdim(A, 1) == OffsetArray(flipdim(parent(A), 1), A.offsets)
384384
@test flipdim(A, 2) == OffsetArray(flipdim(parent(A), 2), A.offsets)
385385

386-
@test A+1 == OffsetArray(parent(A)+1, A.offsets)
386+
@test A .+ 1 == OffsetArray(parent(A) .+ 1, A.offsets)
387387
@test 2*A == OffsetArray(2*parent(A), A.offsets)
388388
@test A+A == OffsetArray(parent(A)+parent(A), A.offsets)
389389
@test A.*A == OffsetArray(parent(A).*parent(A), A.offsets)

test/ranges.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ r7484 = 0.1:0.1:1
546546

547547
# issue #7387
548548
for r in (0:1, 0.0:1.0)
549-
@test [r+im;] == [r;]+im
550-
@test [r-im;] == [r;]-im
549+
@test [r .+ im;] == [r;] .+ im
550+
@test [r .- im;] == [r;] .- im
551551
@test [r*im;] == [r;]*im
552552
@test [r/im;] == [r;]/im
553553
end
@@ -710,13 +710,13 @@ function test_linspace_identity(r::Range{T}, mr) where T
710710
@test -collect(r) == collect(mr)
711711
@test isa(-r, typeof(r))
712712

713-
@test 1 + r + (-1) == r
714-
@test 1 + collect(r) == collect(1 + r) == collect(r + 1)
715-
@test isa(1 + r + (-1), typeof(r))
716-
@test 1 - r - 1 == mr
717-
@test 1 - collect(r) == collect(1 - r) == collect(1 + mr)
718-
@test collect(r) - 1 == collect(r - 1) == -collect(mr + 1)
719-
@test isa(1 - r - 1, typeof(r))
713+
@test 1 .+ r .+ (-1) == r
714+
@test 1 .+ collect(r) == collect(1 .+ r) == collect(r .+ 1)
715+
@test_broken isa(1 .+ r .+ (-1), typeof(r))
716+
@test 1 .- r .- 1 == mr
717+
@test 1 .- collect(r) == collect(1 .- r) == collect(1 .+ mr)
718+
@test collect(r) .- 1 == collect(r .- 1) == -collect(mr .+ 1)
719+
@test_broken isa(1 .- r .- 1, typeof(r))
720720

721721
@test 1 * r * 1 == r
722722
@test 2 * r * T(0.5) == r

test/reducedim.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ for region in Any[
3333
# With init=false
3434
r2 = similar(r)
3535
fill!(r, 1)
36-
@test sum!(r, Areduc, init=false) safe_sum(Areduc, region)+1
36+
@test sum!(r, Areduc, init=false) safe_sum(Areduc, region) .+ 1
3737
fill!(r, 2.2)
3838
@test prod!(r, Areduc, init=false) safe_prod(Areduc, region)*2.2
3939
fill!(r, 1.8)
4040
@test maximum!(r, Areduc, init=false) fill!(r2, 1.8)
4141
fill!(r, -0.2)
4242
@test minimum!(r, Areduc, init=false) fill!(r2, -0.2)
4343
fill!(r, 8.1)
44-
@test sum!(abs, r, Areduc, init=false) safe_sumabs(Areduc, region)+8.1
44+
@test sum!(abs, r, Areduc, init=false) safe_sumabs(Areduc, region) .+ 8.1
4545
fill!(r, 8.1)
46-
@test sum!(abs2, r, Areduc, init=false) safe_sumabs2(Areduc, region)+8.1
46+
@test sum!(abs2, r, Areduc, init=false) safe_sumabs2(Areduc, region) .+ 8.1
4747
fill!(r, 1.5)
4848
@test maximum!(abs, r, Areduc, init=false) fill!(r2, 1.5)
4949
fill!(r, -1.5)
@@ -71,11 +71,11 @@ r = fill(NaN, map(length, Base.reduced_indices(indices(Breduc), 1)))
7171
@test sum(abs2, Breduc, 1) safe_sumabs2(Breduc, 1)
7272

7373
fill!(r, 4.2)
74-
@test sum!(r, Breduc, init=false) safe_sum(Breduc, 1)+4.2
74+
@test sum!(r, Breduc, init=false) safe_sum(Breduc, 1) .+ 4.2
7575
fill!(r, -6.3)
76-
@test sum!(abs, r, Breduc, init=false) safe_sumabs(Breduc, 1)-6.3
76+
@test sum!(abs, r, Breduc, init=false) safe_sumabs(Breduc, 1) .- 6.3
7777
fill!(r, -1.1)
78-
@test sum!(abs2, r, Breduc, init=false) safe_sumabs2(Breduc, 1)-1.1
78+
@test sum!(abs2, r, Breduc, init=false) safe_sumabs2(Breduc, 1) .- 1.1
7979

8080
# Small arrays with init=false
8181
A = reshape(1:15, 3, 5)

0 commit comments

Comments
 (0)