Skip to content

Commit

Permalink
Deprecate +/- methods for array+scalar etc
Browse files Browse the repository at this point in the history
The elementwise definition is incorrect for linear algebra.
  • Loading branch information
Andy Ferris committed Aug 6, 2017
1 parent ae17198 commit d057b36
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 82 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ Deprecated or removed
* Calling `union` with no arguments is deprecated; construct an empty set with an appropriate
element type using `Set{T}()` instead ([#23144]).

* Automatically broadcasted `+` and `-` for `array + scalar`, `scalar - array`, and so-on have
been deprecated due to inconsistency with linear algebra. Use `.+` and `.-` for these operations
instead.


Julia v0.6.0 Release Notes
==========================

Expand Down
2 changes: 1 addition & 1 deletion base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ for f in (:+, :-)
end
end

for f in (:/, :\, :*, :+, :-)
for f in (:/, :\, :*)
if f != :/
@eval ($f)(A::Number, B::AbstractArray) = broadcast($f, A, B)
end
Expand Down
2 changes: 0 additions & 2 deletions base/dates/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,6 @@ GeneralPeriod = Union{Period, CompoundPeriod}

for op in (:+, :-)
@eval begin
($op)(x::GeneralPeriod, Y::StridedArray{<:GeneralPeriod}) = broadcast($op, x, Y)
($op)(Y::StridedArray{<:GeneralPeriod}, x::GeneralPeriod) = broadcast($op, Y, x)
($op)(X::StridedArray{<:GeneralPeriod}, Y::StridedArray{<:GeneralPeriod}) =
reshape(CompoundPeriod[($op)(x, y) for (x, y) in zip(X, Y)], promote_shape(size(X), size(Y)))
end
Expand Down
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,12 @@ function SymTridiagonal(dv::AbstractVector{T}, ev::AbstractVector{S}) where {T,S
SymTridiagonal(convert(Vector{R}, dv), convert(Vector{R}, ev))
end

# PR #22932
@deprecate +(a::Number, b::AbstractArray) a .+ b
@deprecate +(a::AbstractArray, b::Number) a .+ b
@deprecate -(a::Number, b::AbstractArray) a .- b
@deprecate -(a::AbstractArray, b::Number) a .- b

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ A_mul_Bt(A::AbstractTriangular, B::RealHermSymComplexSym) = A*B
Ac_mul_B(A::RealHermSymComplexHerm, B::AbstractTriangular) = A*B
A_mul_Bc(A::AbstractTriangular, B::RealHermSymComplexHerm) = A*B

for T in (:Symmetric, :Hermitian), op in (:+, :-, :*, :/)
for T in (:Symmetric, :Hermitian), op in (:*, :/)
# Deal with an ambiguous case
@eval ($op)(A::$T, x::Bool) = ($T)(($op)(A.data, x), Symbol(A.uplo))
S = T == :Hermitian ? :Real : :Number
Expand Down
2 changes: 1 addition & 1 deletion base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ srand(r::MersenneTwister, n::Integer) = srand(r, make_seed(n))

function dsfmt_gv_srand()
# Temporary fix for #8874 and #9124: update global RNG for Rmath
dsfmt_gv_init_by_array(GLOBAL_RNG.seed+UInt32(1))
dsfmt_gv_init_by_array(GLOBAL_RNG.seed .+ UInt32(1))
return GLOBAL_RNG
end

Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ function print_matrix(io::IO, X::AbstractVecOrMat,
print(io, i == first(rowsA) ? pre : presp)
print_matrix_row(io, X,Lalign,i,colsA[1:length(Lalign)],sep)
print(io, (i - first(rowsA)) % hmod == 0 ? hdots : repeat(" ", length(hdots)))
print_matrix_row(io, X,Ralign,i,n-length(Ralign)+colsA,sep)
print_matrix_row(io, X, Ralign, i, (n - length(Ralign)) .+ colsA, sep)
print(io, i == last(rowsA) ? post : postsp)
if i != last(rowsA); println(io); end
end
Expand Down
2 changes: 1 addition & 1 deletion base/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ end
function get_perm(F::Factor)
s = unsafe_load(pointer(F))
p = unsafe_wrap(Array, s.Perm, s.n, false)
p + 1
p .+ 1
end
get_perm(FC::FactorComponent) = get_perm(Factor(FC))

Expand Down
2 changes: 1 addition & 1 deletion base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ function sort(x::SparseVector{Tv,Ti}; kws...) where {Tv,Ti}
n,k = length(x),length(allvals)
z = findfirst(sinds,k)
newnzind = collect(Ti,1:k-1)
newnzind[z:end]+= n-k+1
newnzind[z:end] .+= n-k+1
newnzvals = allvals[deleteat!(sinds[1:k],z)]
SparseVector(n,newnzind,newnzvals)
end
Expand Down
24 changes: 12 additions & 12 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1647,21 +1647,21 @@ end

@testset "binary ops on bool arrays" begin
A = Array(trues(5))
@test A + true == [2,2,2,2,2]
@test A .+ true == [2,2,2,2,2]
A = Array(trues(5))
@test A + false == [1,1,1,1,1]
@test A .+ false == [1,1,1,1,1]
A = Array(trues(5))
@test true + A == [2,2,2,2,2]
@test true .+ A == [2,2,2,2,2]
A = Array(trues(5))
@test false + A == [1,1,1,1,1]
@test false .+ A == [1,1,1,1,1]
A = Array(trues(5))
@test A - true == [0,0,0,0,0]
@test A .- true == [0,0,0,0,0]
A = Array(trues(5))
@test A - false == [1,1,1,1,1]
@test A .- false == [1,1,1,1,1]
A = Array(trues(5))
@test true - A == [0,0,0,0,0]
@test true .- A == [0,0,0,0,0]
A = Array(trues(5))
@test false - A == [-1,-1,-1,-1,-1]
@test false .- A == [-1,-1,-1,-1,-1]
end

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

@test @inferred(m+[m,m]) == [m+m,m+m]
@test @inferred([m,m]+m) == [m+m,m+m]
@test @inferred(m .+ [m,m]) == [m+m,m+m]
@test @inferred([m,m] .+ m) == [m+m,m+m]
@test @inferred(broadcast(*,m,[m,m])) == [m2,m2]
@test @inferred(broadcast(*,[m,m],m)) == [m2,m2]
@test @inferred([m 2m; m m]*[m,m]) == [3m2,2m2]
Expand Down Expand Up @@ -1824,7 +1824,7 @@ copy!(S, A)
@test flipdim(A, 1) == flipdim(B, 1) == flipdim(S, 2)
@test flipdim(A, 2) == flipdim(B, 2) == flipdim(S, 2)

@test A + 1 == B + 1 == S + 1
@test A .+ 1 == B .+ 1 == S .+ 1
@test 2*A == 2*B == 2*S
@test A/3 == B/3 == S/3

Expand Down Expand Up @@ -1929,7 +1929,7 @@ end

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

module TestNLoops15895

Expand Down
5 changes: 2 additions & 3 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ let A = [sqrt(i)+j for i = 1:3, j=1:4]
@test atan2.(log.(A), sum(A,1)) == broadcast(atan2, broadcast(log, A), sum(A, 1))
end
let x = sin.(1:10)
@test atan2.((x->x+1).(x), (x->x+2).(x)) == broadcast(atan2, x+1, x+2) == broadcast(atan2, x.+1, x.+2)
@test sin.(atan2.([x+1,x+2]...)) == sin.(atan2.(x+1,x+2)) == @. sin(atan2(x+1,x+2))
@test atan2.((x->x+1).(x), (x->x+2).(x)) == broadcast(atan2, x.+1, x.+2)
@test sin.(atan2.([x.+1,x.+2]...)) == sin.(atan2.(x.+1 ,x.+2)) == @. sin(atan2(x+1,x+2))
@test sin.(atan2.(x, 3.7)) == broadcast(x -> sin(atan2(x,3.7)), x)
@test atan2.(x, 3.7) == broadcast(x -> atan2(x,3.7), x) == broadcast(atan2, x, 3.7)
end
Expand Down Expand Up @@ -406,7 +406,6 @@ end
@test (-).(C_NULL, C_NULL)::UInt == 0
@test (+).(1, Ref(2)) == fill(3)
@test (+).(Ref(1), Ref(2)) == fill(3)
@test (+).([[0,2], [1,3]], [1,-1]) == [[1,3], [0,2]]
@test (+).([[0,2], [1,3]], Ref{Vector{Int}}([1,-1])) == [[1,1], [2,2]]

# Check that broadcast!(f, A) populates A via independent calls to f (#12277, #19722),
Expand Down
4 changes: 2 additions & 2 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,8 @@ end
@testset "round and float, PR #8291" begin
@test round(Complex(1.125, 0.875), 2) == Complex(1.12, 0.88)
@test round(Complex(1.5, 0.5), RoundDown, RoundUp) == Complex(1.0, 1.0)
@test round.([1:5;] + im) == [1:5;] + im
@test round.([1:5;] + 0.5im) == [1.0:5.0;]
@test round.([1:5;] .+ im) == [1:5;] .+ im
@test round.([1:5;] .+ 0.5im) == [1.0:5.0;]

@test float(Complex(1, 2)) == Complex(1.0, 2.0)
@test round(float(Complex(π, e)),3) == Complex(3.142, 2.718)
Expand Down
32 changes: 11 additions & 21 deletions test/dates/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

t = Dates.Year(1)
t2 = Dates.Year(2)
@test ([t, t, t, t, t] + Dates.Year(1)) == ([t2, t2, t2, t2, t2])
@test (Dates.Year(1) + [t, t, t, t, t]) == ([t2, t2, t2, t2, t2])
@test ([t2, t2, t2, t2, t2] - Dates.Year(1)) == ([t, t, t, t, t])
@test ([t, t, t, t, t] .+ Dates.Year(1)) == ([t2, t2, t2, t2, t2])
@test (Dates.Year(1) .+ [t, t, t, t, t]) == ([t2, t2, t2, t2, t2])
@test ([t2, t2, t2, t2, t2] .- Dates.Year(1)) == ([t, t, t, t, t])
@test_throws MethodError ([t, t, t, t, t] .* Dates.Year(1)) == ([t, t, t, t, t])
@test ([t, t, t, t, t] * 1) == ([t, t, t, t, t])
@test ([t, t, t, t, t] .% t2) == ([t, t, t, t, t])
Expand Down Expand Up @@ -352,15 +352,15 @@ cpa = [1y + 1s 1m + 1s 1w + 1s 1d + 1s; 1h + 1s 1mi + 1s 2m + 1s 1s + 1ms]
@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]
@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]

@test 1y + pa == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
@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]
@test pa + 1y == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
@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]
@test 1y .+ pa == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
@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]
@test pa .+ 1y == [2y 1y + 1m 1y + 1w 1y + 1d; 1y + 1h 1y + 1mi 1y + 1s 1y + 1ms]
@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]

@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]
@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]
@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]
@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]
@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]
@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]
@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]
@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]

@test 1y .- pa == [0y 1y-1m 1y-1w 1y-1d; 1y-1h 1y-1mi 1y-1s 1y-1ms]
@test (1y + 1m) .- pa == [1m 1y 1y + 1m-1w 1y + 1m-1d; 1y + 1m-1h 1y + 1m-1mi 1y + 1m-1s 1y + 1m-1ms]
Expand All @@ -372,16 +372,6 @@ cpa = [1y + 1s 1m + 1s 1w + 1s 1d + 1s; 1h + 1s 1mi + 1s 2m + 1s 1s + 1ms]
@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]
@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]

@test 1y - pa == [0y 1y-1m 1y-1w 1y-1d; 1y-1h 1y-1mi 1y-1s 1y-1ms]
@test (1y + 1m) - pa == [1m 1y 1y + 1m-1w 1y + 1m-1d; 1y + 1m-1h 1y + 1m-1mi 1y + 1m-1s 1y + 1m-1ms]
@test pa - (1y + 1m) == [-1m -1y -1y-1m + 1w -1y-1m + 1d; -1y-1m + 1h -1y-1m + 1mi -1y-1m + 1s -1y-1m + 1ms]
@test pa - 1y == [0y 1m-1y -1y + 1w -1y + 1d; -1y + 1h -1y + 1mi -1y + 1s -1y + 1ms]

