We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
_broadcast_shape is broken when 32 < nargs
xref https://github.com/numpy/numpy/pull/5371

``` python
>>> np.__version__
'1.10.0.dev0+30e3d41'
>>> from numpy.lib.stride_tricks import _broadcast_shape
>>> lst = [np.ones((5, 7, 11))] * 32 + [np.ones((2, 3))] * 32
>>> _broadcast_shape(*lst)
(2, 3)
>>> _broadcast_shape(*lst[::-1])  # process the list in reverse order
(5, 7, 11)
```

In [this line](https://github.com/numpy/numpy/blob/05b5335ecf25e59477956b4f85b9a8edbdf71bcc/numpy/lib/stride_tricks.py#L123) `b` is ultimately converted to an array of shape `1 x 1`; so it will broadcast with the rest of args regardless of their shape.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `numpy/lib/stride_tricks.py`
Content:
```
1 """
2 Utilities that manipulate strides to achieve desirable effects.
3 
4 An explanation of strides can be found in the "ndarray.rst" file in the
5 NumPy reference guide.
6 
7 """
8 from __future__ import division, absolute_import, print_function
9 
10 import numpy as np
11 
12 __all__ = ['broadcast_to', 'broadcast_arrays']
13 
14 
15 class DummyArray(object):
16     """Dummy object that just exists to hang __array_interface__ dictionaries
17     and possibly keep alive a reference to a base array.
18     """
19 
20     def __init__(self, interface, base=None):
21         self.__array_interface__ = interface
22         self.base = base
23 
24 
25 def _maybe_view_as_subclass(original_array, new_array):
26     if type(original_array) is not type(new_array):
27         # if input was an ndarray subclass and subclasses were OK,
28         # then view the result as that subclass.
29         new_array = new_array.view(type=type(original_array))
30         # Since we have done something akin to a view from original_array, we
31         # should let the subclass finalize (if it has it implemented, i.e., is
32         # not None).
33         if new_array.__array_finalize__:
34             new_array.__array_finalize__(original_array)
35     return new_array
36 
37 
38 def as_strided(x, shape=None, strides=None, subok=False):
39     """ Make an ndarray from the given array with the given shape and strides.
40     """
41     # first convert input to array, possibly keeping subclass
42     x = np.array(x, copy=False, subok=subok)
43     interface = dict(x.__array_interface__)
44     if shape is not None:
45         interface['shape'] = tuple(shape)
46     if strides is not None:
47         interface['strides'] = tuple(strides)
48     array = np.asarray(DummyArray(interface, base=x))
49 
50     if array.dtype.fields is None and x.dtype.fields is not None:
51         # This should only happen if x.dtype is [('', 'Vx')]
52         array.dtype = x.dtype
53 
54     return _maybe_view_as_subclass(x, array)
55 
56 
57 def _broadcast_to(array, shape, subok, readonly):
58     shape = tuple(shape) if np.iterable(shape) else (shape,)
59     array = np.array(array, copy=False, subok=subok)
60     if not shape and array.shape:
61         raise ValueError('cannot broadcast a non-scalar to a scalar array')
62     if any(size < 0 for size in shape):
63         raise ValueError('all elements of broadcast shape must be non-'
64                          'negative')
65     broadcast = np.nditer(
66         (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'],
67         op_flags=['readonly'], itershape=shape, order='C').itviews[0]
68     result = _maybe_view_as_subclass(array, broadcast)
69     if not readonly and array.flags.writeable:
70         result.flags.writeable = True
71     return result
72 
73 
74 def broadcast_to(array, shape, subok=False):
75     """Broadcast an array to a new shape.
76 
77     Parameters
78     ----------
79     array : array_like
80         The array to broadcast.
81     shape : tuple
82         The shape of the desired array.
83     subok : bool, optional
84         If True, then sub-classes will be passed-through, otherwise
85         the returned array will be forced to be a base-class array (default).
86 
87     Returns
88     -------
89     broadcast : array
90         A readonly view on the original array with the given shape. It is
91         typically not contiguous. Furthermore, more than one element of a
92         broadcasted array may refer to a single memory location.
93 
94     Raises
95     ------
96     ValueError
97         If the array is not compatible with the new shape according to NumPy's
98         broadcasting rules.
99 
100     Notes
101     -----
102     .. versionadded:: 1.10.0
103 
104     Examples
105     --------
106     >>> x = np.array([1, 2, 3])
107     >>> np.broadcast_to(x, (3, 3))
108     array([[1, 2, 3],
109            [1, 2, 3],
110            [1, 2, 3]])
111     """
112     return _broadcast_to(array, shape, subok=subok, readonly=True)
113 
114 
115 def _broadcast_shape(*args):
116     """Returns the shape of the ararys that would result from broadcasting the
117     supplied arrays against each other.
118     """
119     if not args:
120         raise ValueError('must provide at least one argument')
121     if len(args) == 1:
122         # a single argument does not work with np.broadcast
123         return np.asarray(args[0]).shape
124     # use the old-iterator because np.nditer does not handle size 0 arrays
125     # consistently
126     b = np.broadcast(*args[:32])
127     # unfortunately, it cannot handle 32 or more arguments directly
128     for pos in range(32, len(args), 31):
129         b = np.broadcast(b, *args[pos:(pos + 31)])
130     return b.shape
131 
132 
133 def broadcast_arrays(*args, **kwargs):
134     """
135     Broadcast any number of arrays against each other.
136 
137     Parameters
138     ----------
139     `*args` : array_likes
140         The arrays to broadcast.
141 
142     subok : bool, optional
143         If True, then sub-classes will be passed-through, otherwise
144         the returned arrays will be forced to be a base-class array (default).
145 
146     Returns
147     -------
148     broadcasted : list of arrays
149         These arrays are views on the original arrays.  They are typically
150         not contiguous.  Furthermore, more than one element of a
151         broadcasted array may refer to a single memory location.  If you
152         need to write to the arrays, make copies first.
153 
154     Examples
155     --------
156     >>> x = np.array([[1,2,3]])
157     >>> y = np.array([[1],[2],[3]])
158     >>> np.broadcast_arrays(x, y)
159     [array([[1, 2, 3],
160            [1, 2, 3],
161            [1, 2, 3]]), array([[1, 1, 1],
162            [2, 2, 2],
163            [3, 3, 3]])]
164 
165     Here is a useful idiom for getting contiguous copies instead of
166     non-contiguous views.
167 
168     >>> [np.array(a) for a in np.broadcast_arrays(x, y)]
169     [array([[1, 2, 3],
170            [1, 2, 3],
171            [1, 2, 3]]), array([[1, 1, 1],
172            [2, 2, 2],
173            [3, 3, 3]])]
174 
175     """
176     # nditer is not used here to avoid the limit of 32 arrays.
177     # Otherwise, something like the following one-liner would suffice:
178     # return np.nditer(args, flags=['multi_index', 'zerosize_ok'],
179     #                  order='C').itviews
180 
181     subok = kwargs.pop('subok', False)
182     if kwargs:
183         raise TypeError('broadcast_arrays() got an unexpected keyword '
184                         'argument {}'.format(kwargs.pop()))
185     args = [np.array(_m, copy=False, subok=subok) for _m in args]
186 
187     shape = _broadcast_shape(*args)
188 
189     if all(array.shape == shape for array in args):
190         # Common case where nothing needs to be broadcasted.
191         return args
192 
193     # TODO: consider making the results of broadcast_arrays readonly to match
194     # broadcast_to. This will require a deprecation cycle.
195     return [_broadcast_to(array, shape, subok=subok, readonly=False)
196             for array in args]
197
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/numpy/lib/stride_tricks.py b/numpy/lib/stride_tricks.py
--- a/numpy/lib/stride_tricks.py
+++ b/numpy/lib/stride_tricks.py
@@ -126,6 +126,10 @@
     b = np.broadcast(*args[:32])
     # unfortunately, it cannot handle 32 or more arguments directly
     for pos in range(32, len(args), 31):
+        # ironically, np.broadcast does not properly handle np.broadcast
+        # objects (it treats them as scalars)
+        # use broadcasting to avoid allocating the full array
+        b = broadcast_to(0, b.shape)
         b = np.broadcast(b, *args[pos:(pos + 31)])
     return b.shape

{"golden_diff": "diff --git a/numpy/lib/stride_tricks.py b/numpy/lib/stride_tricks.py\n--- a/numpy/lib/stride_tricks.py\n+++ b/numpy/lib/stride_tricks.py\n@@ -126,6 +126,10 @@\n     b = np.broadcast(*args[:32])\n     # unfortunately, it cannot handle 32 or more arguments directly\n     for pos in range(32, len(args), 31):\n+        # ironically, np.broadcast does not properly handle np.broadcast\n+        # objects (it treats them as scalars)\n+        # use broadcasting to avoid allocating the full array\n+        b = broadcast_to(0, b.shape)\n         b = np.broadcast(b, *args[pos:(pos + 31)])\n     return b.shape\n", "issue": "_broadcast_shape is broken when 32 < nargs\nxref https://github.com/numpy/numpy/pull/5371\n\n``` python\n>>> np.__version__\n'1.10.0.dev0+30e3d41'\n>>> from numpy.lib.stride_tricks import _broadcast_shape\n>>> lst = [np.ones((5, 7, 11))] * 32 + [np.ones((2, 3))] * 32\n>>> _broadcast_shape(*lst)\n(2, 3)\n>>> _broadcast_shape(*lst[::-1])  # process the list in reverse order\n(5, 7, 11)\n```\n\nIn [this line](https://github.com/numpy/numpy/blob/05b5335ecf25e59477956b4f85b9a8edbdf71bcc/numpy/lib/stride_tricks.py#L123) `b` is ultimately converted to an array of shape `1 x 1`; so it will broadcast with the rest of args regardless of their shape.\n\n", "before_files": [{"content": "\"\"\"\nUtilities that manipulate strides to achieve desirable effects.\n\nAn explanation of strides can be found in the \"ndarray.rst\" file in the\nNumPy reference guide.\n\n\"\"\"\nfrom __future__ import division, absolute_import, print_function\n\nimport numpy as np\n\n__all__ = ['broadcast_to', 'broadcast_arrays']\n\n\nclass DummyArray(object):\n    \"\"\"Dummy object that just exists to hang __array_interface__ dictionaries\n    and possibly keep alive a reference to a base array.\n    \"\"\"\n\n    def __init__(self, interface, base=None):\n        self.__array_interface__ = interface\n        self.base = base\n\n\ndef _maybe_view_as_subclass(original_array, new_array):\n    if type(original_array) is not type(new_array):\n        # if input was an ndarray subclass and subclasses were OK,\n        # then view the result as that subclass.\n        new_array = new_array.view(type=type(original_array))\n        # Since we have done something akin to a view from original_array, we\n        # should let the subclass finalize (if it has it implemented, i.e., is\n        # not None).\n        if new_array.__array_finalize__:\n            new_array.__array_finalize__(original_array)\n    return new_array\n\n\ndef as_strided(x, shape=None, strides=None, subok=False):\n    \"\"\" Make an ndarray from the given array with the given shape and strides.\n    \"\"\"\n    # first convert input to array, possibly keeping subclass\n    x = np.array(x, copy=False, subok=subok)\n    interface = dict(x.__array_interface__)\n    if shape is not None:\n        interface['shape'] = tuple(shape)\n    if strides is not None:\n        interface['strides'] = tuple(strides)\n    array = np.asarray(DummyArray(interface, base=x))\n\n    if array.dtype.fields is None and x.dtype.fields is not None:\n        # This should only happen if x.dtype is [('', 'Vx')]\n        array.dtype = x.dtype\n\n    return _maybe_view_as_subclass(x, array)\n\n\ndef _broadcast_to(array, shape, subok, readonly):\n    shape = tuple(shape) if np.iterable(shape) else (shape,)\n    array = np.array(array, copy=False, subok=subok)\n    if not shape and array.shape:\n        raise ValueError('cannot broadcast a non-scalar to a scalar array')\n    if any(size < 0 for size in shape):\n        raise ValueError('all elements of broadcast shape must be non-'\n                         'negative')\n    broadcast = np.nditer(\n        (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'],\n        op_flags=['readonly'], itershape=shape, order='C').itviews[0]\n    result = _maybe_view_as_subclass(array, broadcast)\n    if not readonly and array.flags.writeable:\n        result.flags.writeable = True\n    return result\n\n\ndef broadcast_to(array, shape, subok=False):\n    \"\"\"Broadcast an array to a new shape.\n\n    Parameters\n    ----------\n    array : array_like\n        The array to broadcast.\n    shape : tuple\n        The shape of the desired array.\n    subok : bool, optional\n        If True, then sub-classes will be passed-through, otherwise\n        the returned array will be forced to be a base-class array (default).\n\n    Returns\n    -------\n    broadcast : array\n        A readonly view on the original array with the given shape. It is\n        typically not contiguous. Furthermore, more than one element of a\n        broadcasted array may refer to a single memory location.\n\n    Raises\n    ------\n    ValueError\n        If the array is not compatible with the new shape according to NumPy's\n        broadcasting rules.\n\n    Notes\n    -----\n    .. versionadded:: 1.10.0\n\n    Examples\n    --------\n    >>> x = np.array([1, 2, 3])\n    >>> np.broadcast_to(x, (3, 3))\n    array([[1, 2, 3],\n           [1, 2, 3],\n           [1, 2, 3]])\n    \"\"\"\n    return _broadcast_to(array, shape, subok=subok, readonly=True)\n\n\ndef _broadcast_shape(*args):\n    \"\"\"Returns the shape of the ararys that would result from broadcasting the\n    supplied arrays against each other.\n    \"\"\"\n    if not args:\n        raise ValueError('must provide at least one argument')\n    if len(args) == 1:\n        # a single argument does not work with np.broadcast\n        return np.asarray(args[0]).shape\n    # use the old-iterator because np.nditer does not handle size 0 arrays\n    # consistently\n    b = np.broadcast(*args[:32])\n    # unfortunately, it cannot handle 32 or more arguments directly\n    for pos in range(32, len(args), 31):\n        b = np.broadcast(b, *args[pos:(pos + 31)])\n    return b.shape\n\n\ndef broadcast_arrays(*args, **kwargs):\n    \"\"\"\n    Broadcast any number of arrays against each other.\n\n    Parameters\n    ----------\n    `*args` : array_likes\n        The arrays to broadcast.\n\n    subok : bool, optional\n        If True, then sub-classes will be passed-through, otherwise\n        the returned arrays will be forced to be a base-class array (default).\n\n    Returns\n    -------\n    broadcasted : list of arrays\n        These arrays are views on the original arrays.  They are typically\n        not contiguous.  Furthermore, more than one element of a\n        broadcasted array may refer to a single memory location.  If you\n        need to write to the arrays, make copies first.\n\n    Examples\n    --------\n    >>> x = np.array([[1,2,3]])\n    >>> y = np.array([[1],[2],[3]])\n    >>> np.broadcast_arrays(x, y)\n    [array([[1, 2, 3],\n           [1, 2, 3],\n           [1, 2, 3]]), array([[1, 1, 1],\n           [2, 2, 2],\n           [3, 3, 3]])]\n\n    Here is a useful idiom for getting contiguous copies instead of\n    non-contiguous views.\n\n    >>> [np.array(a) for a in np.broadcast_arrays(x, y)]\n    [array([[1, 2, 3],\n           [1, 2, 3],\n           [1, 2, 3]]), array([[1, 1, 1],\n           [2, 2, 2],\n           [3, 3, 3]])]\n\n    \"\"\"\n    # nditer is not used here to avoid the limit of 32 arrays.\n    # Otherwise, something like the following one-liner would suffice:\n    # return np.nditer(args, flags=['multi_index', 'zerosize_ok'],\n    #                  order='C').itviews\n\n    subok = kwargs.pop('subok', False)\n    if kwargs:\n        raise TypeError('broadcast_arrays() got an unexpected keyword '\n                        'argument {}'.format(kwargs.pop()))\n    args = [np.array(_m, copy=False, subok=subok) for _m in args]\n\n    shape = _broadcast_shape(*args)\n\n    if all(array.shape == shape for array in args):\n        # Common case where nothing needs to be broadcasted.\n        return args\n\n    # TODO: consider making the results of broadcast_arrays readonly to match\n    # broadcast_to. This will require a deprecation cycle.\n    return [_broadcast_to(array, shape, subok=subok, readonly=False)\n            for array in args]\n", "path": "numpy/lib/stride_tricks.py"}], "after_files": [{"content": "\"\"\"\nUtilities that manipulate strides to achieve desirable effects.\n\nAn explanation of strides can be found in the \"ndarray.rst\" file in the\nNumPy reference guide.\n\n\"\"\"\nfrom __future__ import division, absolute_import, print_function\n\nimport numpy as np\n\n__all__ = ['broadcast_to', 'broadcast_arrays']\n\n\nclass DummyArray(object):\n    \"\"\"Dummy object that just exists to hang __array_interface__ dictionaries\n    and possibly keep alive a reference to a base array.\n    \"\"\"\n\n    def __init__(self, interface, base=None):\n        self.__array_interface__ = interface\n        self.base = base\n\n\ndef _maybe_view_as_subclass(original_array, new_array):\n    if type(original_array) is not type(new_array):\n        # if input was an ndarray subclass and subclasses were OK,\n        # then view the result as that subclass.\n        new_array = new_array.view(type=type(original_array))\n        # Since we have done something akin to a view from original_array, we\n        # should let the subclass finalize (if it has it implemented, i.e., is\n        # not None).\n        if new_array.__array_finalize__:\n            new_array.__array_finalize__(original_array)\n    return new_array\n\n\ndef as_strided(x, shape=None, strides=None, subok=False):\n    \"\"\" Make an ndarray from the given array with the given shape and strides.\n    \"\"\"\n    # first convert input to array, possibly keeping subclass\n    x = np.array(x, copy=False, subok=subok)\n    interface = dict(x.__array_interface__)\n    if shape is not None:\n        interface['shape'] = tuple(shape)\n    if strides is not None:\n        interface['strides'] = tuple(strides)\n    array = np.asarray(DummyArray(interface, base=x))\n\n    if array.dtype.fields is None and x.dtype.fields is not None:\n        # This should only happen if x.dtype is [('', 'Vx')]\n        array.dtype = x.dtype\n\n    return _maybe_view_as_subclass(x, array)\n\n\ndef _broadcast_to(array, shape, subok, readonly):\n    shape = tuple(shape) if np.iterable(shape) else (shape,)\n    array = np.array(array, copy=False, subok=subok)\n    if not shape and array.shape:\n        raise ValueError('cannot broadcast a non-scalar to a scalar array')\n    if any(size < 0 for size in shape):\n        raise ValueError('all elements of broadcast shape must be non-'\n                         'negative')\n    broadcast = np.nditer(\n        (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'],\n        op_flags=['readonly'], itershape=shape, order='C').itviews[0]\n    result = _maybe_view_as_subclass(array, broadcast)\n    if not readonly and array.flags.writeable:\n        result.flags.writeable = True\n    return result\n\n\ndef broadcast_to(array, shape, subok=False):\n    \"\"\"Broadcast an array to a new shape.\n\n    Parameters\n    ----------\n    array : array_like\n        The array to broadcast.\n    shape : tuple\n        The shape of the desired array.\n    subok : bool, optional\n        If True, then sub-classes will be passed-through, otherwise\n        the returned array will be forced to be a base-class array (default).\n\n    Returns\n    -------\n    broadcast : array\n        A readonly view on the original array with the given shape. It is\n        typically not contiguous. Furthermore, more than one element of a\n        broadcasted array may refer to a single memory location.\n\n    Raises\n    ------\n    ValueError\n        If the array is not compatible with the new shape according to NumPy's\n        broadcasting rules.\n\n    Notes\n    -----\n    .. versionadded:: 1.10.0\n\n    Examples\n    --------\n    >>> x = np.array([1, 2, 3])\n    >>> np.broadcast_to(x, (3, 3))\n    array([[1, 2, 3],\n           [1, 2, 3],\n           [1, 2, 3]])\n    \"\"\"\n    return _broadcast_to(array, shape, subok=subok, readonly=True)\n\n\ndef _broadcast_shape(*args):\n    \"\"\"Returns the shape of the ararys that would result from broadcasting the\n    supplied arrays against each other.\n    \"\"\"\n    if not args:\n        raise ValueError('must provide at least one argument')\n    if len(args) == 1:\n        # a single argument does not work with np.broadcast\n        return np.asarray(args[0]).shape\n    # use the old-iterator because np.nditer does not handle size 0 arrays\n    # consistently\n    b = np.broadcast(*args[:32])\n    # unfortunately, it cannot handle 32 or more arguments directly\n    for pos in range(32, len(args), 31):\n        # ironically, np.broadcast does not properly handle np.broadcast\n        # objects (it treats them as scalars)\n        # use broadcasting to avoid allocating the full array\n        b = broadcast_to(0, b.shape)\n        b = np.broadcast(b, *args[pos:(pos + 31)])\n    return b.shape\n\n\ndef broadcast_arrays(*args, **kwargs):\n    \"\"\"\n    Broadcast any number of arrays against each other.\n\n    Parameters\n    ----------\n    `*args` : array_likes\n        The arrays to broadcast.\n\n    subok : bool, optional\n        If True, then sub-classes will be passed-through, otherwise\n        the returned arrays will be forced to be a base-class array (default).\n\n    Returns\n    -------\n    broadcasted : list of arrays\n        These arrays are views on the original arrays.  They are typically\n        not contiguous.  Furthermore, more than one element of a\n        broadcasted array may refer to a single memory location.  If you\n        need to write to the arrays, make copies first.\n\n    Examples\n    --------\n    >>> x = np.array([[1,2,3]])\n    >>> y = np.array([[1],[2],[3]])\n    >>> np.broadcast_arrays(x, y)\n    [array([[1, 2, 3],\n           [1, 2, 3],\n           [1, 2, 3]]), array([[1, 1, 1],\n           [2, 2, 2],\n           [3, 3, 3]])]\n\n    Here is a useful idiom for getting contiguous copies instead of\n    non-contiguous views.\n\n    >>> [np.array(a) for a in np.broadcast_arrays(x, y)]\n    [array([[1, 2, 3],\n           [1, 2, 3],\n           [1, 2, 3]]), array([[1, 1, 1],\n           [2, 2, 2],\n           [3, 3, 3]])]\n\n    \"\"\"\n    # nditer is not used here to avoid the limit of 32 arrays.\n    # Otherwise, something like the following one-liner would suffice:\n    # return np.nditer(args, flags=['multi_index', 'zerosize_ok'],\n    #                  order='C').itviews\n\n    subok = kwargs.pop('subok', False)\n    if kwargs:\n        raise TypeError('broadcast_arrays() got an unexpected keyword '\n                        'argument {}'.format(kwargs.pop()))\n    args = [np.array(_m, copy=False, subok=subok) for _m in args]\n\n    shape = _broadcast_shape(*args)\n\n    if all(array.shape == shape for array in args):\n        # Common case where nothing needs to be broadcasted.\n        return args\n\n    # TODO: consider making the results of broadcast_arrays readonly to match\n    # broadcast_to. This will require a deprecation cycle.\n    return [_broadcast_to(array, shape, subok=subok, readonly=False)\n            for array in args]\n", "path": "numpy/lib/stride_tricks.py"}]}