def test_closure_small(): """ closure on small graph. """ A = np.asarray([[0.0, 0.1, 0.0, 0.2], [0.0, 0.0, 0.3, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.3, 0.0, 0.0]]) # ultrametric source = 0 proxs, paths = clo.closuress(A, source) proxs2, paths2 = clo.cclosuress(A, source, retpaths=1) assert np.allclose(proxs, proxs2) for p1, p2 in zip(paths, paths2): assert np.all(p1 == p2) # metric proxs, paths = clo.closuress(A, source, kind='metric') proxs2, paths2 = clo.cclosuress(A, source, retpaths=1, kind='metric') assert np.allclose(proxs, proxs2) for p1, p2 in zip(paths, paths2): assert np.all(p1 == p2)
def test_closure_big(): """ closure on large graph + speed test. """ np.random.seed(100) N = 500 thresh = 0.1 A = sp.rand(N, N, thresh, 'csr') A = np.asarray(A.todense()) source = 0 tic = time() proxs, _ = clo.closuress(A, source) toc = time() py_time = toc - tic tic = time() proxs2, _ = clo.cclosuress(A, source) toc = time() cy_time = toc - tic assert np.allclose(proxs, proxs2) assert py_time > cy_time, \ 'python: {:.2g} s, cython: {:.2g} s.'.format(py_time, cy_time)