always prefer setting shape to using np.broadcast_to
broadcast_to is only available on numpy 1.10+ and is slower
@@ -402,11 +402,9 @@ def _as_pairs(x, ndim, as_index=False):
# Converting the array with `tolist` seems to improve performance
# when iterating and indexing the result (see usage in `pad`)
- try:
- return numpy.broadcast_to(x, (ndim, 2)).tolist()
- except AttributeError:
- # NumPy < 1.10 does not have broadcast_to
- return cupy.broadcast_to(cupy.asarray(x), (ndim, 2)).tolist()
+ x_view = x.view()
+ x_view.shape = (ndim, 2)
+ return x_view.tolist()
# def _pad_dispatcher(array, pad_width, mode=None, **kwargs):
# return (array,)
