I've run into this a few times (and a few hundred times in python), so I made an @iterize macro. Not sure how useful it is, but you can put it in front of a bunch of chained function calls and it will make iterators automatically to avoid creating any temp arrays:
A = randn(1<<26) @time sum(abs(A)) @time @iterize sum(abs(A)) @time sumabs(A) println(sum(abs(A))) println(@iterize sum(abs(A))) println(sumabs(A)) println(sum(A)) println(@iterize sum(A)) println(sum(ceil(floor(abs(A))))) println(@iterize sum(ceil(floor(abs(A))))) Output: elapsed time: 0.367873796 seconds (537878296 bytes allocated, 2.48% gc time) elapsed time: 0.107278414 seconds (577616 bytes allocated) elapsed time: 0.045590637 seconds (639580 bytes allocated) 5.3551932868680775e7 5.3551932868672036e7 5.3551932868678436e7 658.6904827808266 658.6904827808266 2.4537098e7 2.4537098e7 The macro is in a gist: Iterize.jl <https://gist.github.com/sunetos/f311d5408854e65d7ff9> I had tried using @devec, but that actually made it about 100x slower. On Saturday, August 23, 2014 8:15:44 AM UTC-4, Stefan Karpinski wrote: > > On Sat, Aug 23, 2014 at 7:23 AM, <[email protected] <javascript:>> wrote: > >> >To do any of that justice, you end up with a language that looks >> basically like Haskell. So why not just use Haskell? >> >> Because I don't know anything about it (yet), except the name and the >> fact that you often associated it with lazy evaluation. >> >> Because (#2), this could be a way to make sumabs and the likes obsolete >> in *Julia*. :) >> > > We do really want to get rid of things like sumabs., so it's certainly > worth considering. I know I've thought about it many times, but I don't > think it's the right answer – you really want to preserve eager evaluation > semantics, even if you end up moving around the actual evaluation of things. >
