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

Issue:
Show warning when old scikits.cuda is found
`scikits.cuda` is deprecated now, but users can install new package `scikit-cuda` on a machine which has old one. We don't know what happens in such case.
We strongly recommend uninstall old `scikits.cuda` and the install new one.

Note that when I installed `scikits.cuda` and `sickit-cuda`, my environment was broken.



Discussion:

Resolving patch:
diff --git a/chainer/cuda.py b/chainer/cuda.py
--- a/chainer/cuda.py
+++ b/chainer/cuda.py
@@ -34,12 +34,28 @@
 """
 import atexit
 import os
+import warnings
 
 import numpy
 import pkg_resources
 import six
 
 try:
+    try:
+        pkg_resources.require('scikits.cuda')
+    except pkg_resources.ResolutionError as e:
+        pass
+    else:
+        msg = '''
+`scikits.cuda` package is found. This is deprecated.
+Clean both the old and new `scikit-cuda` packages, and then re-install
+`chainer-cuda-deps`.
+
+$ pip uninstall scikits.cuda scikit-cuda
+$ pip install -U chainer-cuda-deps
+        '''
+        warnings.warn(msg)
+
     _requires = [
         'pycuda>=2014.1',
         'scikit-cuda>=0.5.0',


Test patch:
Repository: chainer/chainer

Issue:
Add type check to Identity Function
Related to #123



Discussion:

Resolving patch:
diff --git a/chainer/functions/identity.py b/chainer/functions/identity.py
--- a/chainer/functions/identity.py
+++ b/chainer/functions/identity.py
@@ -5,6 +5,9 @@ class Identity(function.Function):
 
     """Identity function."""
 
+    def check_type_forward(self, in_types):
+        pass
+
     def forward(self, xs):
         return xs
 


Test patch:
Repository: chainer/chainer

Issue:
Add type check to Parameter function
Related to #123 



Discussion:

Resolving patch:
diff --git a/chainer/functions/parameter.py b/chainer/functions/parameter.py
--- a/chainer/functions/parameter.py
+++ b/chainer/functions/parameter.py
@@ -1,6 +1,7 @@
 import numpy
 
 from chainer import function
+from chainer.utils import type_check
 
 
 class Parameter(function.Function):
@@ -21,6 +22,9 @@ def __init__(self, array):
         self.W = array
         self.gW = numpy.empty_like(array)
 
+    def check_type_forward(self, in_types):
+        type_check.expect(in_types.size() == 0)
+
     def forward(self, x):
         return self.W,
 


Test patch:
Repository: chainer/chainer

Issue:
Add type check to NonparameterizedLinear function
Related to #123



Discussion:

Resolving patch:
diff --git a/chainer/functions/nonparameterized_linear.py b/chainer/functions/nonparameterized_linear.py
--- a/chainer/functions/nonparameterized_linear.py
+++ b/chainer/functions/nonparameterized_linear.py
@@ -1,6 +1,9 @@
+import numpy
+
 from chainer import cuda
 from chainer import function
 from chainer.functions import linear as linear_module
+from chainer.utils import type_check
 
 
 class NonparameterizedLinear(function.Function):
@@ -11,6 +14,29 @@ class NonparameterizedLinear(function.Function):
 
     """
 
+    def check_type_forward(self, in_types):
+        type_check.expect(
+            2 <= in_types.size(),
+            in_types.size() <= 3,
+        )
+        x_type = in_types[0]
+        w_type = in_types[1]
+
+        prod = type_check.Variable(numpy.prod, 'prod')
+        type_check.expect(
+            x_type.dtype == numpy.float32,
+            w_type.dtype == numpy.float32,
+            x_type.ndim >= 2,
+            w_type.ndim == 2,
+            prod(x_type.shape[1:]) == w_type.shape[1],
+        )
+        if in_types.size().eval() == 3:
+            b_type = in_types[2]
+            type_check.expect(
+                b_type.ndim == 1,
+                b_type.shape[0] == w_type.shape[0],
+            )
+
     def forward(self, x):
         W = x[1]
         b = None


Test patch:
Repository: chainer/chainer

Issue:
Add type check to NonparameterizedConvolution2D function
Related to #123 



Discussion:

