Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jsams
Created October 9, 2017 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsams/80e2897a62ba67f7015951b6b078c294 to your computer and use it in GitHub Desktop.
Save jsams/80e2897a62ba67f7015951b6b078c294 to your computer and use it in GitHub Desktop.
metaprogramming error
function scale_sd!(A::SparseMatrixCSC; corrected=true)
n = size(A, 1)
if corrected
sdcall = :(sqrt(sum(vi^2 for vi in v) / (n - 1) - (n / (n - 1)) * mn^2))
else
sdcall = :(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
continue
end
v = view(A.nzval, k)
mn = mean(v) * (length(k) / n)
A.nzval[k] .= v ./ eval(sdcall)
end
return A
end
A = sprand(10, 10, 0.1);
scale_sd!(A);
#ERROR: UndefVarError: v not defined
#Stacktrace:
# [1] eval(::Module, ::Any) at ./boot.jl:288
# [2] eval(::Any) at ./boot.jl:287
# [3] #scale_sd!#1(::Bool, ::Function, ::SparseMatrixCSC{Float64,Int64}) at ./REPL[1]:15
# [4] scale_sd!(::SparseMatrixCSC{Float64,Int64}) at ./REPL[1]:2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment