We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add type check to NonparameterizedLinear 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_linear.py`
Content:
```
1 from chainer import cuda
2 from chainer import function
3 from chainer.functions import linear as linear_module
4 
5 
6 class NonparameterizedLinear(function.Function):
7 
8     """Nonparameterized linear class.
9 
10     .. seealso:: :class:`Linear`
11 
12     """
13 
14     def forward(self, x):
15         W = x[1]
16         b = None
17         if len(x) == 3:
18             b = x[2]
19         out_size, in_size = W.shape
20         func = linear_module.Linear(
21             in_size, out_size, initialW=W, initial_bias=b)
22         self.func = func
23         if any(isinstance(i, cuda.GPUArray) for i in x):
24             func.to_gpu()
25         return func.forward(x[:1])
26 
27     def backward(self, x, gy):
28         func = self.func
29         func.zero_grads()
30         gx = func.backward(x[:1], gy)
31         if func.gb is None:
32             return (gx[0], func.gW)
33         return (gx[0], func.gW, func.gb)
34 
35 
36 def linear(x, W, b=None, stride=1, pad=0, use_cudnn=True):
37     """Nonparameterized linear function.
38 
39     Args:
40         x (~chainer.Variable): Input variable.
41         W (~chainer.Variable): Weight variable.
42         b (~chainer.Variable): Bias variable.
43 
44     Returns:
45         ~chainer.Variable: Output variable.
46 
47     .. seealso:: :class:`Linear`
48 
49     """
50 
51     return NonparameterizedLinear()(x, W, b)
52
```
--- 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_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 @@
 
     """
 
+    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

{"golden_diff": "diff --git a/chainer/functions/nonparameterized_linear.py b/chainer/functions/nonparameterized_linear.py\n--- a/chainer/functions/nonparameterized_linear.py\n+++ b/chainer/functions/nonparameterized_linear.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 linear as linear_module\n+from chainer.utils import type_check\n \n \n class NonparameterizedLinear(function.Function):\n@@ -11,6 +14,29 @@\n \n     \"\"\"\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+        x_type = in_types[0]\n+        w_type = in_types[1]\n+\n+        prod = type_check.Variable(numpy.prod, 'prod')\n+        type_check.expect(\n+            x_type.dtype == numpy.float32,\n+            w_type.dtype == numpy.float32,\n+            x_type.ndim >= 2,\n+            w_type.ndim == 2,\n+            prod(x_type.shape[1:]) == w_type.shape[1],\n+        )\n+        if in_types.size().eval() == 3:\n+            b_type = in_types[2]\n+            type_check.expect(\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 NonparameterizedLinear function\nRelated to #123\n\n", "before_files": [{"content": "from chainer import cuda\nfrom chainer import function\nfrom chainer.functions import linear as linear_module\n\n\nclass NonparameterizedLinear(function.Function):\n\n    \"\"\"Nonparameterized linear class.\n\n    .. seealso:: :class:`Linear`\n\n    \"\"\"\n\n    def forward(self, x):\n        W = x[1]\n        b = None\n        if len(x) == 3:\n            b = x[2]\n        out_size, in_size = W.shape\n        func = linear_module.Linear(\n            in_size, out_size, 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 linear(x, W, b=None, stride=1, pad=0, use_cudnn=True):\n    \"\"\"Nonparameterized linear function.\n\n    Args:\n        x (~chainer.Variable): Input variable.\n        W (~chainer.Variable): Weight variable.\n        b (~chainer.Variable): Bias variable.\n\n    Returns:\n        ~chainer.Variable: Output variable.\n\n    .. seealso:: :class:`Linear`\n\n    \"\"\"\n\n    return NonparameterizedLinear()(x, W, b)\n", "path": "chainer/functions/nonparameterized_linear.py"}], "after_files": [{"content": "import numpy\n\nfrom chainer import cuda\nfrom chainer import function\nfrom chainer.functions import linear as linear_module\nfrom chainer.utils import type_check\n\n\nclass NonparameterizedLinear(function.Function):\n\n    \"\"\"Nonparameterized linear class.\n\n    .. seealso:: :class:`Linear`\n\n    \"\"\"\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        x_type = in_types[0]\n        w_type = in_types[1]\n\n        prod = type_check.Variable(numpy.prod, 'prod')\n        type_check.expect(\n            x_type.dtype == numpy.float32,\n            w_type.dtype == numpy.float32,\n            x_type.ndim >= 2,\n            w_type.ndim == 2,\n            prod(x_type.shape[1:]) == w_type.shape[1],\n        )\n        if in_types.size().eval() == 3:\n            b_type = in_types[2]\n            type_check.expect(\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        out_size, in_size = W.shape\n        func = linear_module.Linear(\n            in_size, out_size, 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 linear(x, W, b=None, stride=1, pad=0, use_cudnn=True):\n    \"\"\"Nonparameterized linear function.\n\n    Args:\n        x (~chainer.Variable): Input variable.\n        W (~chainer.Variable): Weight variable.\n        b (~chainer.Variable): Bias variable.\n\n    Returns:\n        ~chainer.Variable: Output variable.\n\n    .. seealso:: :class:`Linear`\n\n    \"\"\"\n\n    return NonparameterizedLinear()(x, W, b)\n", "path": "chainer/functions/nonparameterized_linear.py"}]}