Resolving patch:
diff --git a/chainer/functions/nonparameterized_convolution_2d.py b/chainer/functions/nonparameterized_convolution_2d.py
--- a/chainer/functions/nonparameterized_convolution_2d.py
+++ b/chainer/functions/nonparameterized_convolution_2d.py
@@ -1,6 +1,9 @@
+import numpy
+
 from chainer import cuda
 from chainer import function
 from chainer.functions import convolution_2d as conv2d_module
+from chainer.utils import type_check
 
 
 class NonparameterizedConvolution2D(function.Function):
@@ -23,6 +26,30 @@ def __init__(self, stride=1, pad=0, use_cudnn=True):
 
         self.use_cudnn = use_cudnn
 
+    def check_type_forward(self, in_types):
+        type_check.expect(
+            2 <= in_types.size(),
+            in_types.size() <= 3,
+        )
+
+        x_type = in_types[0]
+        w_type = in_types[1]
+        type_check.expect(
+            x_type.dtype == numpy.float32,
+            w_type.dtype == numpy.float32,
+            x_type.ndim == 4,
+            w_type.ndim == 4,
+            x_type.shape[1] == w_type.shape[1],
+        )
+
+        if in_types.size().eval() == 3:
+            b_type = in_types[2]
+            type_check.expect(
+                b_type.dtype == numpy.float32,
+                b_type.ndim == 1,
+                b_type.shape[0] == w_type.shape[0],
+            )
+
     def forward(self, x):
         W = x[1]
         b = None


Test patch:
Repository: chainer/chainer

Issue:
Add type check to LocalResponseNormalization function
Related to #123 



Discussion:

Resolving patch:
diff --git a/chainer/functions/local_response_normalization.py b/chainer/functions/local_response_normalization.py
--- a/chainer/functions/local_response_normalization.py
+++ b/chainer/functions/local_response_normalization.py
@@ -1,6 +1,9 @@
+import numpy
+import six
+
 from chainer import cuda
 from chainer import function
-import six
+from chainer.utils import type_check
 
 
 def _cu_conv_sum(y, x, n):
@@ -41,6 +44,15 @@ def __init__(self, n=5, k=2, alpha=1e-4, beta=.75):
         self.alpha = alpha
         self.beta = beta
 
+    def check_type_forward(self, in_types):
+        type_check.expect(in_types.size() == 1)
+        x_type, = in_types
+
+        type_check.expect(
+            x_type.dtype == numpy.float32,
+            x_type.ndim >= 2,
+        )
+
     def forward_cpu(self, x):
         half_n = self.n // 2
         x2 = x[0] * x[0]


Test patch:
Repository: chainer/chainer

Issue:
Add type check to LeakyReLU function
Related to #123 



Discussion:

Resolving patch:
diff --git a/chainer/functions/leaky_relu.py b/chainer/functions/leaky_relu.py
--- a/chainer/functions/leaky_relu.py
+++ b/chainer/functions/leaky_relu.py
@@ -1,5 +1,8 @@
+import numpy
+
 from chainer import cuda
 from chainer import function
+from chainer.utils import type_check
 
 
 def _kern():
@@ -15,6 +18,13 @@ class LeakyReLU(function.Function):
     def __init__(self, slope=0.2):
         self.slope = slope
 
+    def check_type_forward(self, in_types):
+        type_check.expect(in_types.size() == 1)
+        x_type, = in_types
+        type_check.expect(
+            x_type.dtype == numpy.float32,
+        )
+
     def forward_cpu(self, x):
         y = x[0].copy()
         y[x[0] < 0] *= self.slope


Test patch:
diff --git a/tests/functions_tests/test_leaky_relu.py b/tests/functions_tests/test_leaky_relu.py
--- a/tests/functions_tests/test_leaky_relu.py
+++ b/tests/functions_tests/test_leaky_relu.py
@@ -68,4 +68,14 @@ def test_backward_gpu(self):
         self.check_backward(cuda.to_gpu(self.x), cuda.to_gpu(self.gy))
 
 
+class TestLeakyReLUZeroDim(TestLeakyReLU):
+
+    def setUp(self):
+        # Avoid unstability of numeraical grad
+        self.x = numpy.random.uniform(.5, 1, ()).astype(numpy.float32)
+        self.x *= numpy.random.randint(2, size=()) * 2 - 1
+        self.gy = numpy.random.uniform(-1, 1, ()).astype(numpy.float32)
+        self.slope = random.random()
+
+
 testing.run_module(__name__, __file__)
