Hi Julia Users
I write a small function to do Gram-Schmidt orthogonalization:
function ModGS(A::Array{Float64,2})
delta = 1e-16
(m,n) = size(A)
for j = 1: n
q = A[:,j]
q = q / (norm(q)+delta)
A[:,j] = q
for k = j+1: n
a = A[:,k]
r = dot(q, a)
A[:,k] = a - r*q
end
end
return nothing
end
A = rand(1000, 500);
@time ModGS(A);
0.696324 seconds (875.25 k allocations: 2.831 GB, 15.78% gc time)
it cause huge amount of memory allocation, Does anybody know the reason? How to
improve it?
I also use memory track tool, this is the output:
- function ModGS(A::Array{Float64, 2})
65440991 delta = 1e-16
0 (m,n) = size(A)
0 for j = 1: n
4056000 q = A[:,j]
4040000 q = q / (norm(q)+delta)
0 A[:,j] = q
0 for k = j+1: n
1011972000 a = A[:,k]
0 r = dot(q, a)
2019952000 A[:,k] = a - r*q
- end
- end
0 return nothing
- end
-
-
- A = randn(1000, 500);
- ModGS(A)
-
Thanks