prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Incorrect output of `cupy.logaddexp()`
  For this case, mathematically we should get `inf`, but CuPy returns `nan`:
  ```python
  >>> np.logaddexp(np.inf, np.inf)
  inf
  >>>
  >>> cp.logaddexp(np.inf, np.inf)
  array(nan)
  
  ```
  The reason is `in0-in1` gives `nan` when both are `inf`, and it propagates all the way out:
  https://github.com/cupy/cupy/blob/4469fae998df33c72ff40ef954cb08b8f0004b18/cupy/_math/explog.py#L73
  
  
  
  </issue>
  <code>
  [start of cupy/_math/explog.py]
  1 from cupy import _core
  2 from cupy._math import ufunc
  3 
  4 
  5 exp = ufunc.create_math_ufunc(
  6     'exp', 1, 'cupy_exp',
  7     '''Elementwise exponential function.
  8 
  9     .. seealso:: :data:`numpy.exp`
  10 
  11     ''')
  12 
  13 
  14 expm1 = ufunc.create_math_ufunc(
  15     'expm1', 1, 'cupy_expm1',
  16     '''Computes ``exp(x) - 1`` elementwise.
  17 
  18     .. seealso:: :data:`numpy.expm1`
  19 
  20     ''')
  21 
  22 
  23 exp2 = _core.create_ufunc(
  24     'cupy_exp2',
  25     ('e->e', 'f->f', 'd->d', 'F->F', 'D->D'),
  26     'out0 = pow(in0_type(2), in0)',
  27     doc='''Elementwise exponentiation with base 2.
  28 
  29     .. seealso:: :data:`numpy.exp2`
  30 
  31     ''')
  32 
  33 
  34 log = ufunc.create_math_ufunc(
  35     'log', 1, 'cupy_log',
  36     '''Elementwise natural logarithm function.
  37 
  38     .. seealso:: :data:`numpy.log`
  39 
  40     ''')
  41 
  42 
  43 log10 = ufunc.create_math_ufunc(
  44     'log10', 1, 'cupy_log10',
  45     '''Elementwise common logarithm function.
  46 
  47     .. seealso:: :data:`numpy.log10`
  48 
  49     ''')
  50 
  51 
  52 log2 = ufunc.create_math_ufunc(
  53     'log2', 1, 'cupy_log2',
  54     '''Elementwise binary logarithm function.
  55 
  56     .. seealso:: :data:`numpy.log2`
  57 
  58     ''')
  59 
  60 
  61 log1p = ufunc.create_math_ufunc(
  62     'log1p', 1, 'cupy_log1p',
  63     '''Computes ``log(1 + x)`` elementwise.
  64 
  65     .. seealso:: :data:`numpy.log1p`
  66 
  67     ''')
  68 
  69 
  70 logaddexp = _core.create_ufunc(
  71     'cupy_logaddexp',
  72     ('ee->e', 'ff->f', 'dd->d'),
  73     'out0 = fmax(in0, in1) + log1p(exp(-fabs(in0 - in1)))',
  74     doc='''Computes ``log(exp(x1) + exp(x2))`` elementwise.
  75 
  76     .. seealso:: :data:`numpy.logaddexp`
  77 
  78     ''')
  79 
  80 
  81 logaddexp2 = _core.create_ufunc(
  82     'cupy_logaddexp2',
  83     ('ee->e', 'ff->f', 'dd->d'),
  84     'out0 = fmax(in0, in1) + log2(1 + exp2(-fabs(in0 - in1)))',
  85     doc='''Computes ``log2(exp2(x1) + exp2(x2))`` elementwise.
  86 
  87     .. seealso:: :data:`numpy.logaddexp2`
  88 
  89     ''')
  90
  [end of cupy/_math/explog.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/cupy/_math/explog.py b/cupy/_math/explog.py
  --- a/cupy/_math/explog.py
  +++ b/cupy/_math/explog.py
  @@ -70,7 +70,14 @@
   logaddexp = _core.create_ufunc(
       'cupy_logaddexp',
       ('ee->e', 'ff->f', 'dd->d'),
  -    'out0 = fmax(in0, in1) + log1p(exp(-fabs(in0 - in1)))',
  +    '''
  +    if (in0 == in1) {
  +        /* Handles infinities of the same sign */
  +        out0 = in0 + log(2.0);
  +    } else {
  +        out0 = fmax(in0, in1) + log1p(exp(-fabs(in0 - in1)));
  +    }
  +    ''',
       doc='''Computes ``log(exp(x1) + exp(x2))`` elementwise.
   
       .. seealso:: :data:`numpy.logaddexp`
  @@ -81,7 +88,14 @@
   logaddexp2 = _core.create_ufunc(
       'cupy_logaddexp2',
       ('ee->e', 'ff->f', 'dd->d'),
  -    'out0 = fmax(in0, in1) + log2(1 + exp2(-fabs(in0 - in1)))',
  +    '''
  +    if (in0 == in1) {
  +        /* Handles infinities of the same sign */
  +        out0 = in0 + 1.0;
  +    } else {
  +        out0 = fmax(in0, in1) + log2(1 + exp2(-fabs(in0 - in1)));
  +    }
  +    ''',
       doc='''Computes ``log2(exp2(x1) + exp2(x2))`` elementwise.
   
       .. seealso:: :data:`numpy.logaddexp2`
  
verification_info: {"golden_diff": "diff --git a/cupy/_math/explog.py b/cupy/_math/explog.py\n--- a/cupy/_math/explog.py\n+++ b/cupy/_math/explog.py\n@@ -70,7 +70,14 @@\n logaddexp = _core.create_ufunc(\n     'cupy_logaddexp',\n     ('ee->e', 'ff->f', 'dd->d'),\n-    'out0 = fmax(in0, in1) + log1p(exp(-fabs(in0 - in1)))',\n+    '''\n+    if (in0 == in1) {\n+        /* Handles infinities of the same sign */\n+        out0 = in0 + log(2.0);\n+    } else {\n+        out0 = fmax(in0, in1) + log1p(exp(-fabs(in0 - in1)));\n+    }\n+    ''',\n     doc='''Computes ``log(exp(x1) + exp(x2))`` elementwise.\n \n     .. seealso:: :data:`numpy.logaddexp`\n@@ -81,7 +88,14 @@\n logaddexp2 = _core.create_ufunc(\n     'cupy_logaddexp2',\n     ('ee->e', 'ff->f', 'dd->d'),\n-    'out0 = fmax(in0, in1) + log2(1 + exp2(-fabs(in0 - in1)))',\n+    '''\n+    if (in0 == in1) {\n+        /* Handles infinities of the same sign */\n+        out0 = in0 + 1.0;\n+    } else {\n+        out0 = fmax(in0, in1) + log2(1 + exp2(-fabs(in0 - in1)));\n+    }\n+    ''',\n     doc='''Computes ``log2(exp2(x1) + exp2(x2))`` elementwise.\n \n     .. seealso:: :data:`numpy.logaddexp2`\n", "issue": "Incorrect output of `cupy.logaddexp()`\nFor this case, mathematically we should get `inf`, but CuPy returns `nan`:\r\n```python\r\n>>> np.logaddexp(np.inf, np.inf)\r\ninf\r\n>>>\r\n>>> cp.logaddexp(np.inf, np.inf)\r\narray(nan)\r\n\r\n```\r\nThe reason is `in0-in1` gives `nan` when both are `inf`, and it propagates all the way out:\r\nhttps://github.com/cupy/cupy/blob/4469fae998df33c72ff40ef954cb08b8f0004b18/cupy/_math/explog.py#L73\r\n\r\n\n", "before_files": [{"content": "from cupy import _core\nfrom cupy._math import ufunc\n\n\nexp = ufunc.create_math_ufunc(\n    'exp', 1, 'cupy_exp',\n    '''Elementwise exponential function.\n\n    .. seealso:: :data:`numpy.exp`\n\n    ''')\n\n\nexpm1 = ufunc.create_math_ufunc(\n    'expm1', 1, 'cupy_expm1',\n    '''Computes ``exp(x) - 1`` elementwise.\n\n    .. seealso:: :data:`numpy.expm1`\n\n    ''')\n\n\nexp2 = _core.create_ufunc(\n    'cupy_exp2',\n    ('e->e', 'f->f', 'd->d', 'F->F', 'D->D'),\n    'out0 = pow(in0_type(2), in0)',\n    doc='''Elementwise exponentiation with base 2.\n\n    .. seealso:: :data:`numpy.exp2`\n\n    ''')\n\n\nlog = ufunc.create_math_ufunc(\n    'log', 1, 'cupy_log',\n    '''Elementwise natural logarithm function.\n\n    .. seealso:: :data:`numpy.log`\n\n    ''')\n\n\nlog10 = ufunc.create_math_ufunc(\n    'log10', 1, 'cupy_log10',\n    '''Elementwise common logarithm function.\n\n    .. seealso:: :data:`numpy.log10`\n\n    ''')\n\n\nlog2 = ufunc.create_math_ufunc(\n    'log2', 1, 'cupy_log2',\n    '''Elementwise binary logarithm function.\n\n    .. seealso:: :data:`numpy.log2`\n\n    ''')\n\n\nlog1p = ufunc.create_math_ufunc(\n    'log1p', 1, 'cupy_log1p',\n    '''Computes ``log(1 + x)`` elementwise.\n\n    .. seealso:: :data:`numpy.log1p`\n\n    ''')\n\n\nlogaddexp = _core.create_ufunc(\n    'cupy_logaddexp',\n    ('ee->e', 'ff->f', 'dd->d'),\n    'out0 = fmax(in0, in1) + log1p(exp(-fabs(in0 - in1)))',\n    doc='''Computes ``log(exp(x1) + exp(x2))`` elementwise.\n\n    .. seealso:: :data:`numpy.logaddexp`\n\n    ''')\n\n\nlogaddexp2 = _core.create_ufunc(\n    'cupy_logaddexp2',\n    ('ee->e', 'ff->f', 'dd->d'),\n    'out0 = fmax(in0, in1) + log2(1 + exp2(-fabs(in0 - in1)))',\n    doc='''Computes ``log2(exp2(x1) + exp2(x2))`` elementwise.\n\n    .. seealso:: :data:`numpy.logaddexp2`\n\n    ''')\n", "path": "cupy/_math/explog.py"}]}