code: def _lu_factor(a, overwrite_a=False, check_finite=True):
      from cupy_backends.cuda.libs import cusolver
  
      a = cupy.asarray(a)
      _util._assert_2d(a)
  
      dtype = a.dtype
  
      if dtype.char == "f":
          getrf = cusolver.sgetrf
          getrf_bufferSize = cusolver.sgetrf_bufferSize
      elif dtype.char == "d":
          getrf = cusolver.dgetrf
          getrf_bufferSize = cusolver.dgetrf_bufferSize
      elif dtype.char == "F":
          getrf = cusolver.cgetrf
          getrf_bufferSize = cusolver.cgetrf_bufferSize
      elif dtype.char == "D":
          getrf = cusolver.zgetrf
          getrf_bufferSize = cusolver.zgetrf_bufferSize
      else:
          msg = "Only float32, float64, complex64 and complex128 are supported."
          raise NotImplementedError(msg)
  
      a = a.astype(dtype, order="F", copy=(not overwrite_a))
  
      if check_finite:
          if a.dtype.kind == "f" and not cupy.isfinite(a).all():
              raise ValueError("array must not contain infs or NaNs")
  
      cusolver_handle = device.get_cusolver_handle()
      dev_info = cupy.empty(1, dtype=numpy.int32)
  
      m, n = a.shape
  
      ipiv = cupy.empty((min(m, n),), dtype=numpy.intc)
  
      buffersize = getrf_bufferSize(
          cusolver_handle, m, n, a.data.ptr, m
      )
      workspace = cupy.empty(buffersize, dtype=dtype)
  
      # LU factorization
      getrf(
          cusolver_handle,
          m,
          n,
          a.data.ptr,
          m,
          workspace.data.ptr,
          ipiv.data.ptr,
          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 getrf (lu_factor)" % -dev_info[0]
          )
      elif dev_info[0] > 0:
          warn(
              "Diagonal number %d is exactly zero. Singular matrix."
              % dev_info[0],
              RuntimeWarning,
              stacklevel=2,
          )
  
      # cuSolver uses 1-origin while SciPy uses 0-origin
      ipiv -= 1
  
      return (a, ipiv)
  
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 3 for calling a global function with example usage: _lu_factor(a, overwrite_a, check_finite) and returns: a,  ipiv