code: def lu_solve(
      lu_and_piv, b, trans=0, overwrite_b=False, check_finite=True
  ):
      """Solve an equation system, ``a * x = b``, given the LU factorization of ``a``
  
      Args:
          lu_and_piv (tuple): LU factorization of matrix ``a`` (``(M, M)``)
              together with pivot indices.
          b (cupy.ndarray): The matrix with dimension ``(M,)`` or
              ``(M, N)``.
          trans ({0, 1, 2}): Type of system to solve:
  
              ========  =========
              trans     system
              ========  =========
              0         a x  = b
              1         a^T x = b
              2         a^H x = b
              ========  =========
          overwrite_b (bool): Allow overwriting data in b (may enhance
              performance)
          check_finite (bool): Whether to check that the input matrices contain
              only finite numbers. Disabling may give a performance gain, but may
              result in problems (crashes, non-termination) if the inputs do
              contain infinities or NaNs.
  
      Returns:
          cupy.ndarray:
              The matrix with dimension ``(M,)`` or ``(M, N)``.
  
      .. seealso:: :func:`scipy.linalg.lu_solve`
      """  # NOQA
      from cupy_backends.cuda.libs import cusolver
  
      (lu, ipiv) = lu_and_piv
  
      _util._assert_cupy_array(lu)
      _util._assert_2d(lu)
      _util._assert_stacked_square(lu)
  
      m = lu.shape[0]
      if m != b.shape[0]:
          raise ValueError("incompatible dimensions.")
  
      dtype = lu.dtype
      if dtype.char == "f":
          getrs = cusolver.sgetrs
      elif dtype.char == "d":
          getrs = cusolver.dgetrs
      elif dtype.char == "F":
          getrs = cusolver.cgetrs
      elif dtype.char == "D":
          getrs = cusolver.zgetrs
      else:
          msg = "Only float32, float64, complex64 and complex128 are supported."
          raise NotImplementedError(msg)
  
      if trans == 0:
          trans = cublas.CUBLAS_OP_N
      elif trans == 1:
          trans = cublas.CUBLAS_OP_T
      elif trans == 2:
          trans = cublas.CUBLAS_OP_C
      else:
          raise ValueError("unknown trans")
  
      lu = lu.astype(dtype, order="F", copy=False)
      ipiv = ipiv.astype(ipiv.dtype, order="F", copy=True)
      # cuSolver uses 1-origin while SciPy uses 0-origin
      ipiv += 1
      b = b.astype(dtype, order="F", copy=(not overwrite_b))
  
      if check_finite:
          if lu.dtype.kind == "f" and not cupy.isfinite(lu).all():
              raise ValueError(
                  "array must not contain infs or NaNs.\n"
                  "Note that when a singular matrix is given, unlike "
                  "scipy.linalg.lu_factor, cupyx.scipy.linalg.lu_factor "
                  "returns an array containing NaN."
              )
          if b.dtype.kind == "f" and not cupy.isfinite(b).all():
              raise ValueError("array must not contain infs or NaNs")
  
      n = 1 if b.ndim == 1 else b.shape[1]
      cusolver_handle = device.get_cusolver_handle()
      dev_info = cupy.empty(1, dtype=numpy.int32)
  
      # solve for the inverse
      getrs(
          cusolver_handle,
          trans,
          m,
          n,
          lu.data.ptr,
          m,
          ipiv.data.ptr,
          b.data.ptr,
          m,
          dev_info.data.ptr,
      )
  
      if not runtime.is_hip and dev_info[0] < 0:
          # rocSOLVER does not inform us this info
          raise ValueError(
              "illegal value in %d-th argument of "
              "internal getrs (lu_solve)" % -dev_info[0]
          )
  
      return b
  
file_path: cupy/cupyx/scipy/linalg/_decomp_lu.py
imports: from warnings import warn
  import numpy
  import cupy
  from cupy.cuda import cublas
  from cupy.cuda import device
  from cupy.cuda import runtime
  from cupy.linalg import _util
  from cupyx.scipy.linalg import _uarray
label_desc: Use image node_id 6 for calling a global function with example usage: lu_solve(lu_and_piv, b, trans, overwrite_b, check_finite) and returns: b