def test_partition_multilevel(self): self.graph_partition._params['multilevel'] = False self.graph_partition._partition() p_s = self.graph_partition._rel_parts self.graph_partition._rel_parts = None self.graph_partition._params['multilevel'] = True self.graph_partition._partition() p_m = self.graph_partition._rel_parts assert_array_equal(p_s, p_m)
def test_split_pairs(self): g_l, g_r = self.graph_diff.split([25, 25, 25, 25]) p = self.graph_diff._pair_pp p_l = g_l._pair_pp p_r = g_r._pair_pp l = p.shape[0] for i in range(l): for j in range(i + 1, l): assert_array_equal(p_l[i, j], p[i, j][:25, :25]) assert_array_equal(p_r[i, j], p[i, j][25:, 25:]) for j in range(i + 1): self.assertEqual(p[i, j], None) self.assertEqual(p_l[i, j], None)
def test_split(self): g_l, g_r = self.graph.split(self.graph_l.ends) self.assertEqual(str(self.graph_l), str(g_l)) self.assertEqual(str(self.graph_r), str(g_r)) assert_array_equal(g_l.starts, [0, 0, 0, 0]) assert_array_equal(g_l.ends, self.graph_l.ends) assert_array_equal(g_r.starts, self.graph_l.ends) assert_array_equal(g_r.ends, self.graph.ends)
def test_align_cut(self): MIN = 0 MAX = 0.1 def is_cut(ar): return ((ar > MIN) & (ar < MAX)).any() pairs0 = self._align(self.records_diff, cut=MIN) pairs0 = to_dense(pairs0) self.assertTrue(is_cut(pairs0)) pairs1 = self._align(self.records_diff, cut=MAX) pairs1 = to_dense(pairs1) self.assertFalse(is_cut(pairs1)) def uncut(ar): return (ar <= MIN) | (ar >= MAX) assert_array_equal(pairs0[uncut(pairs0)], pairs1[uncut(pairs0)]) pairs0[pairs0 < MAX] = 0 assert_array_equal(pairs0, pairs1)
def test_prune(self): input = csr_matrix([[0, 1, 2, 3], [3, 2, 1, 0], [2, 0, 3, 1]]) output0 = input output1 = [[0, 0, 2, 3], [3, 2, 0, 0], [2, 0, 3, 0]] output2 = [[0, 0, 0, 3], [3, 0, 0, 0], [0, 0, 3, 0]] output3 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] input = input prune(input, 1) assert_array_equal(input, output0) prune(input, 2) assert_array_equal(input, output1) prune(input, 3) assert_array_equal(input, output2) prune(input, 4) assert_array_equal(input, output3)
def test_lengths(self): assert_array_equal(self.graph.lengths, [4, 5, 4, 4]) assert_array_equal(self.graph_l.lengths, [3, 4, 3, 3]) assert_array_equal(self.graph_r.lengths, [1, 1, 1, 1]) assert_array_equal(self.graph_4.lengths, [1, 0, 0, 1])
def test_partition(self): assert_array_equal(self.graph_same.partition, [41, 41]) assert_array_equal(self.graph_partition.partition, [27, 31, 35, 39])
def test_ends(self): assert_array_equal(self.graph.ends, [4, 5, 4, 4]) assert_array_equal(self.graph_l.ends, [3, 4, 3, 3]) assert_array_equal(self.graph_r.ends, [1, 1, 1, 1]) assert_array_equal(self.graph_4.ends, [1, 0, 0, 1])
def test_starts(self): assert_array_equal(self.graph.starts, [0, 0, 0, 0]) assert_array_equal(self.graph_l.starts, [0, 0, 0, 0]) assert_array_equal(self.graph_r.starts, [0, 0, 0, 0]) assert_array_equal(self.graph_4.starts, [0, 0, 0, 0])
def test_pairwise_same(self): pairs = self._pairwise(self.records_same) assert_array_equal(pairs[0, 1], pairs[0, 2]) assert_array_equal(pairs[0, 1], pairs[1, 2])