The function K*M allocates a new array for the result, but if you write
J[:,:]=K*M then J is updated with the values from the new array. This
matter if e.g. J is input to a function

function f1(J)
J = K*M
end

function f2(J)
J[:,:] = K*M
end

f1 will make a local variable J storing the result which will keep the
input array J unaffected whereas f2 will update the input J. However, they
will both allocate a new array.

If you want to avoid allocation, you'll have to use either A_mul_B!(C,A,B)
where C stores the result or BLAS.gemm!.

2014-12-14 20:12 GMT-05:00 Petr Krysl <[email protected]>:
>
> ???
>
> Could I have that again please? I don't follow.
>
>  In-place in my  usage of the word here means that the result of the
> multiplication is immediately stored  in the matrix J,, without a temporary
> being created  and then assigned  to J.
>
> Thanks,
>
> Petr
>
> On Sunday, December 14, 2014 5:00:40 PM UTC-8, John Myles White wrote:
>>
>> Assigning in-place and creating temporaries are actually totally
>> orthogonal.
>>
>> One is concerned with mutating J. This is contrasted with writing,
>>
>> J = K * M
>>
>> The other is concerned with the way that K * M gets computed before any
>> assignment operation or mutation can occur. This is contrasted with
>> something like A_mul_B.
>>
>>  -- John
>>
>> Sent from my iPhone
>>
>> > On Dec 14, 2014, at 7:48 PM, Petr Krysl <[email protected]> wrote:
>> >
>> > Hello everybody,
>> >
>> > I hope someone knows this:  What is the use of writing
>> >
>> > J[:,:] = K*M
>> >
>> > where all of these quantities are matrices? I thought I'd seen
>> somewhere that it was assigning to the matrix "in-place"  instead of
>> creating a temporary.   Is that so?
>> > I couldn't find it in the documentation   for 0.3.
>> >
>> > Thanks,
>> >
>> > Petr
>>
>

Reply via email to