See the discussion here

https://github.com/JuliaLang/julia/issues/249



2014-12-15 14:14 GMT-05:00 Christian Peel <[email protected]>:
>
> Thanks Tim, InPlaceOps is very good to know about.
>
> I guess that it's hard to use simple mathematical notation (operators) to
> express all the subtleties and breadth of even such a simple operation as
> multiplying two matrices and saving the result.  On can have temporary
> matrices created or not, a new or existing output matrix used, and more.
>
> On Monday, December 15, 2014 2:50:24 AM UTC-8, Tim Holy wrote:
>>
>> Some of this is in the InPlaceOps.jl package.
>>
>> --Tim
>>
>> On Sunday, December 14, 2014 10:38:56 PM Christian Peel wrote:
>> > I'm curious if it would be possible to do this in some way that uses
>> > explicit operators.  For example the following three functions:
>> >
>> > # make local variable J storing result which keeps input array J
>> unaffected
>> > function f1(J)
>> > J = K*M
>> > end
>> >
>> > # update the input J with result
>> > function f2(J)
>> > J @= K*M   # Instead of   J[:,:] = K*M
>> > end
>> >
>> > # multiply K by M without allocating a new array
>> > function f3(J)
>> > J := K*M      # Instead A_mul_B!(J,K,M)
>> > end
>> >
>> > ...just curious
>> >
>> > On Sunday, December 14, 2014 6:35:39 PM UTC-8, Petr Krysl wrote:
>> > > Ahhh. Now, that made sense (I did not know Julia actually had a
>> function
>> > > with capitals and underscores its name ;).
>> > >
>> > > Thanks.  Much obliged.
>> > >
>> > > Petr
>> > >
>> > > On Sunday, December 14, 2014 6:01:04 PM UTC-8, Andreas Noack wrote:
>> > >> 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