dtype problem in flatten model process
Closed this issue · 2 comments
Hi,
when I was flattening wsum expression like [numpy.int64 objects] * [intvars]
,
(object numbers are about 1e8, which is below int32 upper bound, but the wsum bound may exceed.)
error occured on cpmpy.expressions.core.Operator.get_bounds, which gives false bounds from overflowed numpy.sum().
problem solved after I raised first object over int32 upper bound.
Hi Charlez,
So do I understand correctly that the get_bounds()
method returned an overflowed np.int32, instead of an int64? And how did you solve it?
I don't seem to be able to reproduce it, this runs fine:
v = 2 ** 33
print(v)
v3 = np.array([v,v], dtype="int64")
print(v3)
e = sum(v3*cp.intvar(1,9, shape=(2)))
print(e)
print(e.get_bounds())
8589934592
[8589934592 8589934592]
sum([8589934592, 8589934592] * [IV11, IV12])
(17179869184, 154618822656)
Hi tias,
Thanks for responding. After revisit, I found that the triggering conditions are not as simple as I originally thought it was.
Here's the code for reproduce this problem.
v = intvar(0,1,(2))
v2 = np.array([int(1e9),int(1e9)], dtype="int64")
v3 = [2,2]
e = min((sum(v * v2 * v3),int(1e9)))
print(e.get_bounds()) # this works fine
m = Model()
m += e == 0
m.solve() # AssertionError: assert (lb <= ub) caused by overflow bounds
And how did you solve it?
Raise 1e9 to 1e10