Both the slices and the transpose create temporaries; this will change in 0.5 but for now it's the way things work. You could do something like (A'.*B)[2:end,2:end] to avoid some temporaries. But if you want to eliminate all temporaries, writing out the loops is the best way at the moment.
On Mon, Sep 14, 2015 at 9:36 PM, Patrick Kofod Mogensen < [email protected]> wrote: > Thank you both. Maybe I was somewhat unclear still, but it should be > > > for i in 2:n, j in 1:n > C[j,i-1] = A[i,1] * B[j,i] > end > > At least to do what I was trying to explain above. > > > On Monday, September 14, 2015 at 9:21:45 PM UTC-4, Ismael VC wrote: >> >> Could also be with this syntax: >> >> >> for i in 2:i, j in 1:j >> C[i,j] = A[i,1] * B[j,i] >> end >> >> >> >> El lunes, 14 de septiembre de 2015, 20:08:12 (UTC-5), Tom Breloff >> escribió: >>> >>> How about you do it in a loop (note this should be done in a function... >>> globals will ruin performance): >>> >>> C = Array(n,n-1) >>> for i in 2:i >>> for j in 1:j >>> C[i,j] = A[i,1] * B[j,i] >>> end >>> end >>> >>> On Mon, Sep 14, 2015 at 8:45 PM, Patrick Kofod Mogensen < >>> [email protected]> wrote: >>> >>>> Sorry, something went wrong with my description. It was supposed to be: >>>> >>>> C =A[2:end, 1]' .* B[:, 2:end] >>>> >>>> A is n-by-2 and B is n-by-n (difference!). So B[:, 2:end] is >>>> n-by-(n-1) and I expect C to be n-by-(n-1). Sorry for this mistakes! >>>> >>>> >>>> >>>> On Monday, September 14, 2015 at 8:39:59 PM UTC-4, Tom Breloff wrote: >>>>> >>>>> What size do you expect your result to be? Are you creating a 1 x >>>>> (b-1) row vector? If so, I would check out the ArrayViews package and do >>>>> something like: >>>>> >>>>> using ArrayViews >>>>> A1 = view(A,:,1) >>>>> C = Float64[dot(A1, view(B,:,i)) for in 2:size(B,2)] >>>>> >>>>> On Mon, Sep 14, 2015 at 7:27 PM, Patrick Kofod Mogensen < >>>>> [email protected]> wrote: >>>>> >>>>>> I have a line in my code that seems to really allocate a lot of >>>>>> memory, and I think it might be slowing down my program. I have two >>>>>> matrices. The first matrix A is n-by-2 and the second matrix B is n-by-b. >>>>>> What I need to do is to multiply the first column of A element by element >>>>>> to each row in B[:, 2:end]. I use broadcasting (.*) to achieve this along >>>>>> with a transpose of A[:,1]: >>>>>> >>>>>> C=A[:,1]'.*B[:,2:end] >>>>>> >>>>>> However, it seems to allocate a lot of temporary memory (the number >>>>>> memory number in .mem overflows even for small problems). Is there >>>>>> anything >>>>>> I can do here? >>>>>> >>>>>> >>>>>> P >>>>>> >>>>> >>>>> >>>
