We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add type check to LocalResponseNormalization 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/local_response_normalization.py`
Content:
```
1 from chainer import cuda
2 from chainer import function
3 import six
4 
5 
6 def _cu_conv_sum(y, x, n):
7     # Convolutional sum
8     # TODO(beam2d): Use scan computation
9     rdim = x.size // (x.shape[0] * x.shape[1])
10     cuda.elementwise(
11         'float* y, const float* x, int rdim, int N, int n_',
12         '''
13           int half_n = n_ / 2;
14           int offset = i / rdim * N * rdim + i % rdim;
15           float* xi = x + offset;
16           float* yi = y + offset;
17 
18           float sum_part = 0;
19           for (int j = 0; j < N + half_n; ++j) {
20             if (j < N) {
21               sum_part += xi[j * rdim];
22             }
23             if (j >= n_) {
24               sum_part -= xi[(j - n_) * rdim];
25             }
26             if (j >= half_n) {
27               yi[(j - half_n) * rdim] = sum_part;
28             }
29           }
30         ''', 'lrn_conv_sum')(y, x, rdim, x.shape[1], n,
31                              range=slice(0, x.shape[0] * rdim, 1))
32 
33 
34 class LocalResponseNormalization(function.Function):
35 
36     """Cross-channel normalization function used in AlexNet."""
37 
38     def __init__(self, n=5, k=2, alpha=1e-4, beta=.75):
39         self.n = n
40         self.k = k
41         self.alpha = alpha
42         self.beta = beta
43 
44     def forward_cpu(self, x):
45         half_n = self.n // 2
46         x2 = x[0] * x[0]
47         sum_part = x2.copy()
48         for i in six.moves.range(1, half_n + 1):
49             sum_part[:, i:] += x2[:, :-i]
50             sum_part[:, :-i] += x2[:, i:]
51         self.unit_scale = self.k + self.alpha * sum_part
52         self.scale = self.unit_scale ** -self.beta
53         self.y = x[0] * self.scale
54         return self.y,
55 
56     def backward_cpu(self, x, gy):
57         half_n = self.n // 2
58         summand = self.y * gy[0] / self.unit_scale
59         sum_part = summand.copy()
60         for i in six.moves.range(1, half_n + 1):
61             sum_part[:, i:] += summand[:, :-i]
62             sum_part[:, :-i] += summand[:, i:]
63 
64         gx = gy[0] * self.scale - 2 * self.alpha * self.beta * x[0] * sum_part
65         return gx,
66 
67     def forward_gpu(self, x):
68         self.y = x[0] * x[0]  # temporary
69         self.scale = cuda.empty_like(self.y)
70         _cu_conv_sum(self.scale, self.y, self.n)
71         cuda.elementwise(
72             '''float* y, float* scale, const float* x,
73                float k, float alpha, float beta''',
74             '''scale[i] = k + alpha * scale[i];
75                y[i] = x[i] * powf(scale[i], -beta);''',
76             'lrn_fwd')(self.y, self.scale, x[0], self.k, self.alpha, self.beta)
77         return self.y,
78 
79     def backward_gpu(self, x, gy):
80         summand = cuda.empty_like(x[0])
81         cuda.elementwise(
82             '''float* summand, const float* scale, const float* y,
83                const float* gy''',
84             'summand[i] = y[i] * gy[i] / scale[i]',
85             'lrn_bwd_summand')(summand, self.scale, self.y, gy[0])
86         gx = cuda.empty_like(x[0])
87         _cu_conv_sum(gx, summand, self.n)
88         cuda.elementwise(
89             '''float* gx, const float* x, const float* gy, const float* scale,
90                float beta, float coeff''',
91             'gx[i] = powf(scale[i], -beta) * gy[i] - coeff * x[i] * gx[i]',
92             'lrn_bwd')(gx, x[0], gy[0], self.scale, self.beta,
93                        2 * self.alpha * self.beta)
94         return gx,
95 
96 
97 def local_response_normalization(x, n=5, k=2, alpha=1e-4, beta=.75):
98     """Local response normalization across neighboring channels.
99 
100     This function implements normalization across channels. Let :math:`x` an
101     input image with :math:`N` channels. Then, this function computes an output
102     image :math:`y` by following formula:
103 
104     .. math::
105        y_i = {x_i \\over \\left( k + \\
106               \\alpha \\sum_{j=\\max{1, i - n/2}}^{\\min{N, i + n/2}} \\
107               x_j^2 \\right)^\\beta}.
108 
109     Args:
110         x (Variable): Input variable.
111         n (int): Normalization window width.
112         k (float): Smoothing parameter.
113         alpha (float): Normalizer scaling parameter.
114         beta (float): Normalizer power parameter.
115 
116     Returns:
117         Variable: Output variable.
118 
119     See: SSec. 3.3 of `ImageNet Classification with Deep Convolutional \\
120     Neural Networks <http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf>`_
121 
122     """
123     return LocalResponseNormalization(n, k, alpha, beta)(x)
124
```
--- 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/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 @@
         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]

{"golden_diff": "diff --git a/chainer/functions/local_response_normalization.py b/chainer/functions/local_response_normalization.py\n--- a/chainer/functions/local_response_normalization.py\n+++ b/chainer/functions/local_response_normalization.py\n@@ -1,6 +1,9 @@\n+import numpy\n+import six\n+\n from chainer import cuda\n from chainer import function\n-import six\n+from chainer.utils import type_check\n \n \n def _cu_conv_sum(y, x, n):\n@@ -41,6 +44,15 @@\n         self.alpha = alpha\n         self.beta = beta\n \n+    def check_type_forward(self, in_types):\n+        type_check.expect(in_types.size() == 1)\n+        x_type, = in_types\n+\n+        type_check.expect(\n+            x_type.dtype == numpy.float32,\n+            x_type.ndim >= 2,\n+        )\n+\n     def forward_cpu(self, x):\n         half_n = self.n // 2\n         x2 = x[0] * x[0]\n", "issue": "Add type check to LocalResponseNormalization function\nRelated to #123 \n\n", "before_files": [{"content": "from chainer import cuda\nfrom chainer import function\nimport six\n\n\ndef _cu_conv_sum(y, x, n):\n    # Convolutional sum\n    # TODO(beam2d): Use scan computation\n    rdim = x.size // (x.shape[0] * x.shape[1])\n    cuda.elementwise(\n        'float* y, const float* x, int rdim, int N, int n_',\n        '''\n          int half_n = n_ / 2;\n          int offset = i / rdim * N * rdim + i % rdim;\n          float* xi = x + offset;\n          float* yi = y + offset;\n\n          float sum_part = 0;\n          for (int j = 0; j < N + half_n; ++j) {\n            if (j < N) {\n              sum_part += xi[j * rdim];\n            }\n            if (j >= n_) {\n              sum_part -= xi[(j - n_) * rdim];\n            }\n            if (j >= half_n) {\n              yi[(j - half_n) * rdim] = sum_part;\n            }\n          }\n        ''', 'lrn_conv_sum')(y, x, rdim, x.shape[1], n,\n                             range=slice(0, x.shape[0] * rdim, 1))\n\n\nclass LocalResponseNormalization(function.Function):\n\n    \"\"\"Cross-channel normalization function used in AlexNet.\"\"\"\n\n    def __init__(self, n=5, k=2, alpha=1e-4, beta=.75):\n        self.n = n\n        self.k = k\n        self.alpha = alpha\n        self.beta = beta\n\n    def forward_cpu(self, x):\n        half_n = self.n // 2\n        x2 = x[0] * x[0]\n        sum_part = x2.copy()\n        for i in six.moves.range(1, half_n + 1):\n            sum_part[:, i:] += x2[:, :-i]\n            sum_part[:, :-i] += x2[:, i:]\n        self.unit_scale = self.k + self.alpha * sum_part\n        self.scale = self.unit_scale ** -self.beta\n        self.y = x[0] * self.scale\n        return self.y,\n\n    def backward_cpu(self, x, gy):\n        half_n = self.n // 2\n        summand = self.y * gy[0] / self.unit_scale\n        sum_part = summand.copy()\n        for i in six.moves.range(1, half_n + 1):\n            sum_part[:, i:] += summand[:, :-i]\n            sum_part[:, :-i] += summand[:, i:]\n\n        gx = gy[0] * self.scale - 2 * self.alpha * self.beta * x[0] * sum_part\n        return gx,\n\n    def forward_gpu(self, x):\n        self.y = x[0] * x[0]  # temporary\n        self.scale = cuda.empty_like(self.y)\n        _cu_conv_sum(self.scale, self.y, self.n)\n        cuda.elementwise(\n            '''float* y, float* scale, const float* x,\n               float k, float alpha, float beta''',\n            '''scale[i] = k + alpha * scale[i];\n               y[i] = x[i] * powf(scale[i], -beta);''',\n            'lrn_fwd')(self.y, self.scale, x[0], self.k, self.alpha, self.beta)\n        return self.y,\n\n    def backward_gpu(self, x, gy):\n        summand = cuda.empty_like(x[0])\n        cuda.elementwise(\n            '''float* summand, const float* scale, const float* y,\n               const float* gy''',\n            'summand[i] = y[i] * gy[i] / scale[i]',\n            'lrn_bwd_summand')(summand, self.scale, self.y, gy[0])\n        gx = cuda.empty_like(x[0])\n        _cu_conv_sum(gx, summand, self.n)\n        cuda.elementwise(\n            '''float* gx, const float* x, const float* gy, const float* scale,\n               float beta, float coeff''',\n            'gx[i] = powf(scale[i], -beta) * gy[i] - coeff * x[i] * gx[i]',\n            'lrn_bwd')(gx, x[0], gy[0], self.scale, self.beta,\n                       2 * self.alpha * self.beta)\n        return gx,\n\n\ndef local_response_normalization(x, n=5, k=2, alpha=1e-4, beta=.75):\n    \"\"\"Local response normalization across neighboring channels.\n\n    This function implements normalization across channels. Let :math:`x` an\n    input image with :math:`N` channels. Then, this function computes an output\n    image :math:`y` by following formula:\n\n    .. math::\n       y_i = {x_i \\\\over \\\\left( k + \\\\\n              \\\\alpha \\\\sum_{j=\\\\max{1, i - n/2}}^{\\\\min{N, i + n/2}} \\\\\n              x_j^2 \\\\right)^\\\\beta}.\n\n    Args:\n        x (Variable): Input variable.\n        n (int): Normalization window width.\n        k (float): Smoothing parameter.\n        alpha (float): Normalizer scaling parameter.\n        beta (float): Normalizer power parameter.\n\n    Returns:\n        Variable: Output variable.\n\n    See: SSec. 3.3 of `ImageNet Classification with Deep Convolutional \\\\\n    Neural Networks <http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf>`_\n\n    \"\"\"\n    return LocalResponseNormalization(n, k, alpha, beta)(x)\n", "path": "chainer/functions/local_response_normalization.py"}], "after_files": [{"content": "import numpy\nimport six\n\nfrom chainer import cuda\nfrom chainer import function\nfrom chainer.utils import type_check\n\n\ndef _cu_conv_sum(y, x, n):\n    # Convolutional sum\n    # TODO(beam2d): Use scan computation\n    rdim = x.size // (x.shape[0] * x.shape[1])\n    cuda.elementwise(\n        'float* y, const float* x, int rdim, int N, int n_',\n        '''\n          int half_n = n_ / 2;\n          int offset = i / rdim * N * rdim + i % rdim;\n          float* xi = x + offset;\n          float* yi = y + offset;\n\n          float sum_part = 0;\n          for (int j = 0; j < N + half_n; ++j) {\n            if (j < N) {\n              sum_part += xi[j * rdim];\n            }\n            if (j >= n_) {\n              sum_part -= xi[(j - n_) * rdim];\n            }\n            if (j >= half_n) {\n              yi[(j - half_n) * rdim] = sum_part;\n            }\n          }\n        ''', 'lrn_conv_sum')(y, x, rdim, x.shape[1], n,\n                             range=slice(0, x.shape[0] * rdim, 1))\n\n\nclass LocalResponseNormalization(function.Function):\n\n    \"\"\"Cross-channel normalization function used in AlexNet.\"\"\"\n\n    def __init__(self, n=5, k=2, alpha=1e-4, beta=.75):\n        self.n = n\n        self.k = k\n        self.alpha = alpha\n        self.beta = beta\n\n    def check_type_forward(self, in_types):\n        type_check.expect(in_types.size() == 1)\n        x_type, = in_types\n\n        type_check.expect(\n            x_type.dtype == numpy.float32,\n            x_type.ndim >= 2,\n        )\n\n    def forward_cpu(self, x):\n        half_n = self.n // 2\n        x2 = x[0] * x[0]\n        sum_part = x2.copy()\n        for i in six.moves.range(1, half_n + 1):\n            sum_part[:, i:] += x2[:, :-i]\n            sum_part[:, :-i] += x2[:, i:]\n        self.unit_scale = self.k + self.alpha * sum_part\n        self.scale = self.unit_scale ** -self.beta\n        self.y = x[0] * self.scale\n        return self.y,\n\n    def backward_cpu(self, x, gy):\n        half_n = self.n // 2\n        summand = self.y * gy[0] / self.unit_scale\n        sum_part = summand.copy()\n        for i in six.moves.range(1, half_n + 1):\n            sum_part[:, i:] += summand[:, :-i]\n            sum_part[:, :-i] += summand[:, i:]\n\n        gx = gy[0] * self.scale - 2 * self.alpha * self.beta * x[0] * sum_part\n        return gx,\n\n    def forward_gpu(self, x):\n        self.y = x[0] * x[0]  # temporary\n        self.scale = cuda.empty_like(self.y)\n        _cu_conv_sum(self.scale, self.y, self.n)\n        cuda.elementwise(\n            '''float* y, float* scale, const float* x,\n               float k, float alpha, float beta''',\n            '''scale[i] = k + alpha * scale[i];\n               y[i] = x[i] * powf(scale[i], -beta);''',\n            'lrn_fwd')(self.y, self.scale, x[0], self.k, self.alpha, self.beta)\n        return self.y,\n\n    def backward_gpu(self, x, gy):\n        summand = cuda.empty_like(x[0])\n        cuda.elementwise(\n            '''float* summand, const float* scale, const float* y,\n               const float* gy''',\n            'summand[i] = y[i] * gy[i] / scale[i]',\n            'lrn_bwd_summand')(summand, self.scale, self.y, gy[0])\n        gx = cuda.empty_like(x[0])\n        _cu_conv_sum(gx, summand, self.n)\n        cuda.elementwise(\n            '''float* gx, const float* x, const float* gy, const float* scale,\n               float beta, float coeff''',\n            'gx[i] = powf(scale[i], -beta) * gy[i] - coeff * x[i] * gx[i]',\n            'lrn_bwd')(gx, x[0], gy[0], self.scale, self.beta,\n                       2 * self.alpha * self.beta)\n        return gx,\n\n\ndef local_response_normalization(x, n=5, k=2, alpha=1e-4, beta=.75):\n    \"\"\"Local response normalization across neighboring channels.\n\n    This function implements normalization across channels. Let :math:`x` an\n    input image with :math:`N` channels. Then, this function computes an output\n    image :math:`y` by following formula:\n\n    .. math::\n       y_i = {x_i \\\\over \\\\left( k + \\\\\n              \\\\alpha \\\\sum_{j=\\\\max{1, i - n/2}}^{\\\\min{N, i + n/2}} \\\\\n              x_j^2 \\\\right)^\\\\beta}.\n\n    Args:\n        x (Variable): Input variable.\n        n (int): Normalization window width.\n        k (float): Smoothing parameter.\n        alpha (float): Normalizer scaling parameter.\n        beta (float): Normalizer power parameter.\n\n    Returns:\n        Variable: Output variable.\n\n    See: SSec. 3.3 of `ImageNet Classification with Deep Convolutional \\\\\n    Neural Networks <http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf>`_\n\n    \"\"\"\n    return LocalResponseNormalization(n, k, alpha, beta)(x)\n", "path": "chainer/functions/local_response_normalization.py"}]}