This works fine for me, for example to minimize x'Ax-x'b (equivalent to
solving A \ b):
using PyCall
@pyimport scipy.optimize as so
A = randn(10,10); A = A'*A # random posdef matrix
b = rand(10)
x = so.fmin_cg(x -> 0.5*dot(x,A*x) - dot(b,x), zeros(10), fprime = x -> A*x
- b, gtol=1e-7)
norm(x - A \ b)
If you want to pass extra args via the "args" keyword, this works for me
too (e.g. to pass b via the "args" tuple keyword):
x = so.fmin_cg((x,b) -> 0.5*dot(x,A*x) - dot(b,x), zeros(10), args = (b,),
fprime = (x,b) -> A*x - b, gtol=1e-7)
This feature is completely pointless, however, in any language like Python
or Julia that has lexical scoping and anonymous functions — notice how I
was able to pass extra information like "A" and "b" to fmin_cg in my first
example just fine, because they are captured by the "x -> ..." closure.
It never fails to amaze me how many Python programmers don't understand
this ("how do I pass extra arguments" is one of the most common questions
of NLopt Python users), and that people like the SciPy programmers include
a clumsy "args" feature simulating closures in a language that already has
real closures.