internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: chainer/chainer

Issue:
Device selection and NumPy scalars
`chainer.cuda.get_device` ignores numpy arrays on the device selection, while treats an integer as a device ordinal. It makes a confusing behavior when some arguments are (unexpectedly) numpy scalars.

``` python
cupy.cuda.Device(0).use()
a = cupy.array([1])
b = numpy.array([1])

chainer.cuda.get_device(a)  # => <CUDA Device 0>
chainer.cuda.get_device(a[0])  # => <CUDA Device 0>

chainer.cuda.get_device(b)  # => <chainer.cuda.DummyDeviceType object at ...>
chainer.cuda.get_device(b[0])  # => <CUDA Device 1>
```

I think it should be fixed, since this behavior makes it hard to implement an automatic device selection for arbitrarily indexed arrays. Note that [the document of get_device](http://docs.chainer.org/en/stable/reference/util.html#chainer.cuda.get_device) says nothing about the case in which an argument is not numpy.ndarray but is _a numpy object_.



Discussion:

Resolving patch:
diff --git a/chainer/cuda.py b/chainer/cuda.py
--- a/chainer/cuda.py
+++ b/chainer/cuda.py
@@ -27,6 +27,8 @@
 import warnings
 
 import numpy
+import six
+
 
 available = False
 cudnn_enabled = False
@@ -157,14 +159,15 @@ def get_device(*args):
     for arg in args:
         if arg is None:
             continue
+        if type(arg) in six.integer_types:
+            check_cuda_available()
+            return Device(arg)
         if not isinstance(arg, numpy.ndarray):
             check_cuda_available()
             if isinstance(arg, cupy.ndarray):
                 if arg.device is None:
                     continue
                 return arg.device
-            else:
-                return Device(arg)
 
     return DummyDevice
 


Test patch:
diff --git a/tests/chainer_tests/test_cuda.py b/tests/chainer_tests/test_cuda.py
--- a/tests/chainer_tests/test_cuda.py
+++ b/tests/chainer_tests/test_cuda.py
@@ -23,14 +23,21 @@ def test_ne(self):
 class TestCuda(unittest.TestCase):
 
     def test_get_dummy_device(self):
-        if not cuda.available:
-            self.assertIs(cuda.get_device(), cuda.DummyDevice)
+        self.assertIs(cuda.get_device(), cuda.DummyDevice)
+
+    @attr.gpu
+    def test_get_device_for_numpy_int(self):
+        self.assertIs(cuda.get_device(numpy.int64(0)), cuda.DummyDevice)
 
     @attr.gpu
     def test_get_dummy_device_for_empty_array(self):
         x = cuda.cupy.array([]).reshape((0, 10))
         self.assertIs(cuda.get_device(x), cuda.DummyDevice)
 
+    @attr.gpu
+    def test_get_device_for_int(self):
+        self.assertEqual(cuda.get_device(0), cuda.Device(0))
+
     def test_to_gpu_unavailable(self):
         x = numpy.array([1])
         if not cuda.available:
Repository: chainer/chainer

Issue:
Error on Sum.backward with zero-dimensional input
F.sum raises an error on backward when the input is zero-dimensional, since the code does not consider this case.

Code:

``` python
import numpy
import chainer
import chainer.functions as F

x = chainer.Variable(numpy.array(0, dtype='f'))
y = F.sum(x)
y.backward()
# => IndexError: too many indices for array
#    (at chainer/functions/math/sum.py:50)
```



Discussion:

Resolving patch:
diff --git a/chainer/functions/math/sum.py b/chainer/functions/math/sum.py
--- a/chainer/functions/math/sum.py
+++ b/chainer/functions/math/sum.py
@@ -46,7 +46,9 @@ def backward(self, x, gy):
         xp = cuda.get_array_module(*x)
 
         gx = xp.empty_like(x[0])
-        if self.axis is None:
+        if gx.ndim == 0:
+            gx = gy[0]
+        elif self.axis is None:
             gx[:] = gy[0]
         else:
             gy = gy[0]


Test patch:
diff --git a/tests/chainer_tests/functions_tests/math_tests/test_sum.py b/tests/chainer_tests/functions_tests/math_tests/test_sum.py
--- a/tests/chainer_tests/functions_tests/math_tests/test_sum.py
+++ b/tests/chainer_tests/functions_tests/math_tests/test_sum.py
@@ -97,6 +97,12 @@ def check_backward(self, x_data, y_grad, axis=None):
     def test_backward_cpu(self):
         self.check_backward(self.x, self.gy)
 
+    @condition.retry(3)
+    def test_backward_zerodim_cpu(self):
+        x = numpy.random.uniform(-1, 1, ()).astype(numpy.float32)
+        gy = numpy.random.uniform(-1, 1, ()).astype(numpy.float32)
+        self.check_backward(x, gy)
+
     @condition.retry(3)
     def test_backward_axis_cpu(self):
         for i in range(self.x.ndim):
@@ -133,6 +139,13 @@ def test_backward_negative_multi_axis_invert_cpu(self):
     def test_backward_gpu(self):
         self.check_backward(cuda.to_gpu(self.x), cuda.to_gpu(self.gy))
 
+    @attr.gpu
+    @condition.retry(3)
+    def test_backward_zerodim_gpu(self):
+        x = numpy.random.uniform(-1, 1, ()).astype(numpy.float32)
+        gy = numpy.random.uniform(-1, 1, ()).astype(numpy.float32)
+        self.check_backward(cuda.to_gpu(x), cuda.to_gpu(gy))
+
     @attr.gpu
     @condition.retry(3)
     def test_backward_axis_gpu(self):
Repository: chainer/chainer

Issue:
`split_axis` doesn't support empty sections
This code causes a TypeError.
`functions.split_axis(x, [], 0)`



Discussion:

Resolving patch:
diff --git a/chainer/functions/array/split_axis.py b/chainer/functions/array/split_axis.py
--- a/chainer/functions/array/split_axis.py
+++ b/chainer/functions/array/split_axis.py
@@ -23,9 +23,10 @@ def check_type_forward(self, in_types):
         type_check.expect(in_types[0].ndim > self.axis)
 
         if isinstance(self.indices_or_sections, collections.Iterable):
-            max_index = type_check.Variable(
-                self.indices_or_sections[-1], 'max_index')
-            type_check.expect(in_types[0].shape[self.axis] > max_index)
+            if len(self.indices_or_sections) > 0:
+                max_index = type_check.Variable(
+                    self.indices_or_sections[-1], 'max_index')
+                type_check.expect(in_types[0].shape[self.axis] > max_index)
         else:
             sections = type_check.Variable(
                 self.indices_or_sections, 'sections')


Test patch:
diff --git a/tests/chainer_tests/functions_tests/array_tests/test_split_axis.py b/tests/chainer_tests/functions_tests/array_tests/test_split_axis.py
--- a/tests/chainer_tests/functions_tests/array_tests/test_split_axis.py
+++ b/tests/chainer_tests/functions_tests/array_tests/test_split_axis.py
@@ -25,6 +25,8 @@
                     [slice(None), slice(4, None)]]},
         {'shape': (2,), 'axis': 0, 'ys_section': [1],
          'slices': [slice(None, 1), slice(1, None)]},
+        {'shape': (2,), 'axis': 0, 'ys_section': [],
+         'slices': [slice(None, None)]},
         {'shape': (2, 7, 3), 'axis': 1, 'ys_section': [2, 5],
          'slices': [[slice(None), slice(None, 2)], [slice(None), slice(2, 5)],
                     [slice(None), slice(5, None)]]},
@@ -47,7 +49,8 @@ def setUp(self):
 
     def check_forward(self, x_data, ys_data, indices_or_sections, axis):
         x = chainer.Variable(x_data)
-        ys = functions.split_axis(x, indices_or_sections, axis)
+        ys = functions.split_axis(
+            x, indices_or_sections, axis, force_tuple=True)
         for yd, y in zip(ys_data, ys):
             self.assertEqual(y.data.dtype, self.dtype)
             self.assertIsInstance(y.data.shape, tuple)
@@ -65,7 +68,8 @@ def test_forward_gpu(self):
 
     def check_backward(self, x_data, indices_or_sections, axis):
         x = chainer.Variable(x_data)
-        ys = functions.split_axis(x, indices_or_sections, axis)
+        ys = functions.split_axis(
+            x, indices_or_sections, axis, force_tuple=True)
         for y in ys:
             y.grad = y.data
         ys[0].backward()
Repository: chainer/chainer

