Can someone explain how to minimize the memory allocations in the line for i=1:N
. The following is output from running --track-allocation=user
for a simple function.
- using LinearAlgebra: norm
- function get_orientations!(rotvec::AbstractArray{Float64,2},
- orientations::AbstractArray{Float64,2})
- N = size(rotvec, 2)::Int
114299917 for i = 1:N
- r = @view rotvec[:,i]
4800000 R = norm(r)
0 q0 = cos(0.5*R)
0 q1, q2, q3 = sin(0.5*R)*(r/R)
38400000 orientations[:,i] = [2*(q0*q2 + q1*q3), -2*(q0*q1 - q2*q3),
- q0^2 - q1^2 - q2^2 + q3^2]
- end
- end
-
- rotvec = rand(3,100000)::Array{Float64,2}
- ori = zeros(Float64, size(rotvec))
- get_orientations!(rotvec, ori)