prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Triangular Solve not working for complex case
  I have discovered, that `solve_triangular` does not work, if the input is complex, but the matrix is real:
  ```
  solve_triangular(
       cholesky,
       rhs,
       lower=True,
  )
  ```
  produces a real valued result, if `cholesky` is real but `rhs` is complex.
  
  ```
  intelpython3 -c 'import cupy; cupy.show_config()'
  OS                           : Linux-5.9.6-1-MANJARO-x86_64-with-arch-Manjaro-Linux
  CuPy Version                 : 9.0.0a1
  NumPy Version                : 1.16.2+intel.0
  SciPy Version                : 1.5.0
  Cython Build Version         : 0.29.21
  Cython Runtime Version       : 0.29.6
  CUDA Root                    : /opt/cuda
  CUDA Build Version           : 11010
  CUDA Driver Version          : 11010
  CUDA Runtime Version         : 11010
  cuBLAS Version               : 11300
  cuFFT Version                : 10300
  cuRAND Version               : 10202
  cuSOLVER Version             : (11, 0, 1)
  cuSPARSE Version             : 11300
  NVRTC Version                : (11, 1)
  Thrust Version               : 100910
  CUB Build Version            : 100910
  cuDNN Build Version          : None
  cuDNN Version                : None
  NCCL Build Version           : 2708
  NCCL Runtime Version         : 2708
  cuTENSOR Version             : None
  Device 0 Name                : GeForce RTX 3090
  Device 0 Compute Capability  : 86
  ```
  
  
  
  </issue>
  <code>
  [start of cupyx/scipy/linalg/solve_triangular.py]
  1 import numpy
  2 
  3 import cupy
  4 from cupy.cuda import cublas
  5 from cupy.cuda import device
  6 from cupy.linalg import _util
  7 
  8 
  9 def solve_triangular(a, b, trans=0, lower=False, unit_diagonal=False,
  10                      overwrite_b=False, check_finite=False):
  11     """Solve the equation a x = b for x, assuming a is a triangular matrix.
  12 
  13     Args:
  14         a (cupy.ndarray): The matrix with dimension ``(M, M)``.
  15         b (cupy.ndarray): The matrix with dimension ``(M,)`` or
  16             ``(M, N)``.
  17         lower (bool): Use only data contained in the lower triangle of ``a``.
  18             Default is to use upper triangle.
  19         trans (0, 1, 2, 'N', 'T' or 'C'): Type of system to solve:
  20 
  21             - *'0'* or *'N'* -- :math:`a x  = b`
  22             - *'1'* or *'T'* -- :math:`a^T x = b`
  23             - *'2'* or *'C'* -- :math:`a^H x = b`
  24 
  25         unit_diagonal (bool): If ``True``, diagonal elements of ``a`` are
  26             assumed to be 1 and will not be referenced.
  27         overwrite_b (bool): Allow overwriting data in b (may enhance
  28             performance)
  29         check_finite (bool): Whether to check that the input matrices contain
  30             only finite numbers. Disabling may give a performance gain, but may
  31             result in problems (crashes, non-termination) if the inputs do
  32             contain infinities or NaNs.
  33 
  34     Returns:
  35         cupy.ndarray:
  36             The matrix with dimension ``(M,)`` or ``(M, N)``.
  37 
  38     .. seealso:: :func:`scipy.linalg.solve_triangular`
  39     """
  40 
  41     _util._assert_cupy_array(a, b)
  42 
  43     if len(a.shape) != 2 or a.shape[0] != a.shape[1]:
  44         raise ValueError('expected square matrix')
  45     if len(a) != len(b):
  46         raise ValueError('incompatible dimensions')
  47 
  48     # Cast to float32 or float64
  49     if a.dtype.char in 'fd':
  50         dtype = a.dtype
  51     else:
  52         dtype = numpy.promote_types(a.dtype.char, 'f')
  53 
  54     a = cupy.array(a, dtype=dtype, order='F', copy=False)
  55     b = cupy.array(b, dtype=dtype, order='F', copy=(not overwrite_b))
  56 
  57     if check_finite:
  58         if a.dtype.kind == 'f' and not cupy.isfinite(a).all():
  59             raise ValueError(
  60                 'array must not contain infs or NaNs')
  61         if b.dtype.kind == 'f' and not cupy.isfinite(b).all():
  62             raise ValueError(
  63                 'array must not contain infs or NaNs')
  64 
  65     m, n = (b.size, 1) if b.ndim == 1 else b.shape
  66     cublas_handle = device.get_cublas_handle()
  67 
  68     if dtype == 'f':
  69         trsm = cublas.strsm
  70     else:  # dtype == 'd'
  71         trsm = cublas.dtrsm
  72     one = numpy.array(1, dtype=dtype)
  73 
  74     if lower:
  75         uplo = cublas.CUBLAS_FILL_MODE_LOWER
  76     else:
  77         uplo = cublas.CUBLAS_FILL_MODE_UPPER
  78 
  79     if trans == 'N':
  80         trans = cublas.CUBLAS_OP_N
  81     elif trans == 'T':
  82         trans = cublas.CUBLAS_OP_T
  83     elif trans == 'C':
  84         trans = cublas.CUBLAS_OP_C
  85 
  86     if unit_diagonal:
  87         diag = cublas.CUBLAS_DIAG_UNIT
  88     else:
  89         diag = cublas.CUBLAS_DIAG_NON_UNIT
  90 
  91     trsm(
  92         cublas_handle, cublas.CUBLAS_SIDE_LEFT, uplo,
  93         trans, diag,
  94         m, n, one.ctypes.data, a.data.ptr, m, b.data.ptr, m)
  95     return b
  96
  [end of cupyx/scipy/linalg/solve_triangular.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/cupyx/scipy/linalg/solve_triangular.py b/cupyx/scipy/linalg/solve_triangular.py
  --- a/cupyx/scipy/linalg/solve_triangular.py
  +++ b/cupyx/scipy/linalg/solve_triangular.py
  @@ -67,8 +67,12 @@
   
       if dtype == 'f':
           trsm = cublas.strsm
  -    else:  # dtype == 'd'
  +    elif dtype == 'd':
           trsm = cublas.dtrsm
  +    elif dtype == 'F':
  +        trsm = cublas.ctrsm
  +    else:  # dtype == 'D'
  +        trsm = cublas.ztrsm
       one = numpy.array(1, dtype=dtype)
   
       if lower:
  
verification_info: {"golden_diff": "diff --git a/cupyx/scipy/linalg/solve_triangular.py b/cupyx/scipy/linalg/solve_triangular.py\n--- a/cupyx/scipy/linalg/solve_triangular.py\n+++ b/cupyx/scipy/linalg/solve_triangular.py\n@@ -67,8 +67,12 @@\n \n     if dtype == 'f':\n         trsm = cublas.strsm\n-    else:  # dtype == 'd'\n+    elif dtype == 'd':\n         trsm = cublas.dtrsm\n+    elif dtype == 'F':\n+        trsm = cublas.ctrsm\n+    else:  # dtype == 'D'\n+        trsm = cublas.ztrsm\n     one = numpy.array(1, dtype=dtype)\n \n     if lower:\n", "issue": "Triangular Solve not working for complex case\nI have discovered, that `solve_triangular` does not work, if the input is complex, but the matrix is real:\r\n```\r\nsolve_triangular(\r\n     cholesky,\r\n     rhs,\r\n     lower=True,\r\n)\r\n```\r\nproduces a real valued result, if `cholesky` is real but `rhs` is complex.\r\n\r\n```\r\nintelpython3 -c 'import cupy; cupy.show_config()'\r\nOS                           : Linux-5.9.6-1-MANJARO-x86_64-with-arch-Manjaro-Linux\r\nCuPy Version                 : 9.0.0a1\r\nNumPy Version                : 1.16.2+intel.0\r\nSciPy Version                : 1.5.0\r\nCython Build Version         : 0.29.21\r\nCython Runtime Version       : 0.29.6\r\nCUDA Root                    : /opt/cuda\r\nCUDA Build Version           : 11010\r\nCUDA Driver Version          : 11010\r\nCUDA Runtime Version         : 11010\r\ncuBLAS Version               : 11300\r\ncuFFT Version                : 10300\r\ncuRAND Version               : 10202\r\ncuSOLVER Version             : (11, 0, 1)\r\ncuSPARSE Version             : 11300\r\nNVRTC Version                : (11, 1)\r\nThrust Version               : 100910\r\nCUB Build Version            : 100910\r\ncuDNN Build Version          : None\r\ncuDNN Version                : None\r\nNCCL Build Version           : 2708\r\nNCCL Runtime Version         : 2708\r\ncuTENSOR Version             : None\r\nDevice 0 Name                : GeForce RTX 3090\r\nDevice 0 Compute Capability  : 86\r\n```\r\n\r\n\n", "before_files": [{"content": "import numpy\n\nimport cupy\nfrom cupy.cuda import cublas\nfrom cupy.cuda import device\nfrom cupy.linalg import _util\n\n\ndef solve_triangular(a, b, trans=0, lower=False, unit_diagonal=False,\n                     overwrite_b=False, check_finite=False):\n    \"\"\"Solve the equation a x = b for x, assuming a is a triangular matrix.\n\n    Args:\n        a (cupy.ndarray): The matrix with dimension ``(M, M)``.\n        b (cupy.ndarray): The matrix with dimension ``(M,)`` or\n            ``(M, N)``.\n        lower (bool): Use only data contained in the lower triangle of ``a``.\n            Default is to use upper triangle.\n        trans (0, 1, 2, 'N', 'T' or 'C'): Type of system to solve:\n\n            - *'0'* or *'N'* -- :math:`a x  = b`\n            - *'1'* or *'T'* -- :math:`a^T x = b`\n            - *'2'* or *'C'* -- :math:`a^H x = b`\n\n        unit_diagonal (bool): If ``True``, diagonal elements of ``a`` are\n            assumed to be 1 and will not be referenced.\n        overwrite_b (bool): Allow overwriting data in b (may enhance\n            performance)\n        check_finite (bool): Whether to check that the input matrices contain\n            only finite numbers. Disabling may give a performance gain, but may\n            result in problems (crashes, non-termination) if the inputs do\n            contain infinities or NaNs.\n\n    Returns:\n        cupy.ndarray:\n            The matrix with dimension ``(M,)`` or ``(M, N)``.\n\n    .. seealso:: :func:`scipy.linalg.solve_triangular`\n    \"\"\"\n\n    _util._assert_cupy_array(a, b)\n\n    if len(a.shape) != 2 or a.shape[0] != a.shape[1]:\n        raise ValueError('expected square matrix')\n    if len(a) != len(b):\n        raise ValueError('incompatible dimensions')\n\n    # Cast to float32 or float64\n    if a.dtype.char in 'fd':\n        dtype = a.dtype\n    else:\n        dtype = numpy.promote_types(a.dtype.char, 'f')\n\n    a = cupy.array(a, dtype=dtype, order='F', copy=False)\n    b = cupy.array(b, dtype=dtype, order='F', copy=(not overwrite_b))\n\n    if check_finite:\n        if a.dtype.kind == 'f' and not cupy.isfinite(a).all():\n            raise ValueError(\n                'array must not contain infs or NaNs')\n        if b.dtype.kind == 'f' and not cupy.isfinite(b).all():\n            raise ValueError(\n                'array must not contain infs or NaNs')\n\n    m, n = (b.size, 1) if b.ndim == 1 else b.shape\n    cublas_handle = device.get_cublas_handle()\n\n    if dtype == 'f':\n        trsm = cublas.strsm\n    else:  # dtype == 'd'\n        trsm = cublas.dtrsm\n    one = numpy.array(1, dtype=dtype)\n\n    if lower:\n        uplo = cublas.CUBLAS_FILL_MODE_LOWER\n    else:\n        uplo = cublas.CUBLAS_FILL_MODE_UPPER\n\n    if trans == 'N':\n        trans = cublas.CUBLAS_OP_N\n    elif trans == 'T':\n        trans = cublas.CUBLAS_OP_T\n    elif trans == 'C':\n        trans = cublas.CUBLAS_OP_C\n\n    if unit_diagonal:\n        diag = cublas.CUBLAS_DIAG_UNIT\n    else:\n        diag = cublas.CUBLAS_DIAG_NON_UNIT\n\n    trsm(\n        cublas_handle, cublas.CUBLAS_SIDE_LEFT, uplo,\n        trans, diag,\n        m, n, one.ctypes.data, a.data.ptr, m, b.data.ptr, m)\n    return b\n", "path": "cupyx/scipy/linalg/solve_triangular.py"}]}