[julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Phil Tomson
Maybe this is just obvious, but it's not making much sense to me. If I have a reference to a function (pardon if that's not the correct Julia-ish terminology - basically just a variable that holds a Function type) and call it, it runs much more slowly (persumably because it's allocating a lot

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Mauro
This is a known limitation of Julia. The trouble is that Julia cannot do its type interference with the passed in function. I don't have time to search for the relevant issues but you should be able to find them. Similarly, lambdas also suffer from this. Hopefully this will be resolved soon! On

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Tim Holy
There have been many prior posts about this topic. Maybe we should add a FAQ page we can direct people to. In the mean time, your best bet is to search (or use FastAnonymous or NumericFuns). --Tim On Wednesday, March 25, 2015 11:41:10 AM Phil Tomson wrote: > Maybe this is just obvious, but it'

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Phil Tomson
I have a couple of instances where a function is determined by some parameters (in a JSON file in this case) and I have to call it in this manner. I'm thinking it should be possible to speed these up via a macro, but I'm a macro newbie. I'll probably post a different question related to that,

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Tim Holy
Don't use a macro, just use the @anon macro to create an object that will be fast to use as a "function." --Tim On Wednesday, March 25, 2015 01:00:27 PM Phil Tomson wrote: > I have a couple of instances where a function is determined by some > parameters (in a JSON file in this case) and I have

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Phil Tomson
On Wednesday, March 25, 2015 at 1:08:24 PM UTC-7, Tim Holy wrote: > > Don't use a macro, just use the @anon macro to create an object that will > be > fast to use as a "function." > I guess I'm not understanding how this is used, I would have thought I'd need to do something like: julia> f

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Tim Holy
No, it's f = @anon x->abs(x) and then pass f to test_time. Declare the function like this: function test_time{F}(func::F) end --Tim On Wednesday, March 25, 2015 01:30:28 PM Phil Tomson wrote: > On Wednesday, March 25, 2015 at 1:08:24 PM UTC-7, Tim Holy wrote: > > Don't use a macro,

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Phil Tomson
On Wednesday, March 25, 2015 at 1:52:04 PM UTC-7, Tim Holy wrote: > > No, it's > >f = @anon x->abs(x) > > and then pass f to test_time. Declare the function like this: > > function test_time{F}(func::F) > > end > Ok, got that working, but when I try using it inside the functio

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread elextr
On Thursday, March 26, 2015 at 8:06:41 AM UTC+11, Phil Tomson wrote: > > > > On Wednesday, March 25, 2015 at 1:52:04 PM UTC-7, Tim Holy wrote: >> >> No, it's >> >>f = @anon x->abs(x) >> >> and then pass f to test_time. Declare the function like this: >> >> function test_time{F}(func::F) >

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Tony Kelman
The function-to-be-called is not known at compile time in Phil's application, apparently. Question for Phil: are there a limited set of functions that you know you'll be calling here? I was doing something similar recently, where it actually made the most sense to create a fixed Dict{Symbol, UI

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Phil Tomson
On Wednesday, March 25, 2015 at 5:07:27 PM UTC-7, Tony Kelman wrote: > > The function-to-be-called is not known at compile time in Phil's > application, apparently. > Right, they come out of a JSON file. I parse the JSON and construct a list of processing nodes from it and those could have 1 o

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Tony Kelman
Here's the code I was referring to - https://github.com/tkelman/BLOM.jl/blob/master/src/functioncodes.jl In my case I'm using Float64 function codes for other reasons, created by reinterpreting a UInt64 with a few bits flipped. Using UInts directly, probably from the object_id of the symbol, wo

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-25 Thread Phil Tomson
On Wednesday, March 25, 2015 at 12:34:47 PM UTC-7, Mauro wrote: > > This is a known limitation of Julia. The trouble is that Julia cannot > do its type interference with the passed in function. I don't have time > to search for the relevant issues but you should be able to find them. > Simil

Re: [julia-users] Calling a function via a reference to a function allocates a lot of memory as compared to directly calling

2015-03-26 Thread Mauro
>> This is a known limitation of Julia. The trouble is that Julia cannot >> do its type interference with the passed in function. I don't have time >> to search for the relevant issues but you should be able to find them. >> Similarly, lambdas also suffer from this. Hopefully this will be >>