I don't understand why the first function doesn't change x, but the second function does. Is the = calling deepcopy in f1, but copy in f2? If so, why?
function f1(x::Array) w = x for i in 1:length(x) w[i] += 10.0 end w += 10.0 return w end function f2(x::Array) w = x for i in 1:length(x) w[i] += 10.0 end w += 10.0 return w end x=randn(10) x_orig = deepcopy(x) f_of_x = f(x) sum((x.-x_orig).^2) After f1: 0.0 After f2: 1000.0 Thanks, Eric (on behalf of an Astro 585 student)
