Closed rschwarz closed 2 years ago
Using Pdb and stepping into the constraint creation, it seems that LinExp.__eq__
is called after all, but for some reason, it still returns a numpy.bool_
.
@rschwarz With #244 your issue should be solved. I have updated some of the arithmetic to be fully commutative.
Fixed with Release 1.14.0
Constraints are built with coefficients that are in a NumPy array (
float64
). A coefficient of0.0
multiplied with with the left-hand side leads to the valueTrue
of typenumpy.bool_
, rather than amip.LinExpr
.Consider this example:
This results in
I would have expected that both
cons1
andcons2
yield aLinExpr
.Note that the problem does not occur if:
float
of0.0
instead of thecoeffs[0]
reference to a NumPy array.coeffs[0] * x
cons2
).The behavior is strange to me, since it's the case that
isinstance(coeffs[0], float)
givesTrue
, so it should be handled the same way when themip
library compares againsnumbers.Real
.So, is this a problem with
__add__
in somenumpy
type?