@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]
@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]
@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]
@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]

@test [1y 1m; 1w 1d] + [1h 1mi; 1s 1ms] == [1y + 1h 1m + 1mi; 1w + 1s 1d + 1ms]
@test [1y 1m; 1w 1d] - [1h 1mi; 1s 1ms] == [1y-1h 1m-1mi; 1w-1s 1d-1ms]
@test [1y 1m; 1w 1d] - [1h 1mi; 1s 1ms] - [1y-1h 1m-1mi; 1w-1s 1d-1ms] == [emptyperiod emptyperiod; emptyperiod emptyperiod]
Expand Down
8 changes: 4 additions & 4 deletions test/hashing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ types = Any[
]
vals = vcat(
typemin(Int64),
-Int64(maxintfloat(Float64))+Int64[-4:1;],
-Int64(maxintfloat(Float64)) .+ Int64[-4:1;],
typemin(Int32),
-Integer(maxintfloat(Float32))+(-4:1),
-Integer(maxintfloat(Float32)) .+ (-4:1),
-2:2,
Integer(maxintfloat(Float32))+(-1:4),
Integer(maxintfloat(Float32)) .+ (-1:4),
typemax(Int32),
Int64(maxintfloat(Float64))+Int64[-1:4;],
Int64(maxintfloat(Float64)) .+ Int64[-1:4;],
typemax(Int64),
)

