def test_broadcast_shapes_raises(): # tests public broadcast_shapes data = [ [(3, ), (4, )], [(2, 3), (2, )], [(3, ), (3, ), (4, )], [(1, 3, 4), (2, 3, 3)], [(1, 2), (3, 1), (3, 2), (10, 5)], [2, (2, 3)], ] for input_shapes in data: assert_raises(ValueError, lambda: broadcast_shapes(*input_shapes)) bad_args = [(2, )] * 32 + [(3, )] * 32 assert_raises(ValueError, lambda: broadcast_shapes(*bad_args))
def test_broadcast_shapes_succeeds(): # tests public broadcast_shapes data = [ [[], ()], [[()], ()], [[(7, )], (7, )], [[(1, 2), (2, )], (1, 2)], [[(1, 1)], (1, 1)], [[(1, 1), (3, 4)], (3, 4)], [[(6, 7), (5, 6, 1), (7, ), (5, 1, 7)], (5, 6, 7)], [[(5, 6, 1)], (5, 6, 1)], [[(1, 3), (3, 1)], (3, 3)], [[(1, 0), (0, 0)], (0, 0)], [[(0, 1), (0, 0)], (0, 0)], [[(1, 0), (0, 1)], (0, 0)], [[(1, 1), (0, 0)], (0, 0)], [[(1, 1), (1, 0)], (1, 0)], [[(1, 1), (0, 1)], (0, 1)], [[(), (0, )], (0, )], [[(0, ), (0, 0)], (0, 0)], [[(0, ), (0, 1)], (0, 0)], [[(1, ), (0, 0)], (0, 0)], [[(), (0, 0)], (0, 0)], [[(1, 1), (0, )], (1, 0)], [[(1, ), (0, 1)], (0, 1)], [[(1, ), (1, 0)], (1, 0)], [[(), (1, 0)], (1, 0)], [[(), (0, 1)], (0, 1)], [[(1, ), (3, )], (3, )], [[2, (3, 2)], (3, 2)], ] for input_shapes, target_shape in data: assert_equal(broadcast_shapes(*input_shapes), target_shape) assert_equal(broadcast_shapes(*([(1, 2)] * 32)), (1, 2)) assert_equal(broadcast_shapes(*([(1, 2)] * 100)), (1, 2)) # regression tests for gh-5862 assert_equal(broadcast_shapes(*([(2, )] * 32)), (2, ))