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

mapslices(f, d; dims=n) is type unstable #36022

Closed
lassepe opened this issue May 25, 2020 · 1 comment
Closed

mapslices(f, d; dims=n) is type unstable #36022

lassepe opened this issue May 25, 2020 · 1 comment
Labels
duplicate Indicates similar issues or pull requests

Comments

@lassepe
Copy link
Contributor

lassepe commented May 25, 2020

A call to mapslices that takes a dims argument is type unstable. This is the case in all recent versions of Julia (1.1.1, 1.2.0, 1.3.1, 1.4.2).

For example:

d = rand(10)
mapslices(identity, d; dims=1)

Shows the following with @code_warntype:

Variables
  #unused#::Core.Compiler.Const(getfield(Base, Symbol("#kw##mapslices"))(), false)
  @_2::NamedTuple{(:dims,),Tuple{Int64}}
  @_3::Core.Compiler.Const(mapslices, false)
  f::Core.Compiler.Const(identity, false)
  A::Array{Float64,1}
  dims::Int64
  @_7::Int64

Body::Any
1 ─ %1  = Base.haskey(@_2, :dims)::Core.Compiler.Const(true, false)
│         %1
│         (@_7 = Base.getindex(@_2, :dims))
└──       goto #3
2 ─       Core.Compiler.Const(:(Core.UndefKeywordError(:dims)), false)
└──       Core.Compiler.Const(:(@_7 = Core.throw(%5)), false)
3 ┄       (dims = @_7)
│   %8  = (:dims,)::Core.Compiler.Const((:dims,), false)
│   %9  = Core.apply_type(Core.NamedTuple, %8)::Core.Compiler.Const(NamedTuple{(:dims,),T} where T<:Tuple, false)
│   %10 = Base.structdiff(@_2, %9)::Core.Compiler.Const(NamedTuple(), false)
│   %11 = Base.pairs(%10)::Core.Compiler.Const(Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}(), false)
│   %12 = Base.isempty(%11)::Core.Compiler.Const(true, false)
│         %12
└──       goto #5
4 ─       Core.Compiler.Const(:(Base.kwerr(@_2, @_3, f, A)), false)
5 ┄ %16 = Base.:(#mapslices#111)(dims, @_3, f, A)::Any
└──       return %16

Due to this type instability, things like Statistics.median(d; dims=n) are also type unstable.

@timholy timholy added the duplicate Indicates similar issues or pull requests label May 25, 2020
@timholy
Copy link
Member

timholy commented May 25, 2020

Essentially a duplicate of #26868

@timholy timholy closed this as completed May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Indicates similar issues or pull requests
Projects
None yet
Development

No branches or pull requests

2 participants