Created
October 9, 2017 16:42
-
-
Save jsams/27836360376cd74eadfbc0e6d67ec6b8 to your computer and use it in GitHub Desktop.
function call different result than inline, also not defined on one branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scale_sd!(A::SparseMatrixCSC; corrected=true) | |
n = size(A, 1) | |
if corrected | |
sdcall(v,n,mn) = sqrt(sum(vi^2 for vi in v) / (n - 1) - (n / (n - 1)) * mn^2) | |
else | |
sdcall(v,n,mn) = sqrt(sum(vi^2 for vi in v) / n - mn^2) | |
end | |
for j in 1:size(A, 2) | |
k = A.colptr[j]:(A.colptr[j+1] - 1) | |
if length(k) > 0 | |
v = view(A.nzval, k) | |
mn = mean(v) * (length(k) / n) | |
sd = sdcall(v,n,mn) | |
sd2 = sqrt(sum(vi^2 for vi in v) / (n - 1) - (n / (n - 1)) * mn^2) | |
println("sdcall is $(sd)\tsdinline is $(sd2)") | |
A.nzval[k] .= v ./ sd | |
end | |
end | |
return A | |
end | |
A = sprand(10, 10, 0.1); | |
std(A, 1) | |
scale_sd!(copy(A)); # sdcall and sdinline different, sdinline correct | |
scale_sd!(copy(A), corrected=false); # ERROR: UndefVarError: sdcall not defined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment