def test_length_memory_leaks(): # Test some dtypes dtypes = [np.float32, np.float64, np.int32, np.int64] for dtype in dtypes: rng = np.random.RandomState(1234) NB_STREAMLINES = 10000 streamlines = [rng.randn(rng.randint(10, 100), 3).astype(dtype) for _ in range(NB_STREAMLINES)] list_refcount_before = get_type_refcount()["list"] lengths = length(streamlines) list_refcount_after = get_type_refcount()["list"] # Calling `length` shouldn't increase the refcount of `list` # since the return value is a numpy array. assert_equal(list_refcount_after, list_refcount_before) # Test mixed dtypes rng = np.random.RandomState(1234) NB_STREAMLINES = 10000 streamlines = [] for i in range(NB_STREAMLINES): dtype = dtypes[i % len(dtypes)] streamlines.append(rng.randn(rng.randint(10, 100), 3).astype(dtype)) list_refcount_before = get_type_refcount()["list"] lengths = length(streamlines) list_refcount_after = get_type_refcount()["list"] # Calling `length` shouldn't increase the refcount of `list` # since the return value is a numpy array. assert_equal(list_refcount_after, list_refcount_before)
def test_length_memory_leaks(): # Test some dtypes dtypes = [np.float32, np.float64, np.int32, np.int64] for dtype in dtypes: rng = np.random.RandomState(1234) NB_STREAMLINES = 10000 streamlines = [rng.randn(rng.randint(10, 100), 3).astype(dtype) for _ in range(NB_STREAMLINES)] list_refcount_before = get_type_refcount()["list"] lengths = ds_length(streamlines) list_refcount_after = get_type_refcount()["list"] # Calling `ds_length` shouldn't increase the refcount of `list` # since the return value is a numpy array. assert_equal(list_refcount_after, list_refcount_before) # Test mixed dtypes rng = np.random.RandomState(1234) NB_STREAMLINES = 10000 streamlines = [] for i in range(NB_STREAMLINES): dtype = dtypes[i % len(dtypes)] streamlines.append(rng.randn(rng.randint(10, 100), 3).astype(dtype)) list_refcount_before = get_type_refcount()["list"] lengths = ds_length(streamlines) list_refcount_after = get_type_refcount()["list"] # Calling `ds_length` shouldn't increase the refcount of `list` # since the return value is a numpy array. assert_equal(list_refcount_after, list_refcount_before)
def test_compress_streamlines_memory_leaks(): # Test some dtypes dtypes = [np.float32, np.float64, np.int32, np.int64] for dtype in dtypes: rng = np.random.RandomState(1234) NB_STREAMLINES = 10000 streamlines = [rng.randn(rng.randint(10, 100), 3).astype(dtype) for _ in range(NB_STREAMLINES)] list_refcount_before = get_type_refcount()["list"] cstreamlines = compress_streamlines(streamlines) list_refcount_after = get_type_refcount()["list"] del cstreamlines # Delete `cstreamlines` because it holds a reference to `list`. # Calling `compress_streamlines` should increase the refcount of `list` by one # since we kept the returned value. assert_equal(list_refcount_after, list_refcount_before+1) # Test mixed dtypes rng = np.random.RandomState(1234) NB_STREAMLINES = 10000 streamlines = [] for i in range(NB_STREAMLINES): dtype = dtypes[i % len(dtypes)] streamlines.append(rng.randn(rng.randint(10, 100), 3).astype(dtype)) list_refcount_before = get_type_refcount()["list"] cstreamlines = compress_streamlines(streamlines) list_refcount_after = get_type_refcount()["list"] # Calling `compress_streamlines` should increase the refcount of `list` by one # since we kept the returned value. assert_equal(list_refcount_after, list_refcount_before+1)
def test_compress_streamlines_memory_leaks(): # Test some dtypes dtypes = [np.float32, np.float64, np.int32, np.int64] for dtype in dtypes: rng = np.random.RandomState(1234) NB_STREAMLINES = 10000 streamlines = [rng.randn(rng.randint(10, 100), 3).astype(dtype) for _ in range(NB_STREAMLINES)] list_refcount_before = get_type_refcount()["list"] cstreamlines = compress_streamlines(streamlines) list_refcount_after = get_type_refcount()["list"] del cstreamlines # Delete `cstreamlines` because it holds a reference # to `list`. # Calling `compress_streamlines` should increase the refcount of `list` # by one since we kept the returned value. assert_equal(list_refcount_after, list_refcount_before+1) # Test mixed dtypes rng = np.random.RandomState(1234) NB_STREAMLINES = 10000 streamlines = [] for i in range(NB_STREAMLINES): dtype = dtypes[i % len(dtypes)] streamlines.append(rng.randn(rng.randint(10, 100), 3).astype(dtype)) list_refcount_before = get_type_refcount()["list"] cstreamlines = compress_streamlines(streamlines) list_refcount_after = get_type_refcount()["list"] # Calling `compress_streamlines` should increase the refcount of `list` by # one since we kept the returned value. assert_equal(list_refcount_after, list_refcount_before+1)
def test_quickbundles_memory_leaks(): qb = QuickBundles(threshold=2 * threshold) type_name_pattern = "memoryview" initial_types_refcount = get_type_refcount(type_name_pattern) qb.cluster(data) # At this point, all memoryviews created during clustering should be freed. assert_equal(get_type_refcount(type_name_pattern), initial_types_refcount)
def test_quickbundles_memory_leaks(): qb = QuickBundles(threshold=2*threshold) type_name_pattern = "memoryview" initial_types_refcount = get_type_refcount(type_name_pattern) qb.cluster(data) # At this point, all memoryviews created during clustering should be freed. assert_equal(get_type_refcount(type_name_pattern), initial_types_refcount)
def test_get_type_refcount(): list_ref_count = get_type_refcount("list") A = list() assert_equal(get_type_refcount("list")["list"], list_ref_count["list"] + 1) del A assert_equal(get_type_refcount("list")["list"], list_ref_count["list"])
def test_get_type_refcount(): list_ref_count = get_type_refcount("list") A = list() assert_equal(get_type_refcount("list")["list"], list_ref_count["list"]+1) del A assert_equal(get_type_refcount("list")["list"], list_ref_count["list"])