Skip to content

Commit

Permalink
perf: remove redundant covariance computations
Browse files Browse the repository at this point in the history
  • Loading branch information
prokolyvakis authored Nov 10, 2023
1 parent 48a6bec commit 9006301
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions mudpod/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ def compute(self, arr: np.ndarray, o: np.ndarray, a: float) -> np.ndarray:
Returns:
The distances with respect to the observer `o`.
"""
def dist(x: np.ndarray) -> float:
if self.dtype == 'euclidean':
return euclidean(x, o)
if self.dtype == 'mahalanobis':
c = np.cov(arr.T)
return mahalanobis(x, o, c)
if self.dtype == 'euclidean':
dist = lambda x: euclidean(x, o)
else:
c = np.cov(arr.T)
dist = lambda x: mahalanobis(x, o, c)

ds = np.apply_along_axis(
dist,
Expand Down

0 comments on commit 9006301

Please sign in to comment.