Skip to content

inference failure on nested zip iteration #31315

Closed
@stakaz

Description

@stakaz

Hello, I was hitting the following problem: when using nested zip functions julia is somehow not able to generate fast code on the first run but on the second run the function becomes fast. An example is

using Statistics 
using BenchmarkTools 

f(X) = reweight((a for a  X.A), 0.1)
g(X) = reweight((a * b for (a, b)  zip(X.A, X.B)), 0.1)

@inline function reweight(A, ω)
    N = 0.0
    for (a,)  zip(A)
        N += a
    end
    return N
end

N = 100
X = (A = rand(N), B = rand(N))

println("f")
@btime f($X)

println("g")
@btime g($X)
@code_warntype g(X)

Here, the first time @code_warntype is reporting some bad things but running the code again removes this and the function is much faster.

There is a discussion on discourse and I was suggested to submit an issue for this here.

julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Pentium(R) CPU  N3530  @ 2.16GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, silvermont)

Please help me to find a solution for this as it really slows down my calculations considerable. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler:inferenceType inferenceiterationInvolves iteration or the iteration protocol

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions