We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add type check to NonparameterizedConvolution2D function
Related to #123 


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `chainer/functions/nonparameterized_convolution_2d.py`
Content:
```
1 from chainer import cuda
2 from chainer import function
3 from chainer.functions import convolution_2d as conv2d_module
4 
5 
6 class NonparameterizedConvolution2D(function.Function):
7 
8     """Two-dimensional nonparameterized convolution class.
9 
10     Args:
11         stride (int or (int, int)): Stride of filter applications.
12             ``stride=s`` and ``stride=(s, s)`` are equivalent.
13         pad (int or (int, int)): Spatial padding width for input arrays.
14             ``pad=p`` and ``pad=(p, p)`` are equivalent.
15         use_cudnn (bool): If True, then this function uses CuDNN if available.
16 
17     .. seealso:: :class:`Convolution2D`
18 
19     """
20     def __init__(self, stride=1, pad=0, use_cudnn=True):
21         self.stride = stride
22         self.pad = pad
23 
24         self.use_cudnn = use_cudnn
25 
26     def forward(self, x):
27         W = x[1]
28         b = None
29         if len(x) == 3:
30             b = x[2]
31         func = conv2d_module.Convolution2D(
32             W.shape[1], W.shape[0], W.shape[2:],
33             stride=self.stride, pad=self.pad, use_cudnn=self.use_cudnn,
34             initialW=W, initial_bias=b)
35         self.func = func
36         if any(isinstance(i, cuda.GPUArray) for i in x):
37             func.to_gpu()
38         return func.forward(x[:1])
39 
40     def backward(self, x, gy):
41         func = self.func
42         func.zero_grads()
43         gx = func.backward(x[:1], gy)
44         if func.gb is None:
45             return (gx[0], func.gW)
46         return (gx[0], func.gW, func.gb)
47 
48 
49 def convolution_2d(x, W, b=None, stride=1, pad=0, use_cudnn=True):
50     """Two-dimensional convolution function.
51 
52     Args:
53         x (~chainer.Variable): Input variable.
54         W (~chainer.Variable): Weight variable.
55         b (~chainer.Variable): Bias  variable.
56         stride (int or (int, int)): Stride of filter applications.
57             ``stride=s`` and ``stride=(s, s)`` are equivalent.
58         pad (int or (int, int)): Spatial padding width for input arrays.
59             ``pad=p`` and ``pad=(p, p)`` are equivalent.
60         use_cudnn (bool): If True, then this function uses CuDNN if available.
61 
62     Returns:
63         ~chainer.Variable: Output variable.
64 
65     .. seealso:: :class:`Convolution2D`
66 
67     """
68     return NonparameterizedConvolution2D(
69         stride=stride, pad=pad, use_cudnn=use_cudnn)(x, W, b)
70
```
--- 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/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 @@
 
         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

