And, as I'm sure you're aware- just as I was immediately after I posted 
this, that second loop is completely superfluous.

On Wednesday, January 21, 2015 at 1:56:19 AM UTC-5, Micah McClimans wrote:
>
> I'm running into trouble with a line of matrix multiplication going very 
> slowly in one of my programs. The line I'm looking into is:
> objectivematrix=shrt*diagm(expr)*(shrt')
> where shrt is 12,000x600 and expr is 600 long. This line takes several 
> HOURS to run, on a computer that can run
>
> k=rand(12000,12000)
> k3=k*k*k
>
> in under a minute. I've tried devectorizing the line into the following 
> loop (shrt is block-diagonal with each block ONevecs and -ONevecs 
> respectively, so I split the loop in half)
>
> objectivematrix=zeros(2*size(ONevecs,1),2*size(ONevecs,1))
> for i in 1:size(ONevecs,1)
>     print(i)
>     for j in 1:size(ONevecs,1)
>         for k in 1:size(ONevecs,2)
>         objectivematrix[i,j]+=ONevecs[i,k]*ONevecs[j,k]*expr[k]
>         end
>     end
> end
> for i in 1:size(ONevecs,1)
>     print(i)
>     for j in 1:size(ONevecs,1)
>         for k in 1:size(ONevecs,2)
>         
> objectivematrix[i+size(ONevecs,1),j+size(ONevecs,1)]+=ONevecs[i,k]*ONevecs[j,k]*expr[k+size(ONevecs,2)]
>         end
>     end
>
> end
>
> and this give a print out every couple seconds- it's faster than the 
> matrix multiplication version, but not enough. Why is this taking so long? 
> This should not be a hard operation.
>

Reply via email to