Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

covar_out argument not used in function (besides asserts); should replace all instances of ccf_sample_covar with covar_out #33

Closed
hematthi opened this issue May 24, 2022 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@hematthi
Copy link
Collaborator

function calc_ccf_sample_covar_helper!( covar_out::A2, ccfs::A2, weights::A1; template::A1, assume_normalized::Bool = false ) where {T1<:Real, A1<:AbstractArray{T1,1}, T2<:Real, A2<:AbstractArray{T2,2} }
num_vels, num_obs = size(ccfs)
@assert 5 <= size(ccfs,1) <= 10000 # Arbitrary limits
@assert 2 <= num_obs <= 10000 # Arbitrary upper limit
@assert size(covar_out,1) == size(covar_out,2) == num_vels
@assert length(weights) == num_obs
@assert length(template) == num_vels
@assert sum(weights) one(eltype(weights))
ccfs_norm = assume_normalized ? ccfs : calc_normalized_ccfs(ccfs)
# Weighted version of (ccfs_norm .- template) * (ccfs_norm .- template)'
ccf_sample_covar = zeros(num_vels, num_vels)
for j in 1:num_vels
for k in 1:j
for i in 1:num_obs
summand = weights[i] * (ccfs[j,i]-template[j]) * (ccfs[k,i]-template[k])
ccf_sample_covar[k,j] += summand
#= Can skip since wrapping with Symmetric below to improve memory access pattern
if j<k
ccf_sample_covar[k,j] += summand
end
=#
end # i
end # j
end # k
ccf_sample_covar = Symmetric(ccf_sample_covar)
if all(weights.==one(eltype(weights)))
normalization = 1.0 / (num_vels-1)
else
sum_w = sum(weights)
sum_w2 = sum(weights.^2)
n_eff = sum_w^2/sum_w2
normalization = 1.0 / (1.0 - sum_w2 )
normalization *= n_eff/(n_eff-1)
end
ccf_sample_covar *= normalization
return ccf_sample_covar
end

Assuming the purpose of passing covar_out is to reduce memory allocation by using a preallocated array, should replace all instances of ccf_sample_covar with covar_out (and remove line 58)

@hematthi hematthi added bug Something isn't working enhancement New feature or request labels May 24, 2022
@eford eford closed this as completed in 12570fe Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant