Skip to content

Commit 23b1929

Browse files
authored
Fix Coordinate comparison error (#717)
* Adding __lt__ to coordinate class * Fixing codeQL issues
1 parent 3c4193a commit 23b1929

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

model_analyzer/config/generate/coordinate.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Coordinate:
2424
def __init__(self, val: Union['Coordinate', List[int]]):
2525
"""
2626
val: list
27-
List of floats or integers cooresponding to the location in space
27+
List of floats or integers corresponding to the location in space
2828
"""
2929
if isinstance(val, Coordinate):
3030
val = val._values
@@ -74,6 +74,12 @@ def __eq__(self, other: Any) -> bool:
7474
return False
7575
return True
7676

77+
def __lt__(self, other: Any) -> bool:
78+
for i, v in enumerate(self._values):
79+
if v != other[i]:
80+
return v < other[i]
81+
return False
82+
7783
def round(self) -> None:
7884
""" Rounds the coordinate in-place """
7985
for i, _ in enumerate(self._values):

tests/test_coordinate.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,18 @@ def test_enumerate(self):
119119
def test_stringification(self):
120120
c1 = Coordinate([2, 4, 1, 7])
121121
self.assertEqual("[2, 4, 1, 7]", c1.__str__())
122+
123+
def test_compare(self):
124+
c1 = Coordinate([1, 3, 2])
125+
c2 = Coordinate([1, 3, 2])
126+
c3 = Coordinate([1, 3, 1])
127+
c4 = Coordinate([1, 3, 3])
128+
c5 = Coordinate([2, 1, 3])
129+
c6 = Coordinate([0, 1, 3])
130+
131+
self.assertEqual(c1, c2)
132+
self.assertGreater(c1, c3)
133+
self.assertLess(c3, c1)
134+
self.assertLess(c1, c4)
135+
self.assertLess(c1, c5)
136+
self.assertGreater(c1, c6)

tests/test_neighborhood.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ def test_all_same_throughputs(self):
757757
step_vector = n._get_step_vector()
758758
self.assertEqual(step_vector, Coordinate([0, 0, 0]))
759759

760+
n.force_slow_mode()
760761
new_coord = n.determine_new_home()
761762
self.assertEqual(new_coord, Coordinate([1, 1, 1]))
762763

0 commit comments

Comments
 (0)