Re: [julia-users] Can't overwrite some methods in 0.5.0
On Oct 19, 2016 7:26 PM, "Alex Mellnik" wrote: > > Here's my bizarre find of the day. Most functions can be overwritten without problems: > > function add7(i) > 7 + i > end > Out[1]: > add7 (generic function with 1 method) > In [2]: > > add7(0) > add7(0) > Out[2]: > 7 > In [3]: > > function add7(i) > 9 + i > end > function add7(i) > 9 + i > end > Out[3]: > add7 (generic function with 1 method) > WARNING: Method definition add7(Any) in module Main at In[1]:2 overwritten at In[3]:2. > In [4]: > > add7(0) > Out[4]: > 9 > > However, others can not: > > using DataFrames > df = DataFrame(A=[1,2,3], B=["A", "B", "C"]) > println(df) > 3×2 DataFrames.DataFrame > │ Row │ A │ B │ > ├─┼───┼─┤ > │ 1 │ 1 │ "A" │ > │ 2 │ 2 │ "B" │ > │ 3 │ 3 │ "C" │ > In [3]: > > row[:A] > 2 > function filter(row) > if row[:A] > 2 > return 1 > else > return 3 > end > end > Out[3]: > filter (generic function with 1 method) > In [4]: > > [filter(row) for row in eachrow(df)] > [filter(row) for row in eachrow(df)] > Out[4]: > 3-element Array{Int64,1}: > 3 > 3 > 1 > In [5]: > > rand() > 0.5 > function filter(row) > if row[:A] > 2 > return 2 > else > return 4 > end > end > WARNING: Method definition filter(Any) in module Main at In[3]:2 overwritten at In[5]:2 > Out[5]: > filter (generic function with 1 method) > . > In [6]: > > [filter(row) for row in eachrow(df)] > Out[6]: > 3-element Array{Int64,1}: > 3 > 3 > 1 > > What is it about this second example that prevents the newer method from being used? Nothing about it but how you use it. It's inlined to the comprehension.
Re: [julia-users] Can't overwrite some methods in 0.5.0
Yichao, I'm afraid I'm not following -- could you expand on that a bit? Thanks, Alex On Wednesday, October 19, 2016 at 4:41:30 PM UTC-7, Yichao Yu wrote: > > On Oct 19, 2016 7:26 PM, "Alex Mellnik" > > wrote: > > > > Here's my bizarre find of the day. Most functions can be overwritten > without problems: > > > > function add7(i) > > 7 + i > > end > > Out[1]: > > add7 (generic function with 1 method) > > In [2]: > > > > add7(0) > > add7(0) > > Out[2]: > > 7 > > In [3]: > > > > function add7(i) > > 9 + i > > end > > function add7(i) > > 9 + i > > end > > Out[3]: > > add7 (generic function with 1 method) > > WARNING: Method definition add7(Any) in module Main at In[1]:2 > overwritten at In[3]:2. > > In [4]: > > > > add7(0) > > Out[4]: > > 9 > > > > However, others can not: > > > > using DataFrames > > df = DataFrame(A=[1,2,3], B=["A", "B", "C"]) > > println(df) > > 3×2 DataFrames.DataFrame > > │ Row │ A │ B │ > > ├─┼───┼─┤ > > │ 1 │ 1 │ "A" │ > > │ 2 │ 2 │ "B" │ > > │ 3 │ 3 │ "C" │ > > In [3]: > > > > row[:A] > 2 > > function filter(row) > > if row[:A] > 2 > > return 1 > > else > > return 3 > > end > > end > > Out[3]: > > filter (generic function with 1 method) > > In [4]: > > > > [filter(row) for row in eachrow(df)] > > [filter(row) for row in eachrow(df)] > > Out[4]: > > 3-element Array{Int64,1}: > > 3 > > 3 > > 1 > > In [5]: > > > > rand() > 0.5 > > function filter(row) > > if row[:A] > 2 > > return 2 > > else > > return 4 > > end > > end > > WARNING: Method definition filter(Any) in module Main at In[3]:2 > overwritten at In[5]:2 > > Out[5]: > > filter (generic function with 1 method) > > . > > In [6]: > > > > [filter(row) for row in eachrow(df)] > > Out[6]: > > 3-element Array{Int64,1}: > > 3 > > 3 > > 1 > > > > What is it about this second example that prevents the newer method from > being used? > > Nothing about it but how you use it. It's inlined to the comprehension. > >
Re: [julia-users] Can't overwrite some methods in 0.5.0
On Wed, Oct 19, 2016 at 10:33 PM, Alex Mellnik wrote: > Yichao, > > I'm afraid I'm not following -- could you expand on that a bit? Thanks, > https://github.com/JuliaLang/julia/issues/265 > > Alex > > On Wednesday, October 19, 2016 at 4:41:30 PM UTC-7, Yichao Yu wrote: > >> On Oct 19, 2016 7:26 PM, "Alex Mellnik" wrote: >> > >> > Here's my bizarre find of the day. Most functions can be overwritten >> without problems: >> > >> > function add7(i) >> > 7 + i >> > end >> > Out[1]: >> > add7 (generic function with 1 method) >> > In [2]: >> > >> > add7(0) >> > add7(0) >> > Out[2]: >> > 7 >> > In [3]: >> > >> > function add7(i) >> > 9 + i >> > end >> > function add7(i) >> > 9 + i >> > end >> > Out[3]: >> > add7 (generic function with 1 method) >> > WARNING: Method definition add7(Any) in module Main at In[1]:2 >> overwritten at In[3]:2. >> > In [4]: >> > >> > add7(0) >> > Out[4]: >> > 9 >> > >> > However, others can not: >> > >> > using DataFrames >> > df = DataFrame(A=[1,2,3], B=["A", "B", "C"]) >> > println(df) >> > 3×2 DataFrames.DataFrame >> > │ Row │ A │ B │ >> > ├─┼───┼─┤ >> > │ 1 │ 1 │ "A" │ >> > │ 2 │ 2 │ "B" │ >> > │ 3 │ 3 │ "C" │ >> > In [3]: >> > >> > row[:A] > 2 >> > function filter(row) >> > if row[:A] > 2 >> > return 1 >> > else >> > return 3 >> > end >> > end >> > Out[3]: >> > filter (generic function with 1 method) >> > In [4]: >> > >> > [filter(row) for row in eachrow(df)] >> > [filter(row) for row in eachrow(df)] >> > Out[4]: >> > 3-element Array{Int64,1}: >> > 3 >> > 3 >> > 1 >> > In [5]: >> > >> > rand() > 0.5 >> > function filter(row) >> > if row[:A] > 2 >> > return 2 >> > else >> > return 4 >> > end >> > end >> > WARNING: Method definition filter(Any) in module Main at In[3]:2 >> overwritten at In[5]:2 >> > Out[5]: >> > filter (generic function with 1 method) >> > . >> > In [6]: >> > >> > [filter(row) for row in eachrow(df)] >> > Out[6]: >> > 3-element Array{Int64,1}: >> > 3 >> > 3 >> > 1 >> > >> > What is it about this second example that prevents the newer method >> from being used? >> >> Nothing about it but how you use it. It's inlined to the comprehension. >> >>
Re: [julia-users] Can't overwrite some methods in 0.5.0
> > I guess I have a similar problem, when using Optim.jl in a IJulia notebook > using Optim function myfunc(a) println("Hey") return abs(a) end x0 = [1.,2.,3.] res = optimize(myfunc, x0, iterations=20, method=BFGS()) Now when I redefine myfun() the changes do not propagate through to the optimize() call somehow, still using the initial definition. (I tried with replacing "Hey" with "Ho", still printing "Hey") What is the recommended way of dealing with this? I really want to redefine myfunc to see how it affects the optimization.
Re: [julia-users] Can't overwrite some methods in 0.5.0
myfunc should return sum(abs(a)) to make actual sense, but this does not matter for the problem I have
Re: [julia-users] Can't overwrite some methods in 0.5.0
myfunc = a -> begin println("Hey") return sum(a) end
Re: [julia-users] Can't overwrite some methods in 0.5.0
Thanks, after seeing https://github.com/JuliaLang/julia/issues/265#issuecomment-243056854 I have a better idea of what's going on and why it doesn't occur in 0.5. On Wednesday, October 19, 2016 at 11:59:08 PM UTC-7, Yichao Yu wrote: > > > > On Wed, Oct 19, 2016 at 10:33 PM, Alex Mellnik > wrote: > >> Yichao, >> >> I'm afraid I'm not following -- could you expand on that a bit? Thanks, >> > > https://github.com/JuliaLang/julia/issues/265 > > >> >> Alex >> >> On Wednesday, October 19, 2016 at 4:41:30 PM UTC-7, Yichao Yu wrote: >> >>> On Oct 19, 2016 7:26 PM, "Alex Mellnik" wrote: >>> > >>> > Here's my bizarre find of the day. Most functions can be overwritten >>> without problems: >>> > >>> > function add7(i) >>> > 7 + i >>> > end >>> > Out[1]: >>> > add7 (generic function with 1 method) >>> > In [2]: >>> > >>> > add7(0) >>> > add7(0) >>> > Out[2]: >>> > 7 >>> > In [3]: >>> > >>> > function add7(i) >>> > 9 + i >>> > end >>> > function add7(i) >>> > 9 + i >>> > end >>> > Out[3]: >>> > add7 (generic function with 1 method) >>> > WARNING: Method definition add7(Any) in module Main at In[1]:2 >>> overwritten at In[3]:2. >>> > In [4]: >>> > >>> > add7(0) >>> > Out[4]: >>> > 9 >>> > >>> > However, others can not: >>> > >>> > using DataFrames >>> > df = DataFrame(A=[1,2,3], B=["A", "B", "C"]) >>> > println(df) >>> > 3×2 DataFrames.DataFrame >>> > │ Row │ A │ B │ >>> > ├─┼───┼─┤ >>> > │ 1 │ 1 │ "A" │ >>> > │ 2 │ 2 │ "B" │ >>> > │ 3 │ 3 │ "C" │ >>> > In [3]: >>> > >>> > row[:A] > 2 >>> > function filter(row) >>> > if row[:A] > 2 >>> > return 1 >>> > else >>> > return 3 >>> > end >>> > end >>> > Out[3]: >>> > filter (generic function with 1 method) >>> > In [4]: >>> > >>> > [filter(row) for row in eachrow(df)] >>> > [filter(row) for row in eachrow(df)] >>> > Out[4]: >>> > 3-element Array{Int64,1}: >>> > 3 >>> > 3 >>> > 1 >>> > In [5]: >>> > >>> > rand() > 0.5 >>> > function filter(row) >>> > if row[:A] > 2 >>> > return 2 >>> > else >>> > return 4 >>> > end >>> > end >>> > WARNING: Method definition filter(Any) in module Main at In[3]:2 >>> overwritten at In[5]:2 >>> > Out[5]: >>> > filter (generic function with 1 method) >>> > . >>> > In [6]: >>> > >>> > [filter(row) for row in eachrow(df)] >>> > Out[6]: >>> > 3-element Array{Int64,1}: >>> > 3 >>> > 3 >>> > 1 >>> > >>> > What is it about this second example that prevents the newer method >>> from being used? >>> >>> Nothing about it but how you use it. It's inlined to the comprehension. >>> >>> >