Issue:
Is it possible to import caffe model on Python 3?
As stated in the documentation, `chainer.functions.caffe.CaffeFunction` only supports Python 2.7. However in the "Install Chainer" section, it says

```
Caffe model support

Protocol Buffers
protobuf>=3.0.0 is required for Py3
```

Thus I am curious whether caffe model import is supported in Python 3. 

Thank you very much for your help.



Discussion:
Sorry, the document is wrong. You can use caffe model with protobuf 3 (it is now beta3) on Python3. 
https://pypi.python.org/pypi/protobuf

protobuf 2 is not supported on Python3.

Thank you so so much for your reply at this time!


Resolving patch:
diff --git a/chainer/links/caffe/caffe_function.py b/chainer/links/caffe/caffe_function.py
--- a/chainer/links/caffe/caffe_function.py
+++ b/chainer/links/caffe/caffe_function.py
@@ -60,9 +60,8 @@ class CaffeFunction(link.Chain):
 
     .. note::
 
-       This class only supports Python 2.7, since the compiled module for
-       protocol buffers only supports Python 2. The ``__init__`` function
-       raises an exception in Python 3.
+       protobuf>=3.0.0 is required if you use Python 3 because protobuf 2 is
+       not supported on Python 3.
 
     .. note::
 


Test patch:
Repository: chainer/chainer

Issue:
Possibly wrong doc or code for deconvolution cover_all
The documentation says:

```
cover_all (bool): If True, all spatial locations are convoluted into
            some output pixels. It may make the output size larger.
```

However, when I prepare a small toy example, the output is larger when `cover_all=True`. I feel like either the code or the documentation needs to be inverted.

See an [gist notebook](https://gist.github.com/LukasDrude/8a9ebbaa3a6ba4ae0e2bef611afefd5a) for the toy example or the attached screenshot. I had set the weight matrices to ones and disabled normalization for clarity.

![screen shot 2016-07-01 at 14 54 08](https://cloud.githubusercontent.com/assets/1886882/16522122/fa0d9554-3f9b-11e6-8f2c-3ea75a9b0a5b.png)



Discussion:
Thank you for pointing out the problem. I think this is documentation bug. In `Convolution2D`, It is true that `cover_all=True` option makes the output larger than `False` case. As deconvolution is the inverse operation of convolution, this option should the output smaller.


Resolving patch:
diff --git a/chainer/functions/pooling/unpooling_2d.py b/chainer/functions/pooling/unpooling_2d.py
--- a/chainer/functions/pooling/unpooling_2d.py
+++ b/chainer/functions/pooling/unpooling_2d.py
@@ -88,9 +88,12 @@ def unpooling_2d(x, ksize, stride=None, pad=0, outsize=None, cover_all=True):
             If outsize is not ``None``, the result of outsize applied to
             :func:`~chainer.utils.conv.get_conv_outsize` must be equal to
             the shape of the 2d array in the input batch ``x``.
-        cover_all (bool): If ``True``, all spatial locations are pooled
-            into some output pixels, and the output size is larger than that
-            when cover_all is ``False``.
+        cover_all (bool): If ``True``, the output size may be smaller than
+            the size if ``cover_all`` is ``False``. This flag serves to
+            align behavior to the pooling functions which can cover all
+            input locations, see :func:`~chainer.functions.max_pooling_2d`
+            and :func:`~chainer.functions.convolution_2d`.
+
 
     Returns:
         ~chainer.Variable: Output variable.


Test patch:
Repository: chainer/chainer

Issue:
GPU implementation of transpose_sequence is too slow
As @jnory mentioned in #1174, `transpose_sequence` is too slow. We need to make a single kernel to make a transposed matrix.



Discussion:

Resolving patch:
diff --git a/chainer/functions/array/transpose_sequence.py b/chainer/functions/array/transpose_sequence.py
--- a/chainer/functions/array/transpose_sequence.py
+++ b/chainer/functions/array/transpose_sequence.py
@@ -6,17 +6,55 @@
 
 
 def _transpose(xs, length):
-    xp = cuda.get_array_module(*xs)
-    lengths = numpy.zeros(length, dtype='i')
-    for i, x in enumerate(xs):
-        lengths[0:len(x)] = i + 1
-    dtype = xs[0].dtype
-    unit = xs[0].shape[1:]
-    outs = tuple([xp.empty((l,) + unit, dtype=dtype) for l in lengths])
+    if length == 0:
+        return ()
 
+    xp = cuda.get_array_module(*xs)
+    lengths = numpy.empty(length, dtype='i')
+    end = length
     for i, x in enumerate(xs):
-        for p, xi in enumerate(x):
-            outs[p][i] = xi
+        lengths[len(x):end] = i
+        end = len(x)
+    lengths[0:end] = len(xs)
+
+    if xp is numpy:
+        dtype = xs[0].dtype
+        unit = xs[0].shape[1:]
+
+        outs = tuple([xp.empty((l,) + unit, dtype=dtype) for l in lengths])
+        for i, x in enumerate(xs):
+            for p, xi in enumerate(x):
+                outs[p][i] = xi
+
+    else:
+        offsets1 = numpy.empty(len(xs) + 1, dtype='i')
+        offsets1[0] = 0
+        numpy.cumsum([len(x) for x in xs], out=offsets1[1:])
+
+        offsets2 = numpy.empty(length + 1, dtype='i')
+        offsets2[0] = 0
+        numpy.cumsum(lengths, dtype='i', out=offsets2[1:])
+
+        x = xp.concatenate(xs, axis=0)
+        o = xp.empty_like(x)
+        unit = xs[0].size // len(xs[0])
+        size = length * len(xs) * unit
+        cuda.elementwise(
+            'int32 len, int32 unit, raw int32 off1, raw int32 off2, raw T vs',
+            'raw T hs',
+            '''
+            int ind = i / unit;
+            int off = i - ind * unit;
+            int y = ind / len;
+            int x = ind - y * len;
+            if (off2[x] + y < off2[x + 1]) {
+              hs[(off2[x] + y) * unit + off] = vs[(off1[y] + x) * unit + off];
+            }
+            ''',
+            'transpose_sequence'
+        )(length, unit, cuda.to_gpu(offsets1), cuda.to_gpu(offsets2), x, o,
+          size=size)
+        outs = tuple(xp.split(o, offsets2[1:-1]))
 
     return outs
 


Test patch:
Repository: chainer/chainer

Issue:
log_name of LogReport with keys causes AttributeError
In MNIST example you change the code

https://github.com/pfnet/chainer/blob/master/examples/mnist/train_mnist.py#L84

```
    # Write a log of evaluation statistics for each epoch
    trainer.extend(extensions.LogReport())
```

to 

```
    # Write a log of evaluation statistics for each epoch
    trainer.extend(extensions.LogReport(log_name='log_{.iteration}'))
```

run train_mnist.py and you'll get `AttributeError: 'dict' object has no attribute 'iteration'`



Discussion:

Resolving patch:
diff --git a/chainer/training/extensions/log_report.py b/chainer/training/extensions/log_report.py
--- a/chainer/training/extensions/log_report.py
+++ b/chainer/training/extensions/log_report.py
@@ -43,7 +43,7 @@ class LogReport(extension.Extension):
             output to the log file.
         log_name (str): Name of the log file under the output directory. It can
             be a format string: the last result dictionary is passed for the
-            formatting. For example, users can use '{.iteration}' to separate
+            formatting. For example, users can use '{iteration}' to separate
             the log files for different iterations. If the log name is None, it
             does not output the log to any file.
 
@@ -87,7 +87,7 @@ def __call__(self, trainer):
 
             # write to the log file
             if self._log_name is not None:
-                log_name = self._log_name.format(stats_cpu)
+                log_name = self._log_name.format(**stats_cpu)
                 fd, path = tempfile.mkstemp(prefix=log_name, dir=trainer.out)
                 with os.fdopen(fd, 'w') as f:
                     json.dump(self._log, f, indent=4)


Test patch:
Repository: chainer/chainer

Issue:
Stop printing cuDNN warning more than once
Users do not need multiple cuDNN warnings. https://github.com/pfnet/chainer/blob/71eef3e90baea61d3140b75741520515f8882f9d/chainer/cuda.py#L86



Discussion:

Resolving patch:
diff --git a/chainer/cuda.py b/chainer/cuda.py
--- a/chainer/cuda.py
+++ b/chainer/cuda.py
@@ -82,11 +82,13 @@ def check_cuda_available():
                '(see https://github.com/pfnet/chainer#installation).')
         msg += str(_resolution_error)
         raise RuntimeError(msg)
-    if not cudnn_enabled:
+    if (not cudnn_enabled and
+            not getattr(check_cuda_available, '_already_warned', False)):
         warnings.warn(
             'cuDNN is not enabled.\n'
             'Please reinstall chainer after you install cudnn\n'
             '(see https://github.com/pfnet/chainer#installation).')
+        check_cuda_available._already_warned = True
 
 
 class DummyDeviceType(object):


Test patch:
Repository: chainer/chainer

Issue:
ProgressBar iters/sec is too low in CPU mode
The 'iters/sec' speed displayed in the `ProgressBar` extension seems too low when running a model in CPU mode. I suspect this is due to the use of `time.clock()` instead of `time.time()`. `time.clock()` apparently measures the total time spent in all CPU cores, which can cause the measured time to (sometimes greatly) exceed the wall clock time.



Discussion:

Resolving patch:
diff --git a/chainer/training/extensions/progress_bar.py b/chainer/training/extensions/progress_bar.py
--- a/chainer/training/extensions/progress_bar.py
+++ b/chainer/training/extensions/progress_bar.py
@@ -61,7 +61,7 @@ def __call__(self, trainer):
         if iteration % self._update_interval == 0:
             epoch = trainer.updater.epoch_detail
             recent_timing = self._recent_timing
-            now = time.clock()
+            now = time.time()
 
             if len(recent_timing) >= 1:
                 out.write('\033[J')


Test patch:
Repository: chainer/chainer

Issue:
Invalid CuPy cache problem with different version of CUDAs
When a user update CUDA, caches of CuPy for old CUDA is sometimes incompatible with new one. We need to check CUDA version and to store kernel cache with its information.

@cosmo__ reported this problem on Twitter. Thank you!



Discussion:

Resolving patch:
diff --git a/cupy/cuda/compiler.py b/cupy/cuda/compiler.py
--- a/cupy/cuda/compiler.py
+++ b/cupy/cuda/compiler.py
@@ -12,6 +12,18 @@
 from cupy.cuda import function
 
 
+_nvcc_version = None
+
+
+def _get_nvcc_version():
+    global _nvcc_version
+    if _nvcc_version is None:
+        cmd = ['nvcc', '--version']
+        _nvcc_version = _run_nvcc(cmd, '.')
+
+    return _nvcc_version
+
+
 def _get_arch():
     cc = device.Device().compute_capability
     return 'sm_%s' % cc
@@ -110,7 +122,7 @@ def compile_with_cache(source, options=(), arch=None, cache_dir=None):
         elif sys.maxsize == 2147483647:
             options += '-m32',
 
-    env = (arch, options)
+    env = (arch, options, _get_nvcc_version())
     if '#include' in source:
         pp_src = '%s %s' % (env, preprocess(source, options))
     else:


Test patch:
Repository: chainer/chainer

Issue:
Nested exception occurs on type error on using Python3
When a type error occurs in type-check, Chainer raises a nested error when a user uses Python3 and shows the message:

```
During handling of the above exception, another exception occurred:
```



Discussion:
Could you paste a more informative error message?


Resolving patch:
diff --git a/chainer/function.py b/chainer/function.py
--- a/chainer/function.py
+++ b/chainer/function.py
@@ -1,9 +1,10 @@
 import collections
 import os
-import six
 import traceback
 import weakref
 
+import six
+
 import chainer
 from chainer import cuda
 from chainer import flag
@@ -194,7 +195,8 @@ def _check_data_type_forward(self, in_data):
 Invalid operation is performed in: {0} (Forward)
 
 {1}""".format(self.label, str(e))
-            raise type_check.InvalidType(e.expect, e.actual, msg=msg)
+            six.raise_from(
+                type_check.InvalidType(e.expect, e.actual, msg=msg), None)
 
     def check_type_forward(self, in_types):
         """Checks types of input data before forward propagation.


Test patch:
Repository: chainer/chainer

Issue:
inconsistency between cupy.vstack and numpy.vstack
```
In [1]: import cupy, numpy
In [2]: a = cupy.arange(12).reshape(3, 4)
In [3]: cupy.vstack([a])
Out[3]: array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
In [4]: numpy.vstack([a.get()])
Out[4]: 
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])
```



Discussion:

Resolving patch:
diff --git a/cupy/manipulation/join.py b/cupy/manipulation/join.py
--- a/cupy/manipulation/join.py
+++ b/cupy/manipulation/join.py
@@ -143,7 +143,7 @@ def vstack(tup):
     .. seealso:: :func:`numpy.dstack`
 
     """
-    return concatenate(cupy.atleast_2d(*tup), 0)
+    return concatenate([cupy.atleast_2d(m) for m in tup], 0)
 
 
 def stack(tup, axis=0):


Test patch:
diff --git a/tests/cupy_tests/manipulation_tests/test_join.py b/tests/cupy_tests/manipulation_tests/test_join.py
--- a/tests/cupy_tests/manipulation_tests/test_join.py
+++ b/tests/cupy_tests/manipulation_tests/test_join.py
@@ -99,6 +99,11 @@ def test_vstack_vectors(self, xp):
         b = xp.arange(2, -1, -1)
         return xp.vstack((a, b))
 
+    @testing.numpy_cupy_array_equal()
+    def test_vstack_single_element(self, xp):
+        a = xp.arange(3)
+        return xp.vstack((a,))
+
     def test_vstack_wrong_ndim(self):
         a = cupy.empty((3,))
         b = cupy.empty((3, 1))
Repository: chainer/chainer

Issue:
Inconsistency between cupy.dstack and numpy.dstack
```
In [10]: import cupy, numpy
In [11]: a = cupy.arange(24).reshape(2, 3, 4)
In [12]: numpy.dstack((a.get(),))
Out[12]: 
array([[[ 0,  1,  2,  3],
        [ 4,  5,  6,  7],
        [ 8,  9, 10, 11]],

       [[12, 13, 14, 15],
        [16, 17, 18, 19],
        [20, 21, 22, 23]]])

In [13]: cupy.dstack((a,))
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-13-aa573685da21> in <module>()
----> 1 cupy.dstack((a,))

/home/delta/dev/chainer/cupy/manipulation/join.py in dstack(tup)
    101 
    102     """
--> 103     return concatenate(cupy.atleast_3d(*tup), 2)
    104 
    105 

/home/delta/dev/chainer/cupy/manipulation/join.py in concatenate(tup, axis)
     59             ndim = a.ndim
     60             shape = list(a.shape)
---> 61             axis = _get_positive_axis(a.ndim, axis)
     62             continue
     63 

/home/delta/dev/chainer/cupy/manipulation/join.py in _get_positive_axis(ndim, axis)
    167         a += ndim
    168     if a < 0 or a >= ndim:
--> 169         raise IndexError('axis {} out of bounds [0, {})'.format(axis, ndim))
    170     return a

IndexError: axis 2 out of bounds [0, 2)
```



Discussion:

Resolving patch:
diff --git a/cupy/manipulation/join.py b/cupy/manipulation/join.py
--- a/cupy/manipulation/join.py
+++ b/cupy/manipulation/join.py
@@ -100,7 +100,7 @@ def dstack(tup):
     .. seealso:: :func:`numpy.dstack`
 
     """
-    return concatenate(cupy.atleast_3d(*tup), 2)
+    return concatenate([cupy.atleast_3d(m) for m in tup], 2)
 
 
 def hstack(tup):


Test patch:
diff --git a/tests/cupy_tests/manipulation_tests/test_join.py b/tests/cupy_tests/manipulation_tests/test_join.py
--- a/tests/cupy_tests/manipulation_tests/test_join.py
+++ b/tests/cupy_tests/manipulation_tests/test_join.py
@@ -73,6 +73,21 @@ def test_dstack(self, xp):
         c = testing.shaped_arange((1, 3), xp)
         return xp.dstack((a, b, c))
 
+    @testing.numpy_cupy_array_equal()
+    def test_dstack_single_element(self, xp):
+        a = testing.shaped_arange((1, 2, 3), xp)
+        return xp.dstack((a,))
+
+    @testing.numpy_cupy_array_equal()
+    def test_dstack_single_element_2(self, xp):
+        a = testing.shaped_arange((1, 2), xp)
+        return xp.dstack((a,))
+
+    @testing.numpy_cupy_array_equal()
+    def test_dstack_single_element_3(self, xp):
+        a = testing.shaped_arange((1,), xp)
+        return xp.dstack((a,))
+
     @testing.numpy_cupy_array_equal()
     def test_hstack_vectors(self, xp):
         a = xp.arange(3)