def test_top_segments_dense(): a = np.ones((300, 100)) seg = top_segment_proportions(a, [50, 100]) assert (seg[:, 0] == .5).all() assert (seg[:, 1] == 1.).all() segfull = top_segment_proportions(a, np.arange(100) + 1) propfull = top_proportions(a, 100) assert (segfull == propfull).all()
def test_top_segments_sparse(): a_dense = np.ones((300, 100)) for fmt in [sparse.csr_matrix, sparse.csc_matrix, sparse.coo_matrix]: a = fmt(a_dense) seg = top_segment_proportions(a, [50, 100]) assert (seg[:, 0] == .5).all() assert (seg[:, 1] == 1.).all() segfull = top_segment_proportions(a, np.arange(100) + 1) propfull = top_proportions(a, 100) assert (segfull == propfull).all()
def test_segments_binary(): a = np.concatenate([np.zeros((300, 50)), np.ones((300, 50))], 1) a = np.apply_along_axis(np.random.permutation, 1, a) seg = top_segment_proportions(a, [25, 50, 100]) assert (seg[:, 0] == .5).all() assert (top_segment_proportions(a, [25]) == .5).all() assert (seg[:, 1] == 1.).all() assert (seg[:, 2] == 1.).all() segfull = top_segment_proportions(a, np.arange(100) + 1) propfull = top_proportions(a, 100) assert (segfull == propfull).all()