Skip to content

Commit

Permalink
Rename approx_equal() -> equals() (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Nov 6, 2023
1 parent e0a27b5 commit 47f7bd8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions graphslam/edge/base_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def plot(self, color=""):
"""

def approx_equal(self, other, tol=1e-6):
"""Check whether two edges are approximately equal.
def equals(self, other, tol=1e-6):
"""Check whether two edges are equal.
Parameters
----------
Expand All @@ -195,7 +195,7 @@ def approx_equal(self, other, tol=1e-6):
Returns
-------
bool
Whether the two edges are approximately equal
Whether the two edges are equal
"""
if len(self.vertex_ids) != len(other.vertex_ids):
Expand All @@ -210,7 +210,7 @@ def approx_equal(self, other, tol=1e-6):
# fmt: on

if isinstance(self.estimate, BasePose):
return isinstance(other.estimate, BasePose) and self.estimate.approx_equal(other.estimate, tol)
return isinstance(other.estimate, BasePose) and self.estimate.equals(other.estimate, tol)

# fmt: off
return not isinstance(other.estimate, BasePose) and np.linalg.norm(self.estimate - other.estimate) / max(np.linalg.norm(self.estimate), tol) < tol
Expand Down
8 changes: 4 additions & 4 deletions graphslam/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ def plot(self, vertex_color="r", vertex_marker="o", vertex_markersize=3, edge_co

plt.show()

def approx_equal(self, other, tol=1e-6):
"""Check whether two graphs are approximately equal.
def equals(self, other, tol=1e-6):
"""Check whether two graphs are equal.
Parameters
----------
Expand All @@ -390,13 +390,13 @@ def approx_equal(self, other, tol=1e-6):
Returns
-------
bool
Whether the two graphs are approximately equal
Whether the two graphs are equal
"""
# pylint: disable=protected-access
if len(self._edges) != len(other._edges) or len(self._vertices) != len(other._vertices):
return False

# fmt: off
return all(e1.approx_equal(e2, tol) for e1, e2 in zip(self._edges, other._edges)) and all(v1.pose.approx_equal(v2.pose, tol) for v1, v2 in zip(self._vertices, other._vertices))
return all(e1.equals(e2, tol) for e1, e2 in zip(self._edges, other._edges)) and all(v1.pose.equals(v2.pose, tol) for v1, v2 in zip(self._vertices, other._vertices))
# fmt: on
6 changes: 3 additions & 3 deletions graphslam/pose/base_pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def to_compact(self):
"""
raise NotImplementedError

def approx_equal(self, other, tol=1e-6):
"""Check whether two poses are approximately equal.
def equals(self, other, tol=1e-6):
"""Check whether two poses are equal.
Parameters
----------
Expand All @@ -57,7 +57,7 @@ def approx_equal(self, other, tol=1e-6):
Returns
-------
bool
Whether the two poses are approximately equal
Whether the two poses are equal
"""
return np.linalg.norm(self.to_array() - other.to_array()) / max(np.linalg.norm(self.to_array()), tol) < tol
Expand Down
14 changes: 7 additions & 7 deletions tests/test_base_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def test_calc_chi2_gradient_hessian(self):
self.assertAlmostEqual(np.linalg.norm(hessian[(v1.gradient_index, v2.gradient_index)] + np.eye(2)), 0.0)
self.assertAlmostEqual(np.linalg.norm(hessian[(v2.gradient_index, v2.gradient_index)] - np.eye(2)), 0.0)

def test_approx_equal(self):
"""Test that the ``approx_equal`` method works as expected."""
def test_equals(self):
"""Test that the ``equals`` method works as expected."""
p1 = PoseR2([1, 2])
p2 = PoseR2([3, 4])
estimate = PoseR2([0, 0])
Expand All @@ -97,19 +97,19 @@ def test_approx_equal(self):
e1 = EdgeOdometry([1, 2], np.eye(2), estimate, [v1, v2])
e2 = EdgeOdometry([1, 2], np.eye(2), estimate, [v1, v2])

self.assertTrue(e1.approx_equal(e2))
self.assertTrue(e1.equals(e2))

e2.estimate = 123
self.assertFalse(e2.approx_equal(e1))
self.assertFalse(e2.equals(e1))

e2.information = np.eye(1)
self.assertFalse(e1.approx_equal(e2))
self.assertFalse(e1.equals(e2))

e2.vertex_ids = [3, 4]
self.assertFalse(e1.approx_equal(e2))
self.assertFalse(e1.equals(e2))

e2.vertex_ids = [5]
self.assertFalse(e1.approx_equal(e2))
self.assertFalse(e1.equals(e2))


if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def test_plot(self):
with patch("graphslam.graph.plt.show"):
self.g.plot(title="Title")

def test_approx_equal(self):
"""Test that the ``approx_equal`` method returns False when comparing to an empty graph."""
def test_equals(self):
"""Test that the ``equals`` method returns False when comparing to an empty graph."""
g = Graph([], [])
self.assertFalse(g.approx_equal(self.g))
self.assertFalse(g.equals(self.g))


class TestGraphR3(TestGraphR2):
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_intel(self):
# g.to_g2o(optimized)

g2 = load_g2o_se2(optimized)
self.assertTrue(g.approx_equal(g2))
self.assertTrue(g.equals(g2))

def test_parking_garage(self):
"""Test for optimizing the parking garage dataset."""
Expand All @@ -318,7 +318,7 @@ def test_parking_garage(self):
# g.to_g2o(optimized)

g2 = load_g2o_se3(optimized)
self.assertTrue(g.approx_equal(g2))
self.assertTrue(g.equals(g2))


if __name__ == "__main__":
Expand Down

0 comments on commit 47f7bd8

Please sign in to comment.