@. and UndefVarError

You don’t need to apply @. to the entire function (and I wouldn’t recommend doing so, for exactly the reason you’ve run into here). The problem is that @. turns your = into .=, which in turn transforms w = ... into w .= ... which tries to broadcast the result into the (non-existent) array w.

Instead, just do:

function dummy(x, p)
  w = @.(3.0*x[:,2] +p[1] +x[:,1]*p[2])
  return w
end

Also, please quote your code so that it will render correctly.

1 Like