Thanks for the reply.

I think this still suffers from the same issue of allocating tmp every 
iteration through the loop. I only need to store the output of qr() if 
certain criteria are met. Then I do as you recommended and push it into a 
array. Consider the following

function test_qr3(iters)
    tmp=rand(3,3)
    a=Array{Array{Float64,2},1}
    for i=1:iters
        a=qr(tmp)
    end
end

julia> @time test_qr3(100000)
elapsed time: 0.474589094 seconds (147200224 bytes allocated)

julia> @time test_qr3(200000)
elapsed time: 0.90662408 seconds (294400224 bytes allocated)


While this is a trivial example, there should be a way to make it so that 
'a' is not re-alloacted each time through the loop. Or maybe the allocation 
is happening within qr()?

Thanks



On Tuesday, October 7, 2014 3:29:01 PM UTC-7, Max Suster wrote:
>
>
> You could try this. 
>
> a= Array{Float64,2}[]
> b= Array{Float64,2}[]
>
> function test_qr(a,b)
>
>   for i=1:100000
>     tmp = qr(rand(3,3))
>     push!(a,tmp[1])
>     push!(b,tmp[2])
>   end
>  
> end
>
> julia> size(a,1)
> 100000
>
> julia> size(b,1)
> 100000
>
>
> On Tuesday, October 7, 2014 10:17:07 PM UTC+2, Ryan Young wrote:
>>
>> Hello,
>>
>> I am working on optimizing a code that looks at 3D deformation fields.  
>> At one point I have to take the QR decompositions at many points. My 
>> problem is that regardless of how I  pre-allocate my variables to store the 
>> results of the QR, they are allocated each time through the loop. I tried 
>> to use the qrfact! method but found it suffered from the same problem.  Any 
>> help in getting around this would be great.  A basic function that has the 
>> same problem is below.  
>>
>> function test_qr()
>>     tmp=rand(3,3)
>>     a=Array(Float64,2)
>>     b=Array(Float64,2)
>>
>>     for i=1:100000
>>         a,b=qr(tmp)
>>     end
>>
>> end
>>
>

Reply via email to