Repository: chainer/chainer

Issue:
`split_axis` fails when it splits the last axis of an array on py3
This code causes an error.

```
>>> x=chainer.Variable(chainer.cuda.to_gpu(numpy.array([1,2,3], numpy.float32)))
>>> chainer.functions.split_axis(x, [1], 0)
...
struct.error: required argument is not an integer
```

A return value of `numpy.prod(())` is `float`, and pycuda cannot pass a float value as an integer argument on py3 (on py2, it works).
https://github.com/pfnet/chainer/blob/master/chainer/functions/split_axis.py#L60

@ShigekiKarita reported this bug. Thanks!!
https://gist.github.com/ShigekiKarita/f27d1d149ccc3e3f381f



Discussion:

Resolving patch:
diff --git a/chainer/functions/split_axis.py b/chainer/functions/split_axis.py
--- a/chainer/functions/split_axis.py
+++ b/chainer/functions/split_axis.py
@@ -57,7 +57,7 @@ def forward_cpu(self, x):
     def forward_gpu(self, x):
         xshape = x[0].shape
         self.cdimx = xshape[self.axis]
-        self.rdim = numpy.prod(xshape[self.axis + 1:])
+        self.rdim = numpy.prod(xshape[self.axis + 1:], dtype=int)
 
         if isinstance(self.indices_or_sections, collections.Iterable):
             ind = list(self.indices_or_sections)


Test patch:
diff --git a/tests/functions_tests/test_split_axis.py b/tests/functions_tests/test_split_axis.py
--- a/tests/functions_tests/test_split_axis.py
+++ b/tests/functions_tests/test_split_axis.py
@@ -83,4 +83,13 @@ def setUp(self):
         self.axis = 1
 
 
+class TestSplitAxis4(TestSplitAxis0):
+
+    def setUp(self):
+        self.x = numpy.arange(2, dtype=numpy.float32)
+        self.ys = [self.x[:1], self.x[1:]]
+        self.ys_section = [1]
+        self.axis = 0
+
+
 testing.run_module(__name__, __file__)
Repository: chainer/chainer

Issue:
Shape of output value of `concat` is list in GPU
`cuda.empty([1])` makes a `GPUArray` with `list` shape. It causes a type invalid error.

https://github.com/pfnet/chainer/blob/master/chainer/functions/concat.py#L69



Discussion:

Resolving patch:
diff --git a/chainer/functions/concat.py b/chainer/functions/concat.py
--- a/chainer/functions/concat.py
+++ b/chainer/functions/concat.py
@@ -64,6 +64,7 @@ def forward_gpu(self, xs):
         shape = list(xs[0].shape)
         for x in xs[1:]:
             shape[self.axis] += x.shape[self.axis]
+        shape = tuple(shape)
         self.shape = shape
 
         y = cuda.empty(shape, dtype=xs[0].dtype)


Test patch:
diff --git a/tests/functions_tests/test_concat.py b/tests/functions_tests/test_concat.py
--- a/tests/functions_tests/test_concat.py
+++ b/tests/functions_tests/test_concat.py
@@ -20,6 +20,7 @@ def check_forward(self, xs_data, y_data, axis):
         xs = tuple(chainer.Variable(x_data) for x_data in xs_data)
         y = functions.concat(xs, axis=axis)
         gradient_check.assert_allclose(y_data, y.data, atol=0, rtol=0)
+        self.assertIsInstance(y.data.shape, tuple)
 
     def test_forward_cpu(self):
         self.check_forward(self.xs, self.y, axis=self.axis)
Repository: chainer/chainer

