Skip to content

Commit

Permalink
TST: Add test that reference counts are not leaked
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbell10 authored and tylerjereddy committed Jul 23, 2021
1 parent 7f01981 commit da394e6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scipy/spatial/tests/test_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import os.path

from functools import wraps, partial
import weakref

import numpy as np
import warnings
Expand Down Expand Up @@ -650,6 +651,28 @@ def test_striding(self):
# test that output is numerically equivalent
_assert_within_tol(Y1, Y2, eps, verbose > 2)

def test_cdist_refcount(self):
with suppress_warnings() as sup:
sup.filter(DeprecationWarning, "'wminkowski' metric is deprecated")
for metric in _METRICS_NAMES:
x1 = np.random.rand(10, 10)
x2 = np.random.rand(10, 10)

kwargs = dict()
if metric in ['minkowski', 'wminkowski']:
kwargs['p'] = 1.23
if metric == 'wminkowski':
kwargs['w'] = 1.0 / x1.std(axis=0)

out = cdist(x1, x2, metric=metric, **kwargs)

# Check reference counts aren't messed up. If we only hold weak
# references, the arrays should be deallocated.
weak_refs = [weakref.ref(v) for v in (x1, x2, out)]
del x1, x2, out
assert all(weak_ref() is None for weak_ref in weak_refs)


class TestPdist:

def setup_method(self):
Expand Down

0 comments on commit da394e6

Please sign in to comment.