We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error type mismatch when broadcast fails
When broadcast fails, numpy causes `ValueError`, but cupy causes `RuntimeError`.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cupy/manipulation/dims.py`
Content:
```
1 import six
2 
3 import cupy
4 from cupy import internal
5 
6 
7 zip_longest = six.moves.zip_longest
8 six_zip = six.moves.zip
9 
10 
11 def atleast_1d(*arys):
12     """Converts arrays to arrays with dimensions >= 1.
13 
14     Args:
15         arys (tuple of arrays): Arrays to be converted. All arguments must be
16             cupy.ndarray objects. Only zero-dimensional array is affected.
17 
18     Returns:
19         If there are only one input, then it returns its converted version.
20         Otherwise, it returns a list of converted arrays.
21 
22     .. seealso:: :func:`numpy.atleast_1d`
23 
24     """
25     res = []
26     for a in arys:
27         if not isinstance(a, cupy.ndarray):
28             raise TypeError('Only cupy arrays can be atleast_1d')
29         if a.ndim == 0:
30             a = a.reshape(1)
31         res.append(a)
32     if len(res) == 1:
33         res = res[0]
34     return res
35 
36 
37 def atleast_2d(*arys):
38     """Converts arrays to arrays with dimensions >= 2.
39 
40     If an input array has dimensions less than two, then this function inserts
41     new axes at the head of dimensions to make it have two dimensions.
42 
43     Args:
44         arys (tuple of arrays): Arrays to be converted. All arguments must be
45             cupy.ndarray objects.
46 
47     Returns:
48         If there are only one input, then it returns its converted version.
49         Otherwise, it returns a list of converted arrays.
50 
51     .. seealso:: :func:`numpy.atleast_2d`
52 
53     """
54     res = []
55     for a in arys:
56         if not isinstance(a, cupy.ndarray):
57             raise TypeError('Only cupy arrays can be atleast_2d')
58         if a.ndim == 0:
59             a = a.reshape(1, 1)
60         elif a.ndim == 1:
61             a = a[cupy.newaxis, :]
62         res.append(a)
63     if len(res) == 1:
64         res = res[0]
65     return res
66 
67 
68 def atleast_3d(*arys):
69     """Converts arrays to arrays with dimensions >= 3.
70 
71     If an input array has dimensions less than three, then this function
72     inserts new axes to make it have three dimensions. The place of the new
73     axes are following:
74 
75     - If its shape is ``()``, then the shape of output is ``(1, 1, 1)``.
76     - If its shape is ``(N,)``, then the shape of output is ``(1, N, 1)``.
77     - If its shape is ``(M, N)``, then the shape of output is ``(M, N, 1)``.
78     - Otherwise, the output is the input array itself.
79 
80     Args:
81         arys (tuple of arrays): Arrays to be converted. All arguments must be
82             cupy.ndarray objects.
83 
84     Returns:
85         If there are only one input, then it returns its converted version.
86         Otherwise, it returns a list of converted arrays.
87 
88     .. seealso:: :func:`numpy.atleast_3d`
89 
90     """
91     res = []
92     for a in arys:
93         if not isinstance(a, cupy.ndarray):
94             raise TypeError('Only cupy arrays can be atleast_3d')
95         if a.ndim == 0:
96             a = a.reshape(1, 1, 1)
97         elif a.ndim == 1:
98             a = a[cupy.newaxis, :, cupy.newaxis]
99         elif a.ndim == 2:
100             a = a[:, :, cupy.newaxis]
101         res.append(a)
102     if len(res) == 1:
103         res = res[0]
104     return res
105 
106 
107 class broadcast(object):
108     """Object that performs broadcasting.
109 
110     CuPy actually uses this class to support broadcasting in various
111     operations. Note that this class does not provide an iterator.
112 
113     Args:
114         arrays (tuple of arrays): Arrays to be broadcasted.
115 
116     Attributes:
117         shape (tuple of ints): The broadcasted shape.
118         nd (int): Number of dimensions of the broadcasted shape.
119         size (int): Total size of the broadcasted shape.
120         values (list of arrays): The broadcasted arrays.
121 
122     .. seealso:: :class:`numpy.broadcast`
123 
124     """
125 
126     def __init__(self, *arrays):
127         ndarray = cupy.ndarray
128         rev = slice(None, None, -1)
129         shape_arr = [a._shape[rev] for a in arrays
130                      if isinstance(a, ndarray)]
131         r_shape = [max(ss) for ss in zip_longest(*shape_arr, fillvalue=0)]
132 
133         self.shape = shape = tuple(r_shape[rev])
134         self.size = size = internal.prod(shape)
135         self.nd = ndim = len(shape)
136 
137         broadcasted = list(arrays)
138         for i, a in enumerate(broadcasted):
139             if not isinstance(a, ndarray):
140                 continue
141 
142             a_shape = a.shape
143             if a_shape == shape:
144                 continue
145 
146             r_strides = [
147                 a_st if sh == a_sh else (0 if a_sh == 1 else None)
148                 for sh, a_sh, a_st
149                 in six_zip(r_shape, a._shape[rev], a._strides[rev])]
150 
151             if None in r_strides:
152                 raise RuntimeError('Broadcasting failed')
153 
154             offset = (0,) * (ndim - len(r_strides))
155 
156             broadcasted[i] = view = a.view()
157             view._shape = shape
158             view._strides = offset + tuple(r_strides[rev])
159             view._size = size
160             view._c_contiguous = -1
161             view._f_contiguous = -1
162 
163         self.values = tuple(broadcasted)
164 
165 
166 def broadcast_arrays(*args):
167     """Broadcasts given arrays.
168 
169     Args:
170         args (tuple of arrays): Arrays to broadcast for each other.
171 
172     Returns:
173         list: A list of broadcasted arrays.
174 
175     .. seealso:: :func:`numpy.broadcast_arrays`
176 
177     """
178     return broadcast(*args).values
179 
180 
181 def expand_dims(a, axis):
182     """Expands given arrays.
183 
184     Args:
185         a (cupy.ndarray): Array to be expanded.
186         axis (int): Position where new axis is to be inserted.
187 
188     Returns:
189         cupy.ndarray: The number of dimensions is one greater than that of
190             the input array.
191 
192     .. seealso:: :func:`numpy.expand_dims`
193 
194     """
195     shape = a.shape
196     if axis < 0:
197         axis = axis + len(shape) + 1
198     return a.reshape(shape[:axis] + (1,) + shape[axis:])
199 
200 
201 def squeeze(a, axis=None):
202     """Removes size-one axes from the shape of an array.
203 
204     Args:
205         a (cupy.ndarray): Array to be reshaped.
206         axis (int or tuple of ints): Axes to be removed. This function removes
207             all size-one axes by default. If one of the specified axes is not
208             of size one, an exception is raised.
209 
210     Returns:
211         cupy.ndarray: An array without (specified) size-one axes.
212 
213     .. seealso:: :func:`numpy.squeeze`
214 
215     """
216     if axis is None:
217         axis = tuple(i for i, n in enumerate(a._shape) if n == 1)
218     elif isinstance(axis, int):
219         axis = axis,
220 
221     new_shape = []
222     new_strides = []
223     j = 0
224     for i, n in enumerate(a._shape):
225         if j < len(axis) and i == axis[j]:
226             if n != 1:
227                 raise RuntimeError('Cannot squeeze dimension of size > 1')
228             j += 1
229         else:
230             new_shape.append(n)
231             new_strides.append(a._strides[i])
232 
233     v = a.view()
234     v._shape = tuple(new_shape)
235     v._strides = tuple(new_strides)
236     v._c_contiguous = -1
237     v._f_contiguous = -1
238     return v
239
```
--- 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/cupy/manipulation/dims.py b/cupy/manipulation/dims.py
--- a/cupy/manipulation/dims.py
+++ b/cupy/manipulation/dims.py
@@ -149,7 +149,7 @@
                 in six_zip(r_shape, a._shape[rev], a._strides[rev])]
 
             if None in r_strides:
-                raise RuntimeError('Broadcasting failed')
+                raise ValueError('Broadcasting failed')
 
             offset = (0,) * (ndim - len(r_strides))

{"golden_diff": "diff --git a/cupy/manipulation/dims.py b/cupy/manipulation/dims.py\n--- a/cupy/manipulation/dims.py\n+++ b/cupy/manipulation/dims.py\n@@ -149,7 +149,7 @@\n                 in six_zip(r_shape, a._shape[rev], a._strides[rev])]\n \n             if None in r_strides:\n-                raise RuntimeError('Broadcasting failed')\n+                raise ValueError('Broadcasting failed')\n \n             offset = (0,) * (ndim - len(r_strides))\n", "issue": "Error type mismatch when broadcast fails\nWhen broadcast fails, numpy causes `ValueError`, but cupy causes `RuntimeError`.\n\n", "before_files": [{"content": "import six\n\nimport cupy\nfrom cupy import internal\n\n\nzip_longest = six.moves.zip_longest\nsix_zip = six.moves.zip\n\n\ndef atleast_1d(*arys):\n    \"\"\"Converts arrays to arrays with dimensions >= 1.\n\n    Args:\n        arys (tuple of arrays): Arrays to be converted. All arguments must be\n            cupy.ndarray objects. Only zero-dimensional array is affected.\n\n    Returns:\n        If there are only one input, then it returns its converted version.\n        Otherwise, it returns a list of converted arrays.\n\n    .. seealso:: :func:`numpy.atleast_1d`\n\n    \"\"\"\n    res = []\n    for a in arys:\n        if not isinstance(a, cupy.ndarray):\n            raise TypeError('Only cupy arrays can be atleast_1d')\n        if a.ndim == 0:\n            a = a.reshape(1)\n        res.append(a)\n    if len(res) == 1:\n        res = res[0]\n    return res\n\n\ndef atleast_2d(*arys):\n    \"\"\"Converts arrays to arrays with dimensions >= 2.\n\n    If an input array has dimensions less than two, then this function inserts\n    new axes at the head of dimensions to make it have two dimensions.\n\n    Args:\n        arys (tuple of arrays): Arrays to be converted. All arguments must be\n            cupy.ndarray objects.\n\n    Returns:\n        If there are only one input, then it returns its converted version.\n        Otherwise, it returns a list of converted arrays.\n\n    .. seealso:: :func:`numpy.atleast_2d`\n\n    \"\"\"\n    res = []\n    for a in arys:\n        if not isinstance(a, cupy.ndarray):\n            raise TypeError('Only cupy arrays can be atleast_2d')\n        if a.ndim == 0:\n            a = a.reshape(1, 1)\n        elif a.ndim == 1:\n            a = a[cupy.newaxis, :]\n        res.append(a)\n    if len(res) == 1:\n        res = res[0]\n    return res\n\n\ndef atleast_3d(*arys):\n    \"\"\"Converts arrays to arrays with dimensions >= 3.\n\n    If an input array has dimensions less than three, then this function\n    inserts new axes to make it have three dimensions. The place of the new\n    axes are following:\n\n    - If its shape is ``()``, then the shape of output is ``(1, 1, 1)``.\n    - If its shape is ``(N,)``, then the shape of output is ``(1, N, 1)``.\n    - If its shape is ``(M, N)``, then the shape of output is ``(M, N, 1)``.\n    - Otherwise, the output is the input array itself.\n\n    Args:\n        arys (tuple of arrays): Arrays to be converted. All arguments must be\n            cupy.ndarray objects.\n\n    Returns:\n        If there are only one input, then it returns its converted version.\n        Otherwise, it returns a list of converted arrays.\n\n    .. seealso:: :func:`numpy.atleast_3d`\n\n    \"\"\"\n    res = []\n    for a in arys:\n        if not isinstance(a, cupy.ndarray):\n            raise TypeError('Only cupy arrays can be atleast_3d')\n        if a.ndim == 0:\n            a = a.reshape(1, 1, 1)\n        elif a.ndim == 1:\n            a = a[cupy.newaxis, :, cupy.newaxis]\n        elif a.ndim == 2:\n            a = a[:, :, cupy.newaxis]\n        res.append(a)\n    if len(res) == 1:\n        res = res[0]\n    return res\n\n\nclass broadcast(object):\n    \"\"\"Object that performs broadcasting.\n\n    CuPy actually uses this class to support broadcasting in various\n    operations. Note that this class does not provide an iterator.\n\n    Args:\n        arrays (tuple of arrays): Arrays to be broadcasted.\n\n    Attributes:\n        shape (tuple of ints): The broadcasted shape.\n        nd (int): Number of dimensions of the broadcasted shape.\n        size (int): Total size of the broadcasted shape.\n        values (list of arrays): The broadcasted arrays.\n\n    .. seealso:: :class:`numpy.broadcast`\n\n    \"\"\"\n\n    def __init__(self, *arrays):\n        ndarray = cupy.ndarray\n        rev = slice(None, None, -1)\n        shape_arr = [a._shape[rev] for a in arrays\n                     if isinstance(a, ndarray)]\n        r_shape = [max(ss) for ss in zip_longest(*shape_arr, fillvalue=0)]\n\n        self.shape = shape = tuple(r_shape[rev])\n        self.size = size = internal.prod(shape)\n        self.nd = ndim = len(shape)\n\n        broadcasted = list(arrays)\n        for i, a in enumerate(broadcasted):\n            if not isinstance(a, ndarray):\n                continue\n\n            a_shape = a.shape\n            if a_shape == shape:\n                continue\n\n            r_strides = [\n                a_st if sh == a_sh else (0 if a_sh == 1 else None)\n                for sh, a_sh, a_st\n                in six_zip(r_shape, a._shape[rev], a._strides[rev])]\n\n            if None in r_strides:\n                raise RuntimeError('Broadcasting failed')\n\n            offset = (0,) * (ndim - len(r_strides))\n\n            broadcasted[i] = view = a.view()\n            view._shape = shape\n            view._strides = offset + tuple(r_strides[rev])\n            view._size = size\n            view._c_contiguous = -1\n            view._f_contiguous = -1\n\n        self.values = tuple(broadcasted)\n\n\ndef broadcast_arrays(*args):\n    \"\"\"Broadcasts given arrays.\n\n    Args:\n        args (tuple of arrays): Arrays to broadcast for each other.\n\n    Returns:\n        list: A list of broadcasted arrays.\n\n    .. seealso:: :func:`numpy.broadcast_arrays`\n\n    \"\"\"\n    return broadcast(*args).values\n\n\ndef expand_dims(a, axis):\n    \"\"\"Expands given arrays.\n\n    Args:\n        a (cupy.ndarray): Array to be expanded.\n        axis (int): Position where new axis is to be inserted.\n\n    Returns:\n        cupy.ndarray: The number of dimensions is one greater than that of\n            the input array.\n\n    .. seealso:: :func:`numpy.expand_dims`\n\n    \"\"\"\n    shape = a.shape\n    if axis < 0:\n        axis = axis + len(shape) + 1\n    return a.reshape(shape[:axis] + (1,) + shape[axis:])\n\n\ndef squeeze(a, axis=None):\n    \"\"\"Removes size-one axes from the shape of an array.\n\n    Args:\n        a (cupy.ndarray): Array to be reshaped.\n        axis (int or tuple of ints): Axes to be removed. This function removes\n            all size-one axes by default. If one of the specified axes is not\n            of size one, an exception is raised.\n\n    Returns:\n        cupy.ndarray: An array without (specified) size-one axes.\n\n    .. seealso:: :func:`numpy.squeeze`\n\n    \"\"\"\n    if axis is None:\n        axis = tuple(i for i, n in enumerate(a._shape) if n == 1)\n    elif isinstance(axis, int):\n        axis = axis,\n\n    new_shape = []\n    new_strides = []\n    j = 0\n    for i, n in enumerate(a._shape):\n        if j < len(axis) and i == axis[j]:\n            if n != 1:\n                raise RuntimeError('Cannot squeeze dimension of size > 1')\n            j += 1\n        else:\n            new_shape.append(n)\n            new_strides.append(a._strides[i])\n\n    v = a.view()\n    v._shape = tuple(new_shape)\n    v._strides = tuple(new_strides)\n    v._c_contiguous = -1\n    v._f_contiguous = -1\n    return v\n", "path": "cupy/manipulation/dims.py"}], "after_files": [{"content": "import six\n\nimport cupy\nfrom cupy import internal\n\n\nzip_longest = six.moves.zip_longest\nsix_zip = six.moves.zip\n\n\ndef atleast_1d(*arys):\n    \"\"\"Converts arrays to arrays with dimensions >= 1.\n\n    Args:\n        arys (tuple of arrays): Arrays to be converted. All arguments must be\n            cupy.ndarray objects. Only zero-dimensional array is affected.\n\n    Returns:\n        If there are only one input, then it returns its converted version.\n        Otherwise, it returns a list of converted arrays.\n\n    .. seealso:: :func:`numpy.atleast_1d`\n\n    \"\"\"\n    res = []\n    for a in arys:\n        if not isinstance(a, cupy.ndarray):\n            raise TypeError('Only cupy arrays can be atleast_1d')\n        if a.ndim == 0:\n            a = a.reshape(1)\n        res.append(a)\n    if len(res) == 1:\n        res = res[0]\n    return res\n\n\ndef atleast_2d(*arys):\n    \"\"\"Converts arrays to arrays with dimensions >= 2.\n\n    If an input array has dimensions less than two, then this function inserts\n    new axes at the head of dimensions to make it have two dimensions.\n\n    Args:\n        arys (tuple of arrays): Arrays to be converted. All arguments must be\n            cupy.ndarray objects.\n\n    Returns:\n        If there are only one input, then it returns its converted version.\n        Otherwise, it returns a list of converted arrays.\n\n    .. seealso:: :func:`numpy.atleast_2d`\n\n    \"\"\"\n    res = []\n    for a in arys:\n        if not isinstance(a, cupy.ndarray):\n            raise TypeError('Only cupy arrays can be atleast_2d')\n        if a.ndim == 0:\n            a = a.reshape(1, 1)\n        elif a.ndim == 1:\n            a = a[cupy.newaxis, :]\n        res.append(a)\n    if len(res) == 1:\n        res = res[0]\n    return res\n\n\ndef atleast_3d(*arys):\n    \"\"\"Converts arrays to arrays with dimensions >= 3.\n\n    If an input array has dimensions less than three, then this function\n    inserts new axes to make it have three dimensions. The place of the new\n    axes are following:\n\n    - If its shape is ``()``, then the shape of output is ``(1, 1, 1)``.\n    - If its shape is ``(N,)``, then the shape of output is ``(1, N, 1)``.\n    - If its shape is ``(M, N)``, then the shape of output is ``(M, N, 1)``.\n    - Otherwise, the output is the input array itself.\n\n    Args:\n        arys (tuple of arrays): Arrays to be converted. All arguments must be\n            cupy.ndarray objects.\n\n    Returns:\n        If there are only one input, then it returns its converted version.\n        Otherwise, it returns a list of converted arrays.\n\n    .. seealso:: :func:`numpy.atleast_3d`\n\n    \"\"\"\n    res = []\n    for a in arys:\n        if not isinstance(a, cupy.ndarray):\n            raise TypeError('Only cupy arrays can be atleast_3d')\n        if a.ndim == 0:\n            a = a.reshape(1, 1, 1)\n        elif a.ndim == 1:\n            a = a[cupy.newaxis, :, cupy.newaxis]\n        elif a.ndim == 2:\n            a = a[:, :, cupy.newaxis]\n        res.append(a)\n    if len(res) == 1:\n        res = res[0]\n    return res\n\n\nclass broadcast(object):\n    \"\"\"Object that performs broadcasting.\n\n    CuPy actually uses this class to support broadcasting in various\n    operations. Note that this class does not provide an iterator.\n\n    Args:\n        arrays (tuple of arrays): Arrays to be broadcasted.\n\n    Attributes:\n        shape (tuple of ints): The broadcasted shape.\n        nd (int): Number of dimensions of the broadcasted shape.\n        size (int): Total size of the broadcasted shape.\n        values (list of arrays): The broadcasted arrays.\n\n    .. seealso:: :class:`numpy.broadcast`\n\n    \"\"\"\n\n    def __init__(self, *arrays):\n        ndarray = cupy.ndarray\n        rev = slice(None, None, -1)\n        shape_arr = [a._shape[rev] for a in arrays\n                     if isinstance(a, ndarray)]\n        r_shape = [max(ss) for ss in zip_longest(*shape_arr, fillvalue=0)]\n\n        self.shape = shape = tuple(r_shape[rev])\n        self.size = size = internal.prod(shape)\n        self.nd = ndim = len(shape)\n\n        broadcasted = list(arrays)\n        for i, a in enumerate(broadcasted):\n            if not isinstance(a, ndarray):\n                continue\n\n            a_shape = a.shape\n            if a_shape == shape:\n                continue\n\n            r_strides = [\n                a_st if sh == a_sh else (0 if a_sh == 1 else None)\n                for sh, a_sh, a_st\n                in six_zip(r_shape, a._shape[rev], a._strides[rev])]\n\n            if None in r_strides:\n                raise ValueError('Broadcasting failed')\n\n            offset = (0,) * (ndim - len(r_strides))\n\n            broadcasted[i] = view = a.view()\n            view._shape = shape\n            view._strides = offset + tuple(r_strides[rev])\n            view._size = size\n            view._c_contiguous = -1\n            view._f_contiguous = -1\n\n        self.values = tuple(broadcasted)\n\n\ndef broadcast_arrays(*args):\n    \"\"\"Broadcasts given arrays.\n\n    Args:\n        args (tuple of arrays): Arrays to broadcast for each other.\n\n    Returns:\n        list: A list of broadcasted arrays.\n\n    .. seealso:: :func:`numpy.broadcast_arrays`\n\n    \"\"\"\n    return broadcast(*args).values\n\n\ndef expand_dims(a, axis):\n    \"\"\"Expands given arrays.\n\n    Args:\n        a (cupy.ndarray): Array to be expanded.\n        axis (int): Position where new axis is to be inserted.\n\n    Returns:\n        cupy.ndarray: The number of dimensions is one greater than that of\n            the input array.\n\n    .. seealso:: :func:`numpy.expand_dims`\n\n    \"\"\"\n    shape = a.shape\n    if axis < 0:\n        axis = axis + len(shape) + 1\n    return a.reshape(shape[:axis] + (1,) + shape[axis:])\n\n\ndef squeeze(a, axis=None):\n    \"\"\"Removes size-one axes from the shape of an array.\n\n    Args:\n        a (cupy.ndarray): Array to be reshaped.\n        axis (int or tuple of ints): Axes to be removed. This function removes\n            all size-one axes by default. If one of the specified axes is not\n            of size one, an exception is raised.\n\n    Returns:\n        cupy.ndarray: An array without (specified) size-one axes.\n\n    .. seealso:: :func:`numpy.squeeze`\n\n    \"\"\"\n    if axis is None:\n        axis = tuple(i for i, n in enumerate(a._shape) if n == 1)\n    elif isinstance(axis, int):\n        axis = axis,\n\n    new_shape = []\n    new_strides = []\n    j = 0\n    for i, n in enumerate(a._shape):\n        if j < len(axis) and i == axis[j]:\n            if n != 1:\n                raise RuntimeError('Cannot squeeze dimension of size > 1')\n            j += 1\n        else:\n            new_shape.append(n)\n            new_strides.append(a._strides[i])\n\n    v = a.view()\n    v._shape = tuple(new_shape)\n    v._strides = tuple(new_strides)\n    v._c_contiguous = -1\n    v._f_contiguous = -1\n    return v\n", "path": "cupy/manipulation/dims.py"}]}