code: def solve_triangular(a, b, lower=False, sparse=None):
      """
      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.
      sparse: bool, optional
          Return sparse value or not.
  
      Returns
      -------
      x : (M,) or (M, N) ndarray
          Solution to the system `a x = b`.  Shape of return matches `b`.
  
      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 mars.tensor as mt
      >>> a = mt.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]])
      >>> b = mt.array([4, 2, 4, 2])
      >>> x = mt.linalg.solve_triangular(a, b, lower=True)
      >>> x.execute()
      array([ 1.33333333, -0.66666667,  2.66666667, -1.33333333])
  
      >>> a.dot(x).execute()  # Check the result
      array([ 4.,  2.,  4.,  2.])
      """
      import scipy.linalg
  
      a = astensor(a)
      b = astensor(b)
  
      if a.ndim != 2:
          raise LinAlgError("a must be 2 dimensional")
      if b.ndim <= 2:
          if a.shape[1] != b.shape[0]:
              raise LinAlgError(
                  "a.shape[1] and b.shape[0] must be equal"
              )
      else:
          raise LinAlgError("b must be 1 or 2 dimensional")
  
      tiny_x = scipy.linalg.solve_triangular(
          np.array([[2, 0], [2, 1]], dtype=a.dtype),
          np.array([[2], [3]], dtype=b.dtype),
      )
      sparse = sparse if sparse is not None else a.issparse()
      op = TensorSolveTriangular(
          lower=lower, dtype=tiny_x.dtype, sparse=sparse
      )
      return op(a, b)
  
imports: import numpy
  from numpy.linalg import LinAlgError
  from ...None import opcodes
  from ...core import recursive_tile
  from ...serialization.serializables import BoolField, KeyField
  from ...utils import has_unknown_shape
  from ..array_utils import device, as_same_device, cp
  from ..operands import TensorOperand, TensorOperandMixin
  from ..datasource import tensor
  from ..utils import decide_unify_split
  from ..core import TensorOrder
label_desc: Use image node_id 1 for calling a global function with example usage: solve_triangular(a, b, lower, sparse) and returns: op