Skip to content

Inference failure for typed concatenation #13254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GunnarFarneback opened this issue Sep 21, 2015 · 5 comments
Closed

Inference failure for typed concatenation #13254

GunnarFarneback opened this issue Sep 21, 2015 · 5 comments
Labels
potential benchmark Could make a good benchmark in BaseBenchmarks regression Regression in behavior compared to a previous version

Comments

@GunnarFarneback
Copy link
Contributor

The typed concatenation T[a:b] is deprecated in favor of T[a:b;]. However, the latter fails to infer result type correctly.

   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.0-rc2+10 (2015-09-20 15:38 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit d8930a0* (0 days old release-0.4)
|__/                   |  x86_64-linux-gnu

julia> f(n) = Float64[1:n]
f (generic function with 1 method)

julia> g(n) = Float64[1:n;]
g (generic function with 1 method)

julia> f(2)
WARNING: T[a:b] concatenation is deprecated; use T[a:b;] instead
 in depwarn at ./deprecated.jl:73
 in getindex at ./deprecated.jl:662
 in f at ./none:1
while loading no file, in expression starting on line 0
2-element Array{Float64,1}:
 1.0
 2.0

julia> g(2)
2-element Array{Float64,1}:
 1.0
 2.0

julia> Base.return_types(f, (Int,))
1-element Array{Any,1}:
 Array{Float64,1}

julia> Base.return_types(g, (Int,))
1-element Array{Any,1}:
 Array{Float64,N}
@GunnarFarneback
Copy link
Contributor Author

This is actually a regression from 0.3.

   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.10
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-linux-gnu

julia> g(n) = Float64[1:n;]
g (generic function with 1 method)

julia> Base.return_types(g, (Int,))
1-element Array{Any,1}:
 Array{Float64,1}

@GunnarFarneback
Copy link
Contributor Author

Let's widen the scope.

f1() = [1]
f2() = [1;]
f3() = [1;2]
f4() = [1;2.0]
f5() = [1 2]
f6() = [1 2.0]
f7() = Int[1]
f8() = Float64[1]
f9() = Int[1;]
f10() = Float64[1;]
f11() = Int[1;2]
f12() = Float64[1;2]
f13() = Int[1;2.0]
f14() = Int[1 2]
f15() = Float64[1 2]
f16() = Int[1 2.0]
f17() = [1:2;]
f18() = Int[1:2;]
f19() = Float64[1:2;]
f20() = [1:2;1:2]
f21() = Int[1:2;1:2]
f22() = Float64[1:2;1:2]
f23() = [1:2;1.0:2.0]
f24() = Int[1:2;1.0:2.0]
f25() = [1:2 1:2]
f26() = Int[1:2 1:2]
f27() = Float64[1:2 1:2]
f28() = [1:2 1.0:2.0]
f29() = Int[1:2 1.0:2.0]
const A = zeros(Int, 2, 2)
const B = zeros(Float64, 2, 2)
f30() = [A;]
f31() = Int[A;]
f32() = Float64[A;]
f33() = [A;A]
f34() = Int[A;A]
f35() = Float64[A;A]
f36() = [A;B]
f37() = Int[A;B]
f38() = [A A]
f39() = Int[A A]
f40() = Float64[A A]
f41() = [A B]
f42() = Int[A B]

for k = 1:42
    f = eval(symbol(string("f", k)))
    try
        f()
        println(k, " ", Base.return_types(f, ())[1])
    catch
        println(k, " error")
    end
end

Many of the result types are not concrete and some of them are regressions from 0.3.

0.3.10 0.4.0-rc2+31 Regression
1 Array{Int64,1} Array{Int64,1}
2 Array{Int64,1} Array{Int64,1}
3 Array{Int64,1} Array{Int64,1}
4 Array{T,1} Array{Float64,1}
5 Array{Int64,2} Array{Int64,2}
6 Array{T,2} Array{Float64,2}
7 Array{Int64,1} Array{Int64,1}
8 Array{Float64,1} Array{Float64,1}
9 Array{Int64,1} Any x
10 Array{Float64,1} Any x
11 Array{Int64,1} Any x
12 Array{Float64,1} Any x
13 Array{Int64,1} Any x
14 Array{Int64,2} Any x
15 Array{Float64,2} Any x
16 Array{Int64,2} Any x
17 Array{Int64,1} Array{Int64,1}
18 Array{Int64,1} Array{Int64,N} x
19 Array{Float64,1} Array{Float64,N} x
20 Array{Int64,1} Array{Int64,1}
21 Array{Int64,N} Array{Int64,N}
22 Array{Float64,N} Array{Float64,N}
23 Array{Float64,N} Array{Float64,N}
24 Array{Int64,N} Array{Int64,N}
25 Array{Int64,2} Array{Int64,2}
26 error Array{Int64,N}
27 error Array{Float64,N}
28 Array{Float64,N} Array{Float64,N}
29 error Array{Int64,N}
30 Array{Int64,2} Array{Int64,2}
31 error Array{Int64,N}
32 error Array{Float64,N}
33 Array{Int64,2} Array{Int64,2}
34 error Array{Int64,N}
35 error Array{Float64,N}
36 Array{Float64,N} Array{Float64,N}
37 error Array{Int64,N}
38 Array{Int64,2} Array{Int64,2}
39 error Array{Int64,N}
40 error Array{Float64,N}
41 Array{Float64,N} Array{Float64,N}
42 error Array{Int64,N}

@JeffBezanson JeffBezanson added the regression Regression in behavior compared to a previous version label Oct 21, 2015
@JeffBezanson
Copy link
Member

Thanks for the thorough analysis here.

@tkelman
Copy link
Contributor

tkelman commented Nov 7, 2015

Just a note for posterity (ref #13834 (comment)) that this change was responsible for a roughly 15% slowdown in the rand_mat_stat benchmark.

@KristofferC
Copy link
Member

Worth creating a separate issue for?

@tkelman tkelman added potential benchmark Could make a good benchmark in BaseBenchmarks and removed backport pending 0.4 labels Nov 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential benchmark Could make a good benchmark in BaseBenchmarks regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

4 participants