fix for "ValueError: domain error" in sqrt in misc.py

757 views
Skip to first unread message

nulix

unread,
Feb 8, 2010, 10:50:20 AM2/8/10
to CVXOPT
I thought I should give something back to this board seeing as it was
a big help when I was building cvxopt with atlas... so in case anyone
else hits this issue as well, here is how (I think) I fixed it.
When running lots of conelp programs with large numbers of variables
(1500 or so) eventually the optimistation would hit a case where it
was sqrt'ing a negative number in misc.py using base.sqrt and die on a
ValueError. I simply abs'd the arrays being sqrt'd as it seemed to be
in code which controls the steps of the solver rather than the code of
the solver itself. This worked for me and didn't seem to effect the
correctness of the solutions.

Maybe someone who knows more about the algorithm in cvxopt can explain
whether this change is correct or not.

diff of my misc.py with that in the tarball is below.

< s[:m] = base.sqrt( s[:m] )
< z[:m] = base.sqrt( z[:m] )
---
> s[:m] = base.sqrt( abs(s[:m]) )
> z[:m] = base.sqrt( abs(z[:m]) )
854c854
< return math.sqrt(x[offset] - a) * math.sqrt(x[offset] + a)
---
> return math.sqrt(abs(x[offset] - a)) * math.sqrt(abs(x[offset] + a))

Reply all
Reply to author
Forward
0 new messages