Expand Down
2 changes: 1 addition & 1 deletion test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ tpara18457(::Type{A}) where {A<:AbstractMyType18457} = tpara18457(supertype(A))
@test tpara18457(MyType18457{true}) === true

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

function FOO_19322(Y::AbstractMatrix; frac::Float64=0.3, nbins::Int=100, n_sims::Int=100)
num_iters, num_chains = size(Y)
Expand Down
2 changes: 1 addition & 1 deletion test/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ end
end

@testset "isposdef" begin
@test isposdef(Diagonal(1.0 + rand(n)))
@test isposdef(Diagonal(1.0 .+ rand(n)))
@test !isposdef(Diagonal(-1.0 * rand(n)))
end

Expand Down
10 changes: 5 additions & 5 deletions test/linalg/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,12 @@ end
@test Y - I == T([0 -1; -1 0])
@test Y * I == Y

@test Y + 1 == T([2 0; 0 2])
@test Y - 1 == T([0 -2; -2 0])
@test Y .+ 1 == T([2 0; 0 2])
@test Y .- 1 == T([0 -2; -2 0])
@test Y * 2 == T([2 -2; -2 2])
@test Y / 1 == Y

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ v = OffsetArray(rand(8), (-2,))
@test flipdim(A, 1) == OffsetArray(flipdim(parent(A), 1), A.offsets)
@test flipdim(A, 2) == OffsetArray(flipdim(parent(A), 2), A.offsets)

@test A+1 == OffsetArray(parent(A)+1, A.offsets)
@test A .+ 1 == OffsetArray(parent(A) .+ 1, A.offsets)
@test 2*A == OffsetArray(2*parent(A), A.offsets)
@test A+A == OffsetArray(parent(A)+parent(A), A.offsets)
@test A.*A == OffsetArray(parent(A).*parent(A), A.offsets)
Expand Down
18 changes: 9 additions & 9 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ r7484 = 0.1:0.1:1

