prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Add type check to LeakyReLU 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/leaky_relu.py`
  Content:
  ```
  1 from chainer import cuda
  2 from chainer import function
  3 
  4 
  5 def _kern():
  6     return cuda.elementwise(
  7         'float* y, const float* cond, const float* x, float slope',
  8         'y[i] = cond[i] >= 0 ? x[i] : slope * x[i]', 'lrelu')
  9 
  10 
  11 class LeakyReLU(function.Function):
  12 
  13     """Leaky rectifier unit."""
  14 
  15     def __init__(self, slope=0.2):
  16         self.slope = slope
  17 
  18     def forward_cpu(self, x):
  19         y = x[0].copy()
  20         y[x[0] < 0] *= self.slope
  21         return y,
  22 
  23     def forward_gpu(self, x):
  24         y = cuda.empty_like(x[0])
  25         _kern()(y, x[0], x[0], self.slope)
  26         return y,
  27 
  28     def backward_cpu(self, x, gy):
  29         gx = gy[0].copy()
  30         gx[x[0] < 0] *= self.slope
  31         return gx,
  32 
  33     def backward_gpu(self, x, gy):
  34         gx = cuda.empty_like(x[0])
  35         _kern()(gx, x[0], gy[0], self.slope)
  36         return gx,
  37 
  38 
  39 def leaky_relu(x, slope=0.2):
  40     """Leaky Rectified Linear Unit function.
  41 
  42     This function is expressed as :math:`f(x) = \max(x, ax)`, where :math:`a`
  43     is a configurable slope value.
  44 
  45     Args:
  46         x (~chainer.Variable): Input variable.
  47         slope (float): Slope value :math:`a`.
  48 
  49     Returns:
  50         ~chainer.Variable: Output variable.
  51 
  52     """
  53     return LeakyReLU(slope)(x)
  54
  ```
  --- 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()
  
  ```
  
golden_diff: 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 @@
       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
  
verification_info: {"golden_diff": "diff --git a/chainer/functions/leaky_relu.py b/chainer/functions/leaky_relu.py\n--- a/chainer/functions/leaky_relu.py\n+++ b/chainer/functions/leaky_relu.py\n@@ -1,5 +1,8 @@\n+import numpy\n+\n from chainer import cuda\n from chainer import function\n+from chainer.utils import type_check\n \n \n def _kern():\n@@ -15,6 +18,13 @@\n     def __init__(self, slope=0.2):\n         self.slope = slope\n \n+    def check_type_forward(self, in_types):\n+        type_check.expect(in_types.size() == 1)\n+        x_type, = in_types\n+        type_check.expect(\n+            x_type.dtype == numpy.float32,\n+        )\n+\n     def forward_cpu(self, x):\n         y = x[0].copy()\n         y[x[0] < 0] *= self.slope\n", "issue": "Add type check to LeakyReLU function\nRelated to #123 \n\n", "before_files": [{"content": "from chainer import cuda\nfrom chainer import function\n\n\ndef _kern():\n    return cuda.elementwise(\n        'float* y, const float* cond, const float* x, float slope',\n        'y[i] = cond[i] >= 0 ? x[i] : slope * x[i]', 'lrelu')\n\n\nclass LeakyReLU(function.Function):\n\n    \"\"\"Leaky rectifier unit.\"\"\"\n\n    def __init__(self, slope=0.2):\n        self.slope = slope\n\n    def forward_cpu(self, x):\n        y = x[0].copy()\n        y[x[0] < 0] *= self.slope\n        return y,\n\n    def forward_gpu(self, x):\n        y = cuda.empty_like(x[0])\n        _kern()(y, x[0], x[0], self.slope)\n        return y,\n\n    def backward_cpu(self, x, gy):\n        gx = gy[0].copy()\n        gx[x[0] < 0] *= self.slope\n        return gx,\n\n    def backward_gpu(self, x, gy):\n        gx = cuda.empty_like(x[0])\n        _kern()(gx, x[0], gy[0], self.slope)\n        return gx,\n\n\ndef leaky_relu(x, slope=0.2):\n    \"\"\"Leaky Rectified Linear Unit function.\n\n    This function is expressed as :math:`f(x) = \\max(x, ax)`, where :math:`a`\n    is a configurable slope value.\n\n    Args:\n        x (~chainer.Variable): Input variable.\n        slope (float): Slope value :math:`a`.\n\n    Returns:\n        ~chainer.Variable: Output variable.\n\n    \"\"\"\n    return LeakyReLU(slope)(x)\n", "path": "chainer/functions/leaky_relu.py"}], "after_files": [{"content": "import numpy\n\nfrom chainer import cuda\nfrom chainer import function\nfrom chainer.utils import type_check\n\n\ndef _kern():\n    return cuda.elementwise(\n        'float* y, const float* cond, const float* x, float slope',\n        'y[i] = cond[i] >= 0 ? x[i] : slope * x[i]', 'lrelu')\n\n\nclass LeakyReLU(function.Function):\n\n    \"\"\"Leaky rectifier unit.\"\"\"\n\n    def __init__(self, slope=0.2):\n        self.slope = slope\n\n    def check_type_forward(self, in_types):\n        type_check.expect(in_types.size() == 1)\n        x_type, = in_types\n        type_check.expect(\n            x_type.dtype == numpy.float32,\n        )\n\n    def forward_cpu(self, x):\n        y = x[0].copy()\n        y[x[0] < 0] *= self.slope\n        return y,\n\n    def forward_gpu(self, x):\n        y = cuda.empty_like(x[0])\n        _kern()(y, x[0], x[0], self.slope)\n        return y,\n\n    def backward_cpu(self, x, gy):\n        gx = gy[0].copy()\n        gx[x[0] < 0] *= self.slope\n        return gx,\n\n    def backward_gpu(self, x, gy):\n        gx = cuda.empty_like(x[0])\n        _kern()(gx, x[0], gy[0], self.slope)\n        return gx,\n\n\ndef leaky_relu(x, slope=0.2):\n    \"\"\"Leaky Rectified Linear Unit function.\n\n    This function is expressed as :math:`f(x) = \\max(x, ax)`, where :math:`a`\n    is a configurable slope value.\n\n    Args:\n        x (~chainer.Variable): Input variable.\n        slope (float): Slope value :math:`a`.\n\n    Returns:\n        ~chainer.Variable: Output variable.\n\n    \"\"\"\n    return LeakyReLU(slope)(x)\n", "path": "chainer/functions/leaky_relu.py"}]}