Issue:
Maybe there is a bug in chainer.optimizer.weight_decay(decay).
In the [optimizer.py](https://github.com/pfnet/chainer/blob/30807b4f9f40177f592099663b86a6bb3eb1f867/chainer/optimizer.py) file,  `weight_decay` is implemented as following:

``` python
 def weight_decay(self, decay):
     for p, g, _ in self.tuples:
         g -= decay * p
```

However, the gradient is decayed, not the weight. So if we update the weights `param -= lr * grad`, because the grad becomes smaller, the param (weight) becomes larger, which is not we want. 

As far as I know the regularized gradient decent is `p = p * (1-decay) - lr * grad`, so I think the weight should be decayed not the gradient.



Discussion:
Ah, you are right. It is a bug of Optimizer. We should **add** the scaled weights to the gradients instead of subtract them. I cannot believe that everyone except you has not noticed. Thank you for the catch!


Resolving patch:
diff --git a/chainer/optimizer.py b/chainer/optimizer.py
--- a/chainer/optimizer.py
+++ b/chainer/optimizer.py
@@ -175,10 +175,10 @@ def weight_decay(self, decay):
             if isinstance(p, cuda.GPUArray):
                 with cuda.using_device(p):
                     cuda.elementwise('float* g, const float* p, float decay',
-                                     'g[i] -= decay * p[i]',
+                                     'g[i] += decay * p[i]',
                                      'weight_decay')(g, p, decay)
             else:
-                g -= decay * p
+                g += decay * p
 
     def accumulate_grads(self, grads):
         """Accumulates gradients from other source.


Test patch:
diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py
--- a/tests/test_optimizer.py
+++ b/tests/test_optimizer.py
@@ -3,7 +3,9 @@
 import numpy as np
 
 from chainer import cuda
+from chainer import gradient_check
 from chainer import optimizer
+from chainer import optimizers
 from chainer import testing
 from chainer.testing import attr
 
@@ -39,7 +41,26 @@ def test_sqnorm_scalar_gpu(self):
 class TestOptimizer(unittest.TestCase):
 
     def setUp(self):
-        pass
+        self.w = np.arange(6, dtype=np.float32).reshape(2, 3)
+        self.g = np.arange(3, -3, -1, dtype=np.float32).reshape(2, 3)
+
+    def check_weight_decay(self, w, g):
+        decay = 0.2
+        expect = w - g - decay * w
+
+        opt = optimizers.SGD(lr=1)
+        opt.setup((w, g))
+        opt.weight_decay(decay)
+        opt.update()
+
+        gradient_check.assert_allclose(expect, w)
+
+    def test_weight_decay_cpu(self):
+        self.check_weight_decay(self.w, self.g)
+
+    @attr.gpu
+    def test_weight_decay_gpu(self):
+        self.check_weight_decay(cuda.to_gpu(self.w), cuda.to_gpu(self.g))
 
 
 testing.run_module(__name__, __file__)
Repository: chainer/chainer

Issue:
FunctionSet.copy_parameters_from()
Hi all!

The code in 'FunctionSet.copy_parameters_from()' does not work, when 'src' and 'dst' are both numpy.ndarrays?

``` python
if isinstance(dst, numpy.ndarray):
    if isinstance(src, numpy.ndarray):
        dst.copy(src)  # this gives a ValueError
```

I think this should read

``` python
if isinstance(dst, numpy.ndarray):
    if isinstance(src, numpy.ndarray):
        numpy.copyto(dst, src)
```

My numpy.version.full_version is 1.9.2, the 'copyto' method exists since 1.7.0.

Cheers,
-r



Discussion:
Thank you for reporting a bug. I'll check it and fix it.


Resolving patch:
diff --git a/chainer/function_set.py b/chainer/function_set.py
--- a/chainer/function_set.py
+++ b/chainer/function_set.py
@@ -81,7 +81,7 @@ def copy_parameters_from(self, params):
         for dst, src in zip(self.parameters, params):
             if isinstance(dst, numpy.ndarray):
                 if isinstance(src, numpy.ndarray):
-                    dst.copy(src)
+                    numpy.copyto(dst, src)
                 else:
                     src.get(dst)
             elif isinstance(src, numpy.ndarray):


Test patch:
diff --git a/tests/test_function_set.py b/tests/test_function_set.py
--- a/tests/test_function_set.py
+++ b/tests/test_function_set.py
@@ -102,5 +102,41 @@ def test_pickle_gpu(self):
         fs2.to_cpu()
         self.check_equal_fs(self.fs, fs2)
 
+    def check_copy_parameters_from(self, src_gpu=False, dst_gpu=False):
+        aW = np.random.uniform(-1, 1, (2, 3)).astype(np.float32)
+        ab = np.random.uniform(-1, 1, (2,)).astype(np.float32)
+        bW = np.random.uniform(-1, 1, (2, 3)).astype(np.float32)
+        bb = np.random.uniform(-1, 1, (2,)).astype(np.float32)
+        params = [aW.copy(), ab.copy(), bW.copy(), bb.copy()]
+
+        if dst_gpu:
+            self.fs.to_gpu()
+
+        if src_gpu:
+            params = map(cuda.to_gpu, params)
+
+        self.fs.copy_parameters_from(params)
+        self.fs.to_cpu()
+
+        self.assertTrue((self.fs.a.W == aW).all())
+        self.assertTrue((self.fs.a.b == ab).all())
+        self.assertTrue((self.fs.b.W == bW).all())
+        self.assertTrue((self.fs.b.b == bb).all())
+
+    def test_copy_parameters_from_cpu_to_cpu(self):
+        self.check_copy_parameters_from(False, False)
+
+    @attr.gpu
+    def test_copy_parameters_from_cpu_to_gpu(self):
+        self.check_copy_parameters_from(False, True)
+
+    @attr.gpu
+    def test_copy_parameters_from_gpu_to_cpu(self):
+        self.check_copy_parameters_from(True, False)
+
+    @attr.gpu
+    def test_copy_parameters_from_gpu_to_gpu(self):
+        self.check_copy_parameters_from(True, True)
+
 
 testing.run_module(__name__, __file__)
Repository: chainer/chainer

Issue:
Add type check to Inception and InceptionBN functions
Related #123 



Discussion:
`forward` of `Inception` and `InceptionBN` is a series of forward operations of existing functions. So, we need not impose additional type check as `check_type_forward`. So I think we can close this issue without any change.


Resolving patch:
diff --git a/chainer/functions/inception.py b/chainer/functions/inception.py
--- a/chainer/functions/inception.py
+++ b/chainer/functions/inception.py
@@ -63,6 +63,11 @@ def __call__(self, x):
         y = relu.relu(concat.concat((out1, out3, out5, pool), axis=1))
         return y
 
+    # forward of Inception is a series of forward operations
+    # of existing functions. So we do not need additional type checks.
+    def check_type_forward(self, in_types):
+        pass
+
     def to_gpu(self, device=None):
         return self.f.to_gpu(device)
 
diff --git a/chainer/functions/inceptionbn.py b/chainer/functions/inceptionbn.py
--- a/chainer/functions/inceptionbn.py
+++ b/chainer/functions/inceptionbn.py
@@ -99,6 +99,11 @@ def __call__(self, x):
         y = concat.concat(outs, axis=1)
         return y
 
+    # forward of InceptionBN is a series of forward operations
+    # of existing functions. So we do not need additional type checks.
+    def check_type_forward(self, in_types):
+        pass
+
     def to_gpu(self, device=None):
         super(InceptionBN, self).to_gpu(device)
         self.f.to_gpu(device)


Test patch:
Repository: chainer/chainer

Issue:
NegativeSampling and WalkerAlias do not implement to_cpu()
`NegativeSampling` implements only `to_gpu()`. Therefore, `self.sampler` does not come back to the CPU side even if `to_cpu()` is called. `WalkerAlias` also does not have `to_cpu()`.

Currently this causes a problem with [word2vec example](https://github.com/pfnet/chainer/pull/270) when loading a GPU-trained model based on negative sampling, which [has been transferred](https://github.com/pfnet/chainer/blob/0bab97c584d462e4478f360c26ce427bfe81eb0f/examples/word2vec/train_word2vec.py#L183) by `model.to_cpu()` before save by pickle.



Discussion:

Resolving patch:
diff --git a/chainer/functions/negative_sampling.py b/chainer/functions/negative_sampling.py
--- a/chainer/functions/negative_sampling.py
+++ b/chainer/functions/negative_sampling.py
@@ -104,6 +104,10 @@ def to_gpu(self, device=None):
         function.Function.to_gpu(self, device)
         self.sampler.to_gpu()
 
+    def to_cpu(self):
+        function.Function.to_cpu(self)
+        self.sampler.to_cpu()
+
     def forward_cpu(self, inputs):
         x, t = inputs
         self._make_samples(t)
diff --git a/chainer/utils/walker_alias.py b/chainer/utils/walker_alias.py
--- a/chainer/utils/walker_alias.py
+++ b/chainer/utils/walker_alias.py
@@ -54,6 +54,15 @@ def to_gpu(self):
             self.values = cuda.to_gpu(self.values)
             self.use_gpu = True
 
+    def to_cpu(self):
+        """Make a sampler CPU mode.
+
+        """
+        if self.use_gpu:
+            self.threshold = cuda.to_cpu(self.threshold)
+            self.values = cuda.to_cpu(self.values)
+            self.use_gpu = False
+
     def sample(self, shape):
         """Generates a random sample based on given probabilities.
 


Test patch:
diff --git a/tests/functions_tests/test_negative_sampling.py b/tests/functions_tests/test_negative_sampling.py
--- a/tests/functions_tests/test_negative_sampling.py
+++ b/tests/functions_tests/test_negative_sampling.py
@@ -70,5 +70,12 @@ def test_backward_gpu(self):
                             cuda.to_gpu(self.t),
                             cuda.to_gpu(self.gy))
 
