Skip to content
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

splitdims not type-stable #26

Closed
cossio opened this issue May 18, 2020 · 3 comments
Closed

splitdims not type-stable #26

cossio opened this issue May 18, 2020 · 3 comments

Comments

@cossio
Copy link

cossio commented May 18, 2020

julia> @code_warntype splitdims([1 2 3; 4 5 6], 1)
Variables
  #self#::Core.Compiler.Const(SplitApplyCombine.splitdims, false)
  a::Array{Int64,2}
  i::Int64
Body::Array{T,N} where T where N
1nothing%2 = Core.tuple(i)::Tuple{Int64}%3 = SplitApplyCombine.Val(%2)::Val{_A} where _A
│   %4 = SplitApplyCombine._splitdims(a, %3)::Array{T,N} where T where N
└──      return %4
@andyferris
Copy link
Member

Thanks @cossio. You had me concerned for a moment, but actually this a consequence of working at the REPL. To be type-stable that 1 argument needs to be constant propagated, which it will from code written in functions.

Check this out:

julia> f(a) = splitdims(a, 1)
f (generic function with 1 method)

julia> @code_warntype f([1 2 3; 4 5 6])
Variables
  #self#::Core.Compiler.Const(f, false)
  a::Array{Int64,2}

Body::Array{Array{Int64,1},1}
1%1 = Main.splitdims(a, 1)::Array{Array{Int64,1},1}
└──      return %1

@cossio
Copy link
Author

cossio commented May 19, 2020

I see, thanks for taking a look!

@andyferris
Copy link
Member

No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants