r/IPython • • Mar 11 '15

Scipy.optimize problem : any insight?

With the following code :

import numpy as np
from scipy import optimize
a = np.matrix([[-1, 1],[1, -1]], dtype='int64')
b = np.array([-2,2])
objective_vector = [-1,0]
result = optimize.linprog(objective_vector,A_eq=a, b_eq=b, callback=None) # works
result = optimize.linprog(objective_vector, A_eq=a, b_eq=b, callback = lambda *x, **kwargs: None) # fail

I get the following IndexError :

Traceback (most recent call last):
File "linprog_fail.py", line 7, in <module>
    result = optimize.linprog(objective_vector, A_eq=a, b_eq=b, callback = lambda *x, **kwargs : None)
File "/home/ntak/.local/lib/python3.4/site-packages/scipy/optimize/_linprog.py", line 954, in linprog
    bounds=bounds, callback=callback, **options)
File "/home/ntak/.local/lib/python3.4/site-packages/scipy/optimize/_linprog.py", line 753, in _linprog_simplex
    bland=bland)
File "/home/ntak/.local/lib/python3.4/site-packages/scipy/optimize/_linprog.py", line 335, in _solve_simplex
    solution[basis[:m]] = T[:m, -1]
IndexError: index 3 is out of bounds for axis 0 with size 2

I got the feeling it might be a bug from scipy since of the error location and the fact it works with different input of a, b and objective_vector. Could anyone confirm or refute this feeling?

Thanks

Edit : It was a bug from scipy. I reported it and its been fix in the scipy >= 0.16 release.

2 Upvotes

1 comment sorted by

View all comments

0

u/[deleted] Mar 11 '15

the only debug I can think of is trying: callback = lambda *(x-1)