Per the error message, 'using' is not allowed there. Move it outside the
function body and the rest should be fine.
On Oct 1, 2014 6:55 AM, "Thomas Moore" <[email protected]> wrote:

> When I place the line
>
> using PyCall
> @pyimport scipy.optimize as optim
>
>
> inside this function (a simple implicit-euler scheme)
>
> function odeEulerImp(F, y0, xvals)
>
>     #placed in the function!
>     using PyCall
>     @pyimport scipy.optimize as optim
>
>     yout = Array(typeof(y0), length(xvals))
>     yout[1] = y0
>     for i = 1:length(xvals)-1
>         h = xvals[i+1]-xvals[i]
>         Fzero(y) = y-h*F(xvals[i+1],y)-yout[i]
>         yout[i+1] = optim.newton(Fzero, yout[i])
>     end
>     return xvals, yout
> end
>
>
>
> I get the following error upon calling the function:
>
> error compiling odeEulerImp: unsupported or misplaced expression using in 
> function odeEulerImp
>
>
> However, if I remove these lines from the function, and instead type them 
> before calling the function (something like:
>
>
> using PyCall
> @pyimport scipy.optimize as optim
> xsteps1, yout1 = odeEulerImp(F, y0, xsteps1)
>
> Then I have no problems. It seems calling PyCall from inside a function is 
> leading to trouble. This is no inconvenience to me, but I was surprised by 
> it, and wanted to check people knew about the behaviour.
>
>

Reply via email to