# issue #7387
for r in (0:1, 0.0:1.0)
@test [r+im;] == [r;]+im
@test [r-im;] == [r;]-im
@test [r .+ im;] == [r;] .+ im
@test [r .- im;] == [r;] .- im
@test [r*im;] == [r;]*im
@test [r/im;] == [r;]/im
end
Expand Down Expand Up @@ -710,13 +710,13 @@ function test_linspace_identity(r::Range{T}, mr) where T
@test -collect(r) == collect(mr)
@test isa(-r, typeof(r))

@test 1 + r + (-1) == r
@test 1 + collect(r) == collect(1 + r) == collect(r + 1)
@test isa(1 + r + (-1), typeof(r))
@test 1 - r - 1 == mr
@test 1 - collect(r) == collect(1 - r) == collect(1 + mr)
@test collect(r) - 1 == collect(r - 1) == -collect(mr + 1)
@test isa(1 - r - 1, typeof(r))
@test 1 .+ r .+ (-1) == r
@test 1 .+ collect(r) == collect(1 .+ r) == collect(r .+ 1)
@test_broken isa(1 .+ r .+ (-1), typeof(r))
@test 1 .- r .- 1 == mr
@test 1 .- collect(r) == collect(1 .- r) == collect(1 .+ mr)
@test collect(r) .- 1 == collect(r .- 1) == -collect(mr .+ 1)
@test_broken isa(1 .- r .- 1, typeof(r))

@test 1 * r * 1 == r
@test 2 * r * T(0.5) == r
Expand Down
12 changes: 6 additions & 6 deletions test/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ for region in Any[
# With init=false
r2 = similar(r)
fill!(r, 1)
@test sum!(r, Areduc, init=false) safe_sum(Areduc, region)+1
@test sum!(r, Areduc, init=false) safe_sum(Areduc, region) .+ 1
fill!(r, 2.2)
@test prod!(r, Areduc, init=false) safe_prod(Areduc, region)*2.2
fill!(r, 1.8)
@test maximum!(r, Areduc, init=false) fill!(r2, 1.8)
fill!(r, -0.2)
@test minimum!(r, Areduc, init=false) fill!(r2, -0.2)
fill!(r, 8.1)
@test sum!(abs, r, Areduc, init=false) safe_sumabs(Areduc, region)+8.1
@test sum!(abs, r, Areduc, init=false) safe_sumabs(Areduc, region) .+ 8.1
fill!(r, 8.1)
@test sum!(abs2, r, Areduc, init=false) safe_sumabs2(Areduc, region)+8.1
@test sum!(abs2, r, Areduc, init=false) safe_sumabs2(Areduc, region) .+ 8.1
fill!(r, 1.5)
@test maximum!(abs, r, Areduc, init=false) fill!(r2, 1.5)
fill!(r, -1.5)
Expand Down Expand Up @@ -71,11 +71,11 @@ r = fill(NaN, map(length, Base.reduced_indices(indices(Breduc), 1)))
@test sum(abs2, Breduc, 1) safe_sumabs2(Breduc, 1)

fill!(r, 4.2)
@test sum!(r, Breduc, init=false) safe_sum(Breduc, 1)+4.2
@test sum!(r, Breduc, init=false) safe_sum(Breduc, 1) .+ 4.2
fill!(r, -6.3)
@test sum!(abs, r, Breduc, init=false) safe_sumabs(Breduc, 1)-6.3
@test sum!(abs, r, Breduc, init=false) safe_sumabs(Breduc, 1) .- 6.3
fill!(r, -1.1)
@test sum!(abs2, r, Breduc, init=false) safe_sumabs2(Breduc, 1)-1.1
@test sum!(abs2, r, Breduc, init=false) safe_sumabs2(Breduc, 1) .- 1.1

# Small arrays with init=false
A = reshape(1:15, 3, 5)
Expand Down
Loading

0 comments on commit d057b36

Please sign in to comment.