Skip to content

Commit

Permalink
Merge pull request #680 from dstl/mean_measures
Browse files Browse the repository at this point in the history
Remove `hasattr` in Measures to avoid calling `mean` twice
  • Loading branch information
sdhiscocks authored Jul 28, 2022
2 parents f36afad + af1213d commit c098a63
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions stonesoup/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,8 @@ def __call__(self, state1, state2):
"""
# Calculate Euclidean distance between two state
if hasattr(state1, 'mean'):
state_vector1 = state1.mean
else:
state_vector1 = state1.state_vector
if hasattr(state2, 'mean'):
state_vector2 = state2.mean
else:
state_vector2 = state2.state_vector
state_vector1 = getattr(state1, 'mean', state1.state_vector)
state_vector2 = getattr(state2, 'mean', state2.state_vector)

if self.mapping is not None:
return distance.euclidean(state_vector1[self.mapping, 0],
Expand Down Expand Up @@ -136,14 +130,8 @@ def __call__(self, state1, state2):
:class:`~.State` objects
"""
if hasattr(state1, 'mean'):
state_vector1 = state1.mean
else:
state_vector1 = state1.state_vector
if hasattr(state2, 'mean'):
state_vector2 = state2.mean
else:
state_vector2 = state2.state_vector
state_vector1 = getattr(state1, 'mean', state1.state_vector)
state_vector2 = getattr(state2, 'mean', state2.state_vector)

if self.mapping is not None:
return distance.euclidean(state_vector1[self.mapping, 0],
Expand Down Expand Up @@ -185,14 +173,8 @@ def __call__(self, state1, state2):
objects
"""
if hasattr(state1, 'mean'):
state_vector1 = state1.mean
else:
state_vector1 = state1.state_vector
if hasattr(state2, 'mean'):
state_vector2 = state2.mean
else:
state_vector2 = state2.state_vector
state_vector1 = getattr(state1, 'mean', state1.state_vector)
state_vector2 = getattr(state2, 'mean', state2.state_vector)

if self.mapping is not None:
u = state_vector1[self.mapping, 0]
Expand Down

0 comments on commit c098a63

Please sign in to comment.