{"golden_diff": "diff --git a/chainer/functions/nonparameterized_convolution_2d.py b/chainer/functions/nonparameterized_convolution_2d.py\n--- a/chainer/functions/nonparameterized_convolution_2d.py\n+++ b/chainer/functions/nonparameterized_convolution_2d.py\n@@ -1,6 +1,9 @@\n+import numpy\n+\n from chainer import cuda\n from chainer import function\n from chainer.functions import convolution_2d as conv2d_module\n+from chainer.utils import type_check\n \n \n class NonparameterizedConvolution2D(function.Function):\n@@ -23,6 +26,30 @@\n \n         self.use_cudnn = use_cudnn\n \n+    def check_type_forward(self, in_types):\n+        type_check.expect(\n+            2 <= in_types.size(),\n+            in_types.size() <= 3,\n+        )\n+\n+        x_type = in_types[0]\n+        w_type = in_types[1]\n+        type_check.expect(\n+            x_type.dtype == numpy.float32,\n+            w_type.dtype == numpy.float32,\n+            x_type.ndim == 4,\n+            w_type.ndim == 4,\n+            x_type.shape[1] == w_type.shape[1],\n+        )\n+\n+        if in_types.size().eval() == 3:\n+            b_type = in_types[2]\n+            type_check.expect(\n+                b_type.dtype == numpy.float32,\n+                b_type.ndim == 1,\n+                b_type.shape[0] == w_type.shape[0],\n+            )\n+\n     def forward(self, x):\n         W = x[1]\n         b = None\n", "issue": "Add type check to NonparameterizedConvolution2D function\nRelated to #123 \n\n", "before_files": [{"content": "from chainer import cuda\nfrom chainer import function\nfrom chainer.functions import convolution_2d as conv2d_module\n\n\nclass NonparameterizedConvolution2D(function.Function):\n\n    \"\"\"Two-dimensional nonparameterized convolution class.\n\n    Args:\n        stride (int or (int, int)): Stride of filter applications.\n            ``stride=s`` and ``stride=(s, s)`` are equivalent.\n        pad (int or (int, int)): Spatial padding width for input arrays.\n            ``pad=p`` and ``pad=(p, p)`` are equivalent.\n        use_cudnn (bool): If True, then this function uses CuDNN if available.\n\n    .. seealso:: :class:`Convolution2D`\n\n    \"\"\"\n    def __init__(self, stride=1, pad=0, use_cudnn=True):\n        self.stride = stride\n        self.pad = pad\n\n        self.use_cudnn = use_cudnn\n\n    def forward(self, x):\n        W = x[1]\n        b = None\n        if len(x) == 3:\n            b = x[2]\n        func = conv2d_module.Convolution2D(\n            W.shape[1], W.shape[0], W.shape[2:],\n            stride=self.stride, pad=self.pad, use_cudnn=self.use_cudnn,\n            initialW=W, initial_bias=b)\n        self.func = func\n        if any(isinstance(i, cuda.GPUArray) for i in x):\n            func.to_gpu()\n        return func.forward(x[:1])\n\n    def backward(self, x, gy):\n        func = self.func\n        func.zero_grads()\n        gx = func.backward(x[:1], gy)\n        if func.gb is None:\n            return (gx[0], func.gW)\n        return (gx[0], func.gW, func.gb)\n\n\ndef convolution_2d(x, W, b=None, stride=1, pad=0, use_cudnn=True):\n    \"\"\"Two-dimensional convolution function.\n\n    Args:\n        x (~chainer.Variable): Input variable.\n        W (~chainer.Variable): Weight variable.\n        b (~chainer.Variable): Bias  variable.\n        stride (int or (int, int)): Stride of filter applications.\n            ``stride=s`` and ``stride=(s, s)`` are equivalent.\n        pad (int or (int, int)): Spatial padding width for input arrays.\n            ``pad=p`` and ``pad=(p, p)`` are equivalent.\n        use_cudnn (bool): If True, then this function uses CuDNN if available.\n\n    Returns:\n        ~chainer.Variable: Output variable.\n\n    .. seealso:: :class:`Convolution2D`\n\n    \"\"\"\n    return NonparameterizedConvolution2D(\n        stride=stride, pad=pad, use_cudnn=use_cudnn)(x, W, b)\n", "path": "chainer/functions/nonparameterized_convolution_2d.py"}], "after_files": [{"content": "import numpy\n\nfrom chainer import cuda\nfrom chainer import function\nfrom chainer.functions import convolution_2d as conv2d_module\nfrom chainer.utils import type_check\n\n\nclass NonparameterizedConvolution2D(function.Function):\n\n    \"\"\"Two-dimensional nonparameterized convolution class.\n\n    Args:\n        stride (int or (int, int)): Stride of filter applications.\n            ``stride=s`` and ``stride=(s, s)`` are equivalent.\n        pad (int or (int, int)): Spatial padding width for input arrays.\n            ``pad=p`` and ``pad=(p, p)`` are equivalent.\n        use_cudnn (bool): If True, then this function uses CuDNN if available.\n\n    .. seealso:: :class:`Convolution2D`\n\n    \"\"\"\n    def __init__(self, stride=1, pad=0, use_cudnn=True):\n        self.stride = stride\n        self.pad = pad\n\n        self.use_cudnn = use_cudnn\n\n    def check_type_forward(self, in_types):\n        type_check.expect(\n            2 <= in_types.size(),\n            in_types.size() <= 3,\n        )\n\n        x_type = in_types[0]\n        w_type = in_types[1]\n        type_check.expect(\n            x_type.dtype == numpy.float32,\n            w_type.dtype == numpy.float32,\n            x_type.ndim == 4,\n            w_type.ndim == 4,\n            x_type.shape[1] == w_type.shape[1],\n        )\n\n        if in_types.size().eval() == 3:\n            b_type = in_types[2]\n            type_check.expect(\n                b_type.dtype == numpy.float32,\n                b_type.ndim == 1,\n                b_type.shape[0] == w_type.shape[0],\n            )\n\n    def forward(self, x):\n        W = x[1]\n        b = None\n        if len(x) == 3:\n            b = x[2]\n        func = conv2d_module.Convolution2D(\n            W.shape[1], W.shape[0], W.shape[2:],\n            stride=self.stride, pad=self.pad, use_cudnn=self.use_cudnn,\n            initialW=W, initial_bias=b)\n        self.func = func\n        if any(isinstance(i, cuda.GPUArray) for i in x):\n            func.to_gpu()\n        return func.forward(x[:1])\n\n    def backward(self, x, gy):\n        func = self.func\n        func.zero_grads()\n        gx = func.backward(x[:1], gy)\n        if func.gb is None:\n            return (gx[0], func.gW)\n        return (gx[0], func.gW, func.gb)\n\n\ndef convolution_2d(x, W, b=None, stride=1, pad=0, use_cudnn=True):\n    \"\"\"Two-dimensional convolution function.\n\n    Args:\n        x (~chainer.Variable): Input variable.\n        W (~chainer.Variable): Weight variable.\n        b (~chainer.Variable): Bias  variable.\n        stride (int or (int, int)): Stride of filter applications.\n            ``stride=s`` and ``stride=(s, s)`` are equivalent.\n        pad (int or (int, int)): Spatial padding width for input arrays.\n            ``pad=p`` and ``pad=(p, p)`` are equivalent.\n        use_cudnn (bool): If True, then this function uses CuDNN if available.\n\n    Returns:\n        ~chainer.Variable: Output variable.\n\n    .. seealso:: :class:`Convolution2D`\n\n    \"\"\"\n    return NonparameterizedConvolution2D(\n        stride=stride, pad=pad, use_cudnn=use_cudnn)(x, W, b)\n", "path": "chainer/functions/nonparameterized_convolution_2d.py"}]}