Skip to content

Commit

Permalink
deprecate syntax 1.+. fixes #19089
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jun 21, 2017
1 parent 2de5dab commit 4df4c25
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 34 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ New language features
Language changes
----------------

* The syntax `1.+2` is deprecated, since it is ambiguous: it could mean either
`1 .+ 2` (the current meaning) or `1. + 2` ([#19089]).

Breaking changes
----------------
Expand Down
2 changes: 1 addition & 1 deletion base/sparse/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ function normestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))))
end
end
end
scale!(X, 1./n)
scale!(X, 1 ./ n)

iter = 0
local est
Expand Down
8 changes: 7 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,13 @@
(if (eqv? (peek-char port) #\.)
(begin (read-char port)
(if (dot-opchar? (peek-char port))
(io.ungetc port #\.)
(begin
(if (not (eqv? (peek-char port) #\.))
(let ((num (get-output-string str)))
(syntax-deprecation port
(string num #\. (peek-char port))
(string num " ." (peek-char port)))))
(io.ungetc port #\.))
(begin (write-char #\. str)
(read-digs #f #t)
(if (eq? pred char-hex?)
Expand Down
38 changes: 19 additions & 19 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ using TestHelpers.OAs
@test length((1,)) == 1
@test length((1,2)) == 2

@test isequal(1.+[1,2,3], [2,3,4])
@test isequal([1,2,3].+1, [2,3,4])
@test isequal(1.-[1,2,3], [0,-1,-2])
@test isequal([1,2,3].-1, [0,1,2])
@test isequal(1 .+ [1,2,3], [2,3,4])
@test isequal([1,2,3] .+ 1, [2,3,4])
@test isequal(1 .- [1,2,3], [0,-1,-2])
@test isequal([1,2,3] .- 1, [0,1,2])

@test isequal(5*[1,2,3], [5,10,15])
@test isequal([1,2,3]*5, [5,10,15])
@test isequal(1./[1,2,5], [1.0,0.5,0.2])
@test isequal(1 ./ [1,2,5], [1.0,0.5,0.2])
@test isequal([1,2,3]/5, [0.2,0.4,0.6])

@test isequal(2.%[1,2,3], [0,0,2])
@test isequal([1,2,3].%2, [1,0,1])
@test isequal(2.÷[1,2,3], [2,1,0])
@test isequal([1,2,3].÷2, [0,1,1])
@test isequal(-2.%[1,2,3], [0,0,-2])
@test isequal(2 .% [1,2,3], [0,0,2])
@test isequal([1,2,3] .% 2, [1,0,1])
@test isequal(2 [1,2,3], [2,1,0])
@test isequal([1,2,3] 2, [0,1,1])
@test isequal(-2 .% [1,2,3], [0,0,-2])
@test isequal([-1,-2,-3].%2, [-1,0,-1])
@test isequal(-2.÷[1,2,3], [-2,-1,0])
@test isequal([-1,-2,-3].÷2, [0,-1,-1])

@test isequal(1.<<[1,2,5], [2,4,32])
@test isequal(128.>>[1,2,5], [64,32,4])
@test isequal(2.>>1, 1)
@test isequal(1.<<1, 2)
@test isequal([1,2,5].<<[1,2,5], [2,8,160])
@test isequal([10,20,50].>>[1,2,5], [5,5,1])
@test isequal(-2 [1,2,3], [-2,-1,0])
@test isequal([-1,-2,-3] 2, [0,-1,-1])

@test isequal(1 .<< [1,2,5], [2,4,32])
@test isequal(128 .>> [1,2,5], [64,32,4])
@test isequal(2 .>> 1, 1)
@test isequal(1 .<< 1, 2)
@test isequal([1,2,5] .<< [1,2,5], [2,8,160])
@test isequal([10,20,50] .>> [1,2,5], [5,5,1])


a = ones(2,2)
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ end

# Against vectorized versions
@test norm(x,-Inf) minimum(abs.(x))
@test norm(x,-1) inv(sum(1./abs.(x)))
@test norm(x,-1) inv(sum(1 ./ abs.(x)))
@test norm(x,0) sum(x .!= 0)
@test norm(x,1) sum(abs.(x))
@test norm(x) sqrt(sum(abs2.(x)))
Expand Down Expand Up @@ -362,7 +362,7 @@ end

## Issue related tests
@testset "issue #1447" begin
A = [1.+0.0im 0; 0 1]
A = [1.0+0.0im 0; 0 1]
B = pinv(A)
for i = 1:4
@test A[i] B[i]
Expand Down
6 changes: 3 additions & 3 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ end
# issue #9684
let
undot(op) = Symbol(string(op)[2:end])
for (ex1, ex2) in [("5.≠x", "5.!=x"),
("5.≥x", "5.>=x"),
("5.≤x", "5.<=x")]
for (ex1, ex2) in [("5 .≠ x", "5 .!= x"),
("5 .≥ x", "5 .>= x"),
("5 .≤ x", "5 .<= x")]
ex1 = parse(ex1); ex2 = parse(ex2)
@test ex1.head === :call && (ex1.head === ex2.head)
@test ex1.args[2] === 5 && ex2.args[2] === 5
Expand Down
6 changes: 3 additions & 3 deletions test/perf/kernel/laplace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function laplace_iter_devec(u, dx2, dy2, Niter, N)
for iter = 1:Niter
for i = 2:N-1
for j = 2:N-1
uout[i,j] = ( (u[i-1,j]+u[i+1,j])*dy2 + (u[i,j-1]+u[i,j+1])*dx2 ) * (1./(2*(dx2+dy2)))
uout[i,j] = ( (u[i-1,j]+u[i+1,j])*dy2 + (u[i,j-1]+u[i,j+1])*dx2 ) * (1 ./ (2*(dx2+dy2)))
end
end
u, uout = uout, u
Expand All @@ -24,7 +24,7 @@ end

function laplace_iter_vec(u, dx2, dy2, Niter, N)
for i = 1:Niter
u[2:N-1, 2:N-1] = ((u[1:N-2, 2:N-1] + u[3:N, 2:N-1])*dy2 + (u[2:N-1,1:N-2] + u[2:N-1, 3:N])*dx2) * (1./ (2*(dx2+dy2)))
u[2:N-1, 2:N-1] = ((u[1:N-2, 2:N-1] + u[3:N, 2:N-1])*dy2 + (u[2:N-1,1:N-2] + u[2:N-1, 3:N])*dx2) * (1 ./ (2*(dx2+dy2)))
end
return u
end
Expand All @@ -40,7 +40,7 @@ end

function laplace_iter_vec_sub(u, dx2, dy2, Niter, N)
for i = 1:Niter
u[2:N-1, 2:N-1] = ((view(u, 1:N-2, 2:N-1) + view(u,3:N, 2:N-1))*dy2 + (view(u,2:N-1,1:N-2) + view(u,2:N-1, 3:N))*dx2) * (1./ (2*(dx2+dy2)))
u[2:N-1, 2:N-1] = ((view(u, 1:N-2, 2:N-1) + view(u,3:N, 2:N-1))*dy2 + (view(u,2:N-1,1:N-2) + view(u,2:N-1, 3:N))*dx2) * (1 ./ (2*(dx2+dy2)))
end
return u
end
Expand Down
2 changes: 1 addition & 1 deletion test/perf/kernel/raytracer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function Raytracer(levels, n, ss)
g = 0.
for dx in 0:1:(ss-1)
for dy in 0:1:(ss-1)
d = Vec(x+dx*1./ss-n/2., y+dy*1./ss-n/2., n*1.0)
d = Vec(x+dx*1.0/ss-n/2.0, y+dy*1.0/ss-n/2.0, n*1.0)
ray = Ray(Vec(0., 0., -4.0), unitize(d))
g += ray_trace(light, ray, scene)
end
Expand Down
2 changes: 1 addition & 1 deletion test/perf/micro/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function pisumvec()
s = 0.0
a = [1:10000]
for j = 1:500
s = sum(1./(a.^2))
s = sum(1 ./ (a.^2))
end
s
end
Expand Down
2 changes: 1 addition & 1 deletion test/perf/spell/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function spelltest(tests; bias=0, verbose=false)
end
end

return Dict("bad"=>bad, "n"=>n, "bias"=>bias, "pct"=>round(Int, 100. - 100.*bad/n),
return Dict("bad"=>bad, "n"=>n, "bias"=>bias, "pct"=>round(Int, 100. - 100. * bad/n),
"unknown"=>unknown, "secs"=>toc())
end

Expand Down
4 changes: 2 additions & 2 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,8 @@ end
@testset "logspace" begin
n = 10; a = 2; b = 4
# test default values; n = 50, base = 10
@test logspace(a, b) == logspace(a, b, 50) == 10.^linspace(a, b, 50)
@test logspace(a, b, n) == 10.^linspace(a, b, n)
@test logspace(a, b) == logspace(a, b, 50) == 10 .^ linspace(a, b, 50)
@test logspace(a, b, n) == 10 .^ linspace(a, b, n)
for base in (10, 2, e)
@test logspace(a, b, base=base) == logspace(a, b, 50, base=base) == base.^linspace(a, b, 50)
@test logspace(a, b, n, base=base) == base.^linspace(a, b, n)
Expand Down

0 comments on commit 4df4c25

Please sign in to comment.