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 7, 2017
1 parent ae17198 commit 2db93d0
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 106 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/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ function _cat(A, shape::NTuple{N}, catdims, X...) where N
for x in X
for i = 1:N
if concat[i]
inds[i] = offsets[i] + cat_indices(x, i)
inds[i] = broadcast(+, offsets[i], cat_indices(x, i))
offsets[i] += cat_size(x, i)
else
inds[i] = 1:shape[i]
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
11 changes: 11 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,17 @@ 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) broadcast(+, a, b)
@deprecate +(a::AbstractArray, b::Number) broadcast(+, a, b)
@deprecate -(a::Number, b::AbstractArray) broadcast(-, a, b)
@deprecate -(a::AbstractArray, b::Number) broadcast(-, a, b)

@deprecate +(a::GeneralPeriod, b::StridedArray{<:GeneralPeriod}) broadcast(+, a, b)
@deprecate +(a::StridedArray{<:GeneralPeriod}, b::GeneralPeriod) broadcast(+, a, b)
@deprecate -(a::GeneralPeriod, b::StridedArray{<:GeneralPeriod}) broadcast(-, a, b)
@deprecate -(a::StridedArray{<:GeneralPeriod}, b::GeneralPeriod) broadcast(-, 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
71 changes: 49 additions & 22 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -728,27 +728,6 @@ end
-(r::StepRangeLen) = StepRangeLen(-r.ref, -r.step, length(r), r.offset)
-(r::LinSpace) = LinSpace(-r.start, -r.stop, length(r))

+(x::Real, r::AbstractUnitRange) = range(x + first(r), length(r))
# For #18336 we need to prevent promotion of the step type:
+(x::Number, r::AbstractUnitRange) = range(x + first(r), step(r), length(r))
+(x::Number, r::Range) = (x+first(r)):step(r):(x+last(r))
function +(x::Number, r::StepRangeLen)
newref = x + r.ref
StepRangeLen{eltype(newref),typeof(newref),typeof(r.step)}(newref, r.step, length(r), r.offset)
end
function +(x::Number, r::LinSpace)
LinSpace(x + r.start, x + r.stop, r.len)
end
+(r::Range, x::Number) = x + r # assumes addition is commutative

-(x::Number, r::Range) = (x-first(r)):-step(r):(x-last(r))
-(x::Number, r::StepRangeLen) = +(x, -r)
function -(x::Number, r::LinSpace)
LinSpace(x - r.start, x - r.stop, r.len)
end

-(r::Range, x::Number) = +(-x, r)

*(x::Number, r::Range) = range(x*first(r), x*step(r), length(r))
*(x::Number, r::StepRangeLen) = StepRangeLen(x*r.ref, x*r.step, length(r), r.offset)
*(x::Number, r::LinSpace) = LinSpace(x * r.start, x * r.stop, r.len)
Expand All @@ -760,8 +739,53 @@ end
/(r::Range, x::Number) = range(first(r)/x, step(r)/x, length(r))
/(r::StepRangeLen, x::Number) = StepRangeLen(r.ref/x, r.step/x, length(r), r.offset)
/(r::LinSpace, x::Number) = LinSpace(r.start / x, r.stop / x, r.len)
# also, separate in case of noncommutative multiplication (division)
\(x::Number, r::Range) = range(x\first(r), x\step(r), x\length(r))
\(x::Number, r::StepRangeLen) = StepRangeLen(x\r.ref, x\r.step, length(r), r.offset)
\(x::Number, r::LinSpace) = LinSpace(x \ r.start, x \ r.stop, r.len)

## scalar-range broadcast operations ##

broadcast(::typeof(-), r::OrdinalRange) = range(-first(r), -step(r), length(r))
broadcast(::typeof(-), r::StepRangeLen) = StepRangeLen(-r.ref, -r.step, length(r), r.offset)
broadcast(::typeof(-), r::LinSpace) = LinSpace(-r.start, -r.stop, length(r))

/(x::Number, r::Range) = [ x/y for y=r ]
broadcast(::typeof(+), x::Real, r::AbstractUnitRange) = range(x + first(r), length(r))
# For #18336 we need to prevent promotion of the step type:
broadcast(::typeof(+), x::Number, r::AbstractUnitRange) = range(x + first(r), step(r), length(r))
broadcast(::typeof(+), x::Number, r::Range) = (x+first(r)):step(r):(x+last(r))
function broadcast(::typeof(+), x::Number, r::StepRangeLen)
newref = x + r.ref
StepRangeLen{eltype(newref),typeof(newref),typeof(r.step)}(newref, r.step, length(r), r.offset)
end
function broadcast(::typeof(+), x::Number, r::LinSpace)
LinSpace(x + r.start, x + r.stop, r.len)
end
broadcast(::typeof(+), r::Range, x::Number) = broadcast(+, x, r) # assumes addition is commutative

broadcast(::typeof(-), x::Number, r::Range) = (x-first(r)):-step(r):(x-last(r))
broadcast(::typeof(-), x::Number, r::StepRangeLen) = broadcast(+, x, -r)
function broadcast(::typeof(-), x::Number, r::LinSpace)
LinSpace(x - r.start, x - r.stop, r.len)
end

broadcast(::typeof(-), r::Range, x::Number) = broadcast(+, -x, r) # assumes addition is commutative

broadcast(::typeof(*), x::Number, r::Range) = range(x*first(r), x*step(r), length(r))
broadcast(::typeof(*), x::Number, r::StepRangeLen) = StepRangeLen(x*r.ref, x*r.step, length(r), r.offset)
broadcast(::typeof(*), x::Number, r::LinSpace) = LinSpace(x * r.start, x * r.stop, r.len)
# separate in case of noncommutative multiplication
broadcast(::typeof(*), r::Range, x::Number) = range(first(r)*x, step(r)*x, length(r))
broadcast(::typeof(*), r::StepRangeLen, x::Number) = StepRangeLen(r.ref*x, r.step*x, length(r), r.offset)
broadcast(::typeof(*), r::LinSpace, x::Number) = LinSpace(r.start * x, r.stop * x, r.len)

broadcast(::typeof(/), r::Range, x::Number) = range(first(r)/x, step(r)/x, length(r))
broadcast(::typeof(/), r::StepRangeLen, x::Number) = StepRangeLen(r.ref/x, r.step/x, length(r), r.offset)
broadcast(::typeof(/), r::LinSpace, x::Number) = LinSpace(r.start / x, r.stop / x, r.len)
# also, separate in case of noncommutative multiplication (division)
broadcast(::typeof(\), x::Number, r::Range) = range(x\first(r), x\step(r), x\length(r))
broadcast(::typeof(\), x::Number, r::StepRangeLen) = StepRangeLen(x\r.ref, x\r.step, length(r), r.offset)
broadcast(::typeof(\), x::Number, r::LinSpace) = LinSpace(x \ r.start, x \ r.stop, r.len)

# promote eltype if at least one container wouldn't change, otherwise join container types.
el_same(::Type{T}, a::Type{<:AbstractArray{T,n}}, b::Type{<:AbstractArray{T,n}}) where {T,n} = a
Expand Down Expand Up @@ -945,3 +969,6 @@ function +(r1::StepRangeLen{T,S}, r2::StepRangeLen{T,S}) where {T,S}
end

-(r1::StepRangeLen, r2::StepRangeLen) = +(r1, -r2)

broadcast(::typeof(+), r1::Range, r2::Range) = r1 + r2
broadcast(::typeof(-), r1::Range, r2::Range) = r1 - r2
2 changes: 1 addition & 1 deletion base/repl/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ function splice_buffer!(buf::IOBuffer, r::UnitRange{<:Integer}, ins::AbstractStr
elseif pos > last(r)
seek(buf, pos - length(r))
end
splice!(buf.data, r + 1, Vector{UInt8}(ins)) # position(), etc, are 0-indexed
splice!(buf.data, broadcast(+, r, 1), Vector{UInt8}(ins)) # position(), etc, are 0-indexed
buf.size = buf.size + sizeof(ins) - length(r)
seek(buf, position(buf) + sizeof(ins))
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
Loading

0 comments on commit 2db93d0

Please sign in to comment.