Re: [julia-users] matrix multiplications
I agree on the consistency part with other in-place operations. I certainly don’t feel it’s hard to just use A_mul_B!, but my familiarity with BLAS shouldn’t be taken for granted. And if an in-place operator syntax exists in the language already… How about the flip side of the argument, it appears to works now — but doesn’t do what one expects. I understand why it doesn’t, and not a big deal with an evolving landscape of a developing language, but it certainly can be confusing and suggests matrices are a different beast. I’m not sure that is consistent with Julian way. But yeah, no fusing like broadcast so the gain is much reduced in implementing this. Cameron On Wed, Oct 19, 2016 at 8:58 AM, Milan Bouchet-Valatwrote: > Le mardi 18 octobre 2016 à 15:28 -0700, Steven G. Johnson a écrit : > > > > > > > Since it uses the in-place assignment operator .= it could be made > > > to work as desired, but there's some designing to do. > > > > > > > The problem is that it doesn't know that * is a matrix multiplication > > until compile-time. > > > > In any case, I don't think there's a huge amount to be gained from > > special syntax here. Unlike broadcast operations, matrix > > multiplications cannot in general be fused with other operations. > > So you might as well do A_mul_B!. > I think the biggest gain would be discoverability and consistency with > other in-place operations. A_mul_B! isn't the most Julian of our APIs > (to say the least)... > > > Regards >
Re: [julia-users] matrix multiplications
yes exactly ! On Wednesday, October 19, 2016 at 4:28:21 PM UTC+3:30, Milan Bouchet-Valat wrote: > > Le mardi 18 octobre 2016 à 15:28 -0700, Steven G. Johnson a écrit : > > > > > > > Since it uses the in-place assignment operator .= it could be made > > > to work as desired, but there's some designing to do. > > > > > > > The problem is that it doesn't know that * is a matrix multiplication > > until compile-time. > > > > In any case, I don't think there's a huge amount to be gained from > > special syntax here. Unlike broadcast operations, matrix > > multiplications cannot in general be fused with other operations. > > So you might as well do A_mul_B!. > I think the biggest gain would be discoverability and consistency with > other in-place operations. A_mul_B! isn't the most Julian of our APIs > (to say the least)... > > > Regards >
Re: [julia-users] matrix multiplications
Le mardi 18 octobre 2016 à 15:28 -0700, Steven G. Johnson a écrit : > > > > Since it uses the in-place assignment operator .= it could be made > > to work as desired, but there's some designing to do. > > > > The problem is that it doesn't know that * is a matrix multiplication > until compile-time. > > In any case, I don't think there's a huge amount to be gained from > special syntax here. Unlike broadcast operations, matrix > multiplications cannot in general be fused with other operations. > So you might as well do A_mul_B!. I think the biggest gain would be discoverability and consistency with other in-place operations. A_mul_B! isn't the most Julian of our APIs (to say the least)... Regards
Re: [julia-users] matrix multiplications
On Tuesday, October 18, 2016 at 4:10:57 PM UTC-4, Stefan Karpinski wrote: > > Since it uses the in-place assignment operator .= it could be made to work > as desired, but there's some designing to do. > The problem is that it doesn't know that * is a matrix multiplication until compile-time. In any case, I don't think there's a huge amount to be gained from special syntax here. Unlike broadcast operations, matrix multiplications cannot in general be fused with other operations. So you might as well do A_mul_B!.
Re: [julia-users] matrix multiplications
Since it uses the in-place assignment operator .= it could be made to work as desired, but there's some designing to do. On Tue, Oct 18, 2016 at 2:55 PM, Cameron McBridewrote: > You mean like the following? > > julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; Y = similar(B); Y.= A * > B > > This doesn’t work as you might hope. I believe it just creates a temporary > result of A*B and then stuffs it into the preexisting Y. > > On Tue, Oct 18, 2016 at 2:41 PM, Jérémy Béjanin > wrote: > >> I know, I was asking about that being the default behaviour of * >> >> On Tuesday, October 18, 2016 at 2:10:14 PM UTC-4, Stefan Karpinski wrote: >>> >>> That's what A_mul_B! does. >>> >>> On Tue, Oct 18, 2016 at 1:45 PM, Jérémy Béjanin >>> wrote: >>> I think this is something I might have read about in the past, but are there plans to make y = a*b use an already allocated y? On Tuesday, October 18, 2016 at 12:38:00 PM UTC-4, Stefan Karpinski wrote: > > A_mul_B!(Y, A, B) -> Y > > Calculates the matrix-matrix or matrix-vector product A⋅B and stores > the result in Y, overwriting the > existing value of Y. Note that Y must not be aliased with either A > or B. > > julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; Y = similar(B); > A_mul_B!(Y, A, B); > > julia> Y > 2×2 Array{Float64,2}: >3.0 3.0 >7.0 7.0 > > On Tue, Oct 18, 2016 at 10:27 AM, wrote: > >> hi guys >> is there a way to reduce allocated memory in matrix multiplications? >> >> for example this code blew in my machine gives : >> >> function test4(n) >> a = rand(n,n) >> for i = 1:100 >> a*a >>end >> end >> >> >> -- answer -- >> test4(1) >> # force compiling >> >> @time test4(1000) >> 16.589743 seconds (433 allocations: 770.587 MB, 0.68% gc time) >> > > >>> >
Re: [julia-users] matrix multiplications
You mean like the following? julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; Y = similar(B); Y.= A * B This doesn’t work as you might hope. I believe it just creates a temporary result of A*B and then stuffs it into the preexisting Y. On Tue, Oct 18, 2016 at 2:41 PM, Jérémy Béjaninwrote: > I know, I was asking about that being the default behaviour of * > > On Tuesday, October 18, 2016 at 2:10:14 PM UTC-4, Stefan Karpinski wrote: >> >> That's what A_mul_B! does. >> >> On Tue, Oct 18, 2016 at 1:45 PM, Jérémy Béjanin >> wrote: >> >>> I think this is something I might have read about in the past, but are >>> there plans to make y = a*b use an already allocated y? >>> >>> On Tuesday, October 18, 2016 at 12:38:00 PM UTC-4, Stefan Karpinski >>> wrote: A_mul_B!(Y, A, B) -> Y Calculates the matrix-matrix or matrix-vector product A⋅B and stores the result in Y, overwriting the existing value of Y. Note that Y must not be aliased with either A or B. julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; Y = similar(B); A_mul_B!(Y, A, B); julia> Y 2×2 Array{Float64,2}: 3.0 3.0 7.0 7.0 On Tue, Oct 18, 2016 at 10:27 AM, wrote: > hi guys > is there a way to reduce allocated memory in matrix multiplications? > > for example this code blew in my machine gives : > > function test4(n) > a = rand(n,n) > for i = 1:100 > a*a >end > end > > > -- answer -- > test4(1) > # force compiling > > @time test4(1000) > 16.589743 seconds (433 allocations: 770.587 MB, 0.68% gc time) > >>
Re: [julia-users] matrix multiplications
I know, I was asking about that being the default behaviour of * On Tuesday, October 18, 2016 at 2:10:14 PM UTC-4, Stefan Karpinski wrote: > > That's what A_mul_B! does. > > On Tue, Oct 18, 2016 at 1:45 PM, Jérémy Béjanin> wrote: > >> I think this is something I might have read about in the past, but are >> there plans to make y = a*b use an already allocated y? >> >> On Tuesday, October 18, 2016 at 12:38:00 PM UTC-4, Stefan Karpinski wrote: >>> >>> A_mul_B!(Y, A, B) -> Y >>> >>> Calculates the matrix-matrix or matrix-vector product A⋅B and stores >>> the result in Y, overwriting the >>> existing value of Y. Note that Y must not be aliased with either A or >>> B. >>> >>> julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; Y = similar(B); >>> A_mul_B!(Y, A, B); >>> >>> julia> Y >>> 2×2 Array{Float64,2}: >>>3.0 3.0 >>>7.0 7.0 >>> >>> On Tue, Oct 18, 2016 at 10:27 AM, wrote: >>> hi guys is there a way to reduce allocated memory in matrix multiplications? for example this code blew in my machine gives : function test4(n) a = rand(n,n) for i = 1:100 a*a end end -- answer -- test4(1) # force compiling @time test4(1000) 16.589743 seconds (433 allocations: 770.587 MB, 0.68% gc time) >>> >>> >
Re: [julia-users] matrix multiplications
That's what A_mul_B! does. On Tue, Oct 18, 2016 at 1:45 PM, Jérémy Béjaninwrote: > I think this is something I might have read about in the past, but are > there plans to make y = a*b use an already allocated y? > > On Tuesday, October 18, 2016 at 12:38:00 PM UTC-4, Stefan Karpinski wrote: >> >> A_mul_B!(Y, A, B) -> Y >> >> Calculates the matrix-matrix or matrix-vector product A⋅B and stores >> the result in Y, overwriting the >> existing value of Y. Note that Y must not be aliased with either A or B. >> >> julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; Y = similar(B); >> A_mul_B!(Y, A, B); >> >> julia> Y >> 2×2 Array{Float64,2}: >>3.0 3.0 >>7.0 7.0 >> >> On Tue, Oct 18, 2016 at 10:27 AM, wrote: >> >>> hi guys >>> is there a way to reduce allocated memory in matrix multiplications? >>> >>> for example this code blew in my machine gives : >>> >>> function test4(n) >>> a = rand(n,n) >>> for i = 1:100 >>> a*a >>>end >>> end >>> >>> >>> -- answer -- >>> test4(1) >>> # force compiling >>> >>> @time test4(1000) >>> 16.589743 seconds (433 allocations: 770.587 MB, 0.68% gc time) >>> >> >>
Re: [julia-users] matrix multiplications
I think this is something I might have read about in the past, but are there plans to make y = a*b use an already allocated y? On Tuesday, October 18, 2016 at 12:38:00 PM UTC-4, Stefan Karpinski wrote: > > A_mul_B!(Y, A, B) -> Y > > Calculates the matrix-matrix or matrix-vector product A⋅B and stores the > result in Y, overwriting the > existing value of Y. Note that Y must not be aliased with either A or B. > > julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; Y = similar(B); > A_mul_B!(Y, A, B); > > julia> Y > 2×2 Array{Float64,2}: >3.0 3.0 >7.0 7.0 > > On Tue, Oct 18, 2016 at 10:27 AM,> wrote: > >> hi guys >> is there a way to reduce allocated memory in matrix multiplications? >> >> for example this code blew in my machine gives : >> >> function test4(n) >> a = rand(n,n) >> for i = 1:100 >> a*a >>end >> end >> >> >> -- answer -- >> test4(1) >> # force compiling >> >> @time test4(1000) >> 16.589743 seconds (433 allocations: 770.587 MB, 0.68% gc time) >> > >
Re: [julia-users] matrix multiplications
A_mul_B!(Y, A, B) -> Y Calculates the matrix-matrix or matrix-vector product A⋅B and stores the result in Y, overwriting the existing value of Y. Note that Y must not be aliased with either A or B. julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; Y = similar(B); A_mul_B!(Y, A, B); julia> Y 2×2 Array{Float64,2}: 3.0 3.0 7.0 7.0 On Tue, Oct 18, 2016 at 10:27 AM,wrote: > hi guys > is there a way to reduce allocated memory in matrix multiplications? > > for example this code blew in my machine gives : > > function test4(n) > a = rand(n,n) > for i = 1:100 > a*a >end > end > > > -- answer -- > test4(1) > # force compiling > > @time test4(1000) > 16.589743 seconds (433 allocations: 770.587 MB, 0.68% gc time) >
[julia-users] matrix multiplications
hi guys is there a way to reduce allocated memory in matrix multiplications? for example this code blew in my machine gives : function test4(n) a = rand(n,n) for i = 1:100 a*a end end -- answer -- test4(1) # force compiling @time test4(1000) 16.589743 seconds (433 allocations: 770.587 MB, 0.68% gc time)