Beispiel #1
0
 def test_cross_comb(self):
     """cross_comb should produce correct combinations"""
     v1 = range(2)
     v2 = range(3)
     v3 = list("abc")
     vv1 = ([e] for e in v1)
     v1_x_v2 = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2]]
     v1v2v3 = [
         [0, 0, "a"],
         [0, 0, "b"],
         [0, 0, "c"],
         [0, 1, "a"],
         [0, 1, "b"],
         [0, 1, "c"],
         [0, 2, "a"],
         [0, 2, "b"],
         [0, 2, "c"],
         [1, 0, "a"],
         [1, 0, "b"],
         [1, 0, "c"],
         [1, 1, "a"],
         [1, 1, "b"],
         [1, 1, "c"],
         [1, 2, "a"],
         [1, 2, "b"],
         [1, 2, "c"],
     ]
     self.assertEqual(list(_increment_comb(vv1, v2)), v1_x_v2)
     self.assertEqual(list(cross_comb([v1, v2])), v1_x_v2)
     self.assertEqual(list(cross_comb([v1, v2, v3])), v1v2v3)
Beispiel #2
0
 def test_cross_comb(self):
     """cross_comb should produce correct combinations"""
     v1 = list(range(2))
     v2 = list(range(3))
     v3 = list('abc')
     vv1 = ([e] for e in v1)
     v1_x_v2 = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2]]
     v1v2v3 = [[0, 0, 'a'], [0, 0, 'b'], [0, 0, 'c'], [0, 1, 'a'],
               [0, 1, 'b'], [0, 1, 'c'], [0, 2, 'a'], [0, 2, 'b'],
               [0, 2, 'c'], [1, 0, 'a'], [1, 0, 'b'], [1, 0, 'c'],
               [1, 1, 'a'], [1, 1, 'b'], [1, 1, 'c'], [1, 2, 'a'],
               [1, 2, 'b'], [1, 2, 'c']]
     self.assertEqual(list(_increment_comb(vv1, v2)), v1_x_v2)
     self.assertEqual(list(cross_comb([v1, v2])), v1_x_v2)
     self.assertEqual(list(cross_comb([v1, v2, v3])), v1v2v3)
Beispiel #3
0
def cartesian_product(lists):
    """Returns cartesian product of lists as list of tuples.

    WARNING: Explicitly constructs list in memory. Should use generator
    version in cogent.util.transform instead for most uses.

    Provided for compatibility.
    """
    return map(tuple, cross_comb(lists))
Beispiel #4
0
def cartesian_product(lists):
    """Returns cartesian product of lists as list of tuples.

    WARNING: Explicitly constructs list in memory. Should use generator
    version in cogent.util.transform instead for most uses.

    Provided for compatibility.
    """
    return map(tuple, cross_comb(lists))