code: def solve_triangular(
      a,
      b,
      trans=0,
      lower=False,
      unit_diagonal=False,
      overwrite_b=False,
      check_finite=True,
  ):
      """
      Solve the equation `a x = b` for `x`, assuming a is a triangular matrix.
  
      Parameters
      ----------
      a : (M, M) array_like
          A triangular matrix
      b : (M,) or (M, N) array_like
          Right-hand side matrix in `a x = b`
      lower : bool, optional
          Use only data contained in the lower triangle of `a`.
          Default is to use upper triangle.
      trans : {0, 1, 2, 'N', 'T', 'C'}, optional
          Type of system to solve:
  
          ========  =========
          trans     system
          ========  =========
          0 or 'N'  a x  = b
          1 or 'T'  a^T x = b
          2 or 'C'  a^H x = b
          ========  =========
      unit_diagonal : bool, optional
          If True, diagonal elements of `a` are assumed to be 1 and
          will not be referenced.
      overwrite_b : bool, optional
          Allow overwriting data in `b` (may enhance performance)
      check_finite : bool, optional
          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
      -------
      x : (M,) or (M, N) ndarray
          Solution to the system `a x = b`.  Shape of return matches `b`.
  
      Raises
      ------
      LinAlgError
          If `a` is singular
  
      Notes
      -----
      .. versionadded:: 0.9.0
  
      Examples
      --------
      Solve the lower triangular system a x = b, where::
  
               [3  0  0  0]       [4]
          a =  [2  1  0  0]   b = [2]
               [1  0  1  0]       [4]
               [1  1  1  1]       [2]
  
      >>> import numpy as np
      >>> from scipy.linalg import solve_triangular
      >>> a = np.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]])
      >>> b = np.array([4, 2, 4, 2])
      >>> x = solve_triangular(a, b, lower=True)
      >>> x
      array([ 1.33333333, -0.66666667,  2.66666667, -1.33333333])
      >>> a.dot(x)  # Check the result
      array([ 4.,  2.,  4.,  2.])
  
      """
  
      a1 = _asarray_validated(a, check_finite=check_finite)
      b1 = _asarray_validated(b, check_finite=check_finite)
      if len(a1.shape) != 2 or a1.shape[0] != a1.shape[1]:
          raise ValueError("expected square matrix")
      if a1.shape[0] != b1.shape[0]:
          raise ValueError(
              f"shapes of a {a1.shape} and b {b1.shape} are incompatible"
          )
      overwrite_b = overwrite_b or _datacopied(b1, b)
  
      trans = {"N": 0, "T": 1, "C": 2}.get(trans, trans)
      (trtrs,) = get_lapack_funcs(("trtrs",), (a1, b1))
      if a1.flags.f_contiguous or trans == 2:
          x, info = trtrs(
              a1,
              b1,
              overwrite_b=overwrite_b,
              lower=lower,
              trans=trans,
              unitdiag=unit_diagonal,
          )
      else:
          # transposed system is solved since trtrs expects Fortran ordering
          x, info = trtrs(
              a1.T,
              b1,
              overwrite_b=overwrite_b,
              lower=not lower,
              trans=not trans,
              unitdiag=unit_diagonal,
          )
  
      if info == 0:
          return x
      if info > 0:
          raise LinAlgError(
              "singular matrix: resolution failed at diagonal %d"
              % (info - 1)
          )
      raise ValueError(
          "illegal value in %dth argument of internal trtrs" % (-info)
      )
  
imports: from warnings import warn
  from itertools import product
  import numpy
  from numpy import atleast_1d, atleast_2d
  from .lapack import get_lapack_funcs, _compute_lwork
  from ._misc import LinAlgError, _datacopied, LinAlgWarning
  from ._decomp import _asarray_validated
  from .None import _decomp, _decomp_svd
  from ._solve_toeplitz import levinson
  from ._cythonized_array_utils import find_det_from_lu
  from scipy._lib.deprecation import _NoValue, _deprecate_positional_args
label_desc: Use image node_id 3 for calling a global function with example usage: solve_triangular(a, b, trans, lower, unit_diagonal, overwrite_b, check_finite) and returns: x