Add assertion to prevent nonsense mod values (#2474)

This commit is contained in:
Paul Gustafson
2023-11-27 18:37:44 -08:00
committed by GitHub
parent 186ac77ec3
commit 98cd9e8926
2 changed files with 7 additions and 1 deletions
+6
View File
@@ -402,6 +402,12 @@ class TestSymbolicSymbolicOps(unittest.TestCase):
with self.assertRaises(AssertionError):
lt3 = (x < 3)
def test_nested_variable_mod(self):
i = Variable("i", 1, 5)
idx0 = Variable("idx0", 0, i)
with self.assertRaises(AssertionError):
assert idx0 % 2 == idx0
def test_num_node_mul_node(self):
a = Variable("a", 1, 5)
b = NumNode(2) * a
+1 -1
View File
@@ -94,7 +94,7 @@ class Node:
if self == b: return NumNode(0)
if (b - self).min > 0 and self.min >= 0: return self # b - self simplifies the node
raise RuntimeError(f"not supported: {self} % {b}")
assert b > 0
assert b > 0 and isinstance(self.max, int) and isinstance(self.min, int), 'not supported'
if b == 1: return NumNode(0)
if self.min >= 0 and self.max < b: return self
if (self.min//b) == (self.max//b): return self - (b*(self.min//b))