[julia-users] in-place fn in a higher order fn

2015-04-23 Thread Mauro
It is well know that Julia struggles with type inference in higher order functions. This usually leads to slow code and memory allocations. There are a few hacks to work around this. Anyway, the question I have is: Why can't Julia do better with in-place functions? In short, a higher-order funct

Re: [julia-users] in-place fn in a higher order fn

2015-04-23 Thread Jameson Nash
The short answer is that there is a certain set of optimizations that have been implemented in Julia, but still a considerable set that has not been implemented. This falls into the category of optimizations that have not been implemented. Pull requests are always welcome (although I do not recomme

Re: [julia-users] in-place fn in a higher order fn

2015-04-23 Thread Mauro
Thanks! In that case, I'll file an issue then to get this noted. Also, I think there is no (general) issue on the bad performance of higher order functions. Should I file that too? On Thu, 2015-04-23 at 15:52, Jameson Nash wrote: > The short answer is that there is a certain set of optimizatio

Re: [julia-users] in-place fn in a higher order fn

2015-04-23 Thread Patrick O'Leary
It's part of #3440, the compiler optimization metabug: "function-valued argument inlining" https://github.com/JuliaLang/julia/issues/3440 On Thursday, April 23, 2015 at 9:34:48 AM UTC-5, Mauro wrote: > > Thanks! In that case, I'll file an issue then to get this noted. Also, > I think there is

Re: [julia-users] in-place fn in a higher order fn

2015-04-23 Thread Mauro
> It's part of #3440, the compiler optimization metabug: "function-valued > argument inlining" > > https://github.com/JuliaLang/julia/issues/3440 Thanks, and yes, I'm aware of that one. For me it's a bit hard to tell, will the "function-valued argument inlining" solve all the higher order functi

Re: [julia-users] in-place fn in a higher order fn

2015-04-23 Thread elextr
On Friday, April 24, 2015 at 2:03:07 AM UTC+10, Mauro wrote: > > > It's part of #3440, the compiler optimization metabug: "function-valued > > argument inlining" > > > > https://github.com/JuliaLang/julia/issues/3440 > > Thanks, and yes, I'm aware of that one. For me it's a bit hard to tell,

Re: [julia-users] in-place fn in a higher order fn

2015-04-24 Thread Mauro
>> >> >> function f(fn!,ar) >> >> >> for i=1:n >> >> >> fn!(ar, i) # fn! updates ar[i] somehow, returns nothing >> >> >> nothing# to make sure output of f is discarded >> >> >> end >> >> >> end > > > I'm curious how you would see it optimised? IIUC Julia doesn't kn

Re: [julia-users] in-place fn in a higher order fn

2015-04-24 Thread elextr
On Friday, April 24, 2015 at 6:33:08 PM UTC+10, Mauro wrote: > > >> >> >> function f(fn!,ar) > >> >> >> for i=1:n > >> >> >> fn!(ar, i) # fn! updates ar[i] somehow, returns nothing > >> >> >> nothing# to make sure output of f is discarded > >> >> >> end > >> >> >>

Re: [julia-users] in-place fn in a higher order fn

2015-04-24 Thread Mauro
>> Well it seems Julia should know that nothing is used from fn!, without >> knowing anything about fn!. That is at least what @code_warntype >> suggest (with julia --inline=no). For >> >> function f(ar) >> for i=1:n >> hh!(ar, i) >> end >> end >> >> the loop gives: >> >>

Re: [julia-users] in-place fn in a higher order fn

2015-04-24 Thread Tim Holy
I don't think there's any fundamental reason things can't work as you're hoping, I just think they all count as optimizations that have not yet been implemented. --Tim On Friday, April 24, 2015 11:19:14 AM Mauro wrote: > >> Well it seems Julia should know that nothing is used from fn!, without

Re: [julia-users] in-place fn in a higher order fn

2015-04-24 Thread elextr
On Friday, April 24, 2015 at 8:11:52 PM UTC+10, Mauro wrote: > > >> Well it seems Julia should know that nothing is used from fn!, without > >> knowing anything about fn!. That is at least what @code_warntype > >> suggest (with julia --inline=no). For > >> > >> function f(ar) > >> for

Re: [julia-users] in-place fn in a higher order fn

2015-04-25 Thread Mauro
>> I think this optimisation should work irrespective of what fn! returns >> by the fact that the value is not used. This and more seems to happen >> in the first-order function. Here a version of first-order >> function which calls a function which returns an inferred Any: >> >> const aa = A