On Fri, 2016-10-21 at 09:51, Alexey Cherkaev <alexey.cherk...@gmail.com> wrote:
> Ay, how many times I've done it! Still forget about global variables!
>
> OK, I see now about `.+` and friends.

As a work-around until 0.6: If you use the functional form of binary
operators then they get fused too:

x .= (+).(y,z)

> Thanks!
>
> On Friday, October 21, 2016 at 3:59:59 AM UTC+2, Steven G. Johnson wrote:
>>
>> Putting things into a function to avoid benchmarking in global scope:
>>
>>
>> foo!(x,y) = x .= cos.(sin.(y))
>>
>> y = rand(1000); x = similar(y);
>>
>> @time foo!(x, y);
>>
>>
>> gives (after running @time twice to eliminate the compilation time):
>>
>>
>>   0.000035 seconds (5 allocations: 176 bytes)
>>
>>
>> i.e. it is not allocating any arrays, and all the loops are fused.
>>
>>
>> Binary operations like .+ will not be fused until Julia 0.6, however.
>>  (This is documented in the manual.)
>>

Reply via email to