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

plot heatmap function gives a compile error when working on a variable from a global scope #106

Closed
lwabeke opened this issue Jan 13, 2017 · 1 comment

Comments

@lwabeke
Copy link

lwabeke commented Jan 13, 2017

See the code snippet below for a smallest reproducible case

using PlotlyJS
let
    var = randn(10,5)
    global function P1()
        lay = Layout(;title="Dummy1")
        plot( heatmap( z=var ), lay )
     end  # function
    
    global function P2()
        lay = Layout(;title="Dummy2")
        plot( heatmap( z=randn(10,5) ), lay )
     end  # function

end # let

P2() works fine, but calling P1() which is essentially the same, give a compile error:

error compiling P1: unsupported or misplaced expression "quote" in function P1

If I am doing something wrong, I cannot think what. I guess I can work around it, by copying the variable into a local variable, but still

Julia Version 0.5.0
Commit 3c9d753 (2016-09-19 18:14 UTC)
Platform Info:
System: Darwin (x86_64-apple-darwin13.4.0)
CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.7.1 (ORCJIT, haswell)
In [48]:

Pkg.status()
19 required packages:
...

  • PlotlyJS 0.5.2
    ...
@sglyon
Copy link
Member

sglyon commented Jan 13, 2017

Hmm, this seems like more of a Julia issue rather than a PlotlyJS.jl issue.

See the example below

julia> f(;kwargs...) = Dict(kwargs)
f (generic function with 1 method)

julia> f(x=1, y=2)
Dict{Symbol,Int64} with 2 entries:
  :y => 2
  :x => 1

julia> let
       v = rand(5)

       global function g()
           f(myvar=v)
       end

       global function h()
           f(myvar=rand(5))
       end
       end
h (generic function with 1 method)

julia> g()
ERROR: error compiling g: unsupported or misplaced expression "quote" in function g

julia> h()
Dict{Symbol,Array{Float64,1}} with 1 entry:
  :myvar => [0.0102912,0.411641,0.0612579,0.630711,0.720062]

If you do a little digging you can see what the problem is:

julia> m1 = methods(P1).ms[1]
P1() at REPL[41]:4

julia> m2 = methods(P2).ms[1]
P2() at REPL[41]:9

julia> m1.lambda_template
LambdaInfo template for P1() at REPL[41]:4
:(begin
        nothing
        lay = ((Core.kwfunc)(Main.Layout))((Base.vector_any)(:title,"Dummy1"),Main.Layout) # line 5:
        return (Main.plot)(((Core.kwfunc)(Main.heatmap))((Base.vector_any)(:z,$(QuoteNode([0.0719331 -0.235815 … 0.104974 1.09685; 0.473269 -0.432309 … -0.495483 -1.04663; … ; 0.0528695 0.285481 … -0.93711 -1.08406; 0.513901 -1.82477 … -2.06176 1.1875]))),Main.heatmap),lay)
    end)

julia> m2.lambda_template
LambdaInfo template for P2() at REPL[41]:9
:(begin
        nothing
        lay = ((Core.kwfunc)(Main.Layout))((Base.vector_any)(:title,"Dummy2"),Main.Layout) # line 10:
        return (Main.plot)(((Core.kwfunc)(Main.heatmap))((Base.vector_any)(:z,(Main.randn)(10,5)),Main.heatmap),lay)
    end)

Notice that in m1.lambda_template you have the random matrix var input as a QuoteNode. This is why the error talks about a misplaced quote.

I don't think there is anything for me to do on this as it seems to be an issue with scoping and keyword arguments -- which are Julia problems. I recommend posting over at the julia discussion page and seeing if you get more help there.

@sglyon sglyon closed this as completed Jan 13, 2017
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