+    @attr.gpu
+    def test_to_cpu(self):
+        self.func.to_gpu()
+        self.assertTrue(self.func.sampler.use_gpu)
+        self.func.to_cpu()
+        self.assertFalse(self.func.sampler.use_gpu)
+
 
 testing.run_module(__name__, __file__)
diff --git a/tests/utils_tests/test_walker_alias.py b/tests/utils_tests/test_walker_alias.py
--- a/tests/utils_tests/test_walker_alias.py
+++ b/tests/utils_tests/test_walker_alias.py
@@ -32,6 +32,14 @@ def test_sample_cpu(self):
     @attr.gpu
     def test_sample_gpu(self):
         self.sampler.to_gpu()
+        self.assertTrue(self.sampler.use_gpu)
+        self.check_sample()
+
+    @attr.gpu
+    def test_to_cpu(self):
+        self.sampler.to_gpu()
+        self.sampler.to_cpu()
+        self.assertFalse(self.sampler.use_gpu)
         self.check_sample()
Repository: chainer/chainer

Issue:
A confusing error occurs when GPU and CPU arrays are mixed on `numerical_grad`
In this case, unreadable error occurs. We nee to check if arrays are not mixed.



Discussion:

Resolving patch:
diff --git a/chainer/gradient_check.py b/chainer/gradient_check.py
--- a/chainer/gradient_check.py
+++ b/chainer/gradient_check.py
@@ -73,9 +73,18 @@ def numerical_grad(f, inputs, grad_outputs, eps=1e-3):
 
     """
     assert eps > 0
-    if any(isinstance(x, cuda.GPUArray) for x in inputs):
+    inputs = tuple(inputs)
+    grad_outputs = tuple(grad_outputs)
+    gpu = any(isinstance(x, cuda.GPUArray) for x in inputs + grad_outputs)
+
+    cpu = any(isinstance(x, numpy.ndarray) for x in inputs + grad_outputs)
+
+    if gpu and cpu:
+        raise RuntimeError('Do not mix GPU and CPU arrays in `numerical_grad`')
+    elif gpu:
         return numerical_grad_gpu(f, inputs, grad_outputs, eps)
-    return numerical_grad_cpu(f, inputs, grad_outputs, eps)
+    else:
+        return numerical_grad_cpu(f, inputs, grad_outputs, eps)
 
 
 def assert_allclose(x, y, atol=1e-5, rtol=1e-4, verbose=True):


Test patch:
diff --git a/tests/test_gradient_check.py b/tests/test_gradient_check.py
--- a/tests/test_gradient_check.py
+++ b/tests/test_gradient_check.py
@@ -177,6 +177,32 @@ def test_numerical_grad_gpu(self):
         self.check_invalid_eps(xs, gys, -1.0)
 
 
+class NumericalGradientInvalidType(unittest.TestCase):
+
+    def setUp(self):
+        self.x = numpy.array(0)
+        self.y = numpy.array(0)
+        self.f = lambda: None
+
+    @attr.gpu
+    def test_invalid_inputs(self):
+        y = cuda.to_gpu(self.y)
+        with self.assertRaises(RuntimeError):
+            gradient_check.numerical_grad(self.f, (self.x, y), ())
+
+    @attr.gpu
+    def test_invalid_outputs(self):
+        y = cuda.to_gpu(self.y)
+        with self.assertRaises(RuntimeError):
+            gradient_check.numerical_grad(self.f, (), (self.x, y))
+
+    @attr.gpu
+    def test_invalid_mixed(self):
+        y = cuda.to_gpu(self.y)
+        with self.assertRaises(RuntimeError):
+            gradient_check.numerical_grad(self.f, (self.x,), (y,))
+
+
 class AssertAllCloseTest(unittest.TestCase):
 
     def setUp(self):