code: def _triangular_solve(
      matrix, rhs, lower=True, adjoint=False, name=None
  ):  # pylint: disable=redefined-outer-name
      """Scipy solve does not broadcast, so we must do so explicitly."""
      del name
      if JAX_MODE:
          (
              matrix_broadcast,
              rhs_broadcast,
              rhs_batch_dims,
              result_permutation,
          ) = _create_solve_broadcastable_inputs(matrix, rhs)
          result = scipy_linalg.solve_triangular(
              matrix_broadcast,
              rhs_broadcast,
              lower=lower,
              trans="C" if adjoint else "N",
          )
          return _reshape_solve_result(
              result, rhs_batch_dims, result_permutation
          )
      try:
          bcast_shp = np.broadcast_shapes(
              matrix.shape[:-2], rhs.shape[:-2]
          )
      except ValueError as e:
          raise ValueError(
              f"Error with inputs shaped `matrix`={matrix.shape}, rhs={rhs.shape}"
          ) from e
      dim = matrix.shape[-1]
      matrix = np.broadcast_to(matrix, bcast_shp + (dim, dim))
      rhs = np.broadcast_to(rhs, bcast_shp + (dim, rhs.shape[-1]))
      nbatch = int(np.prod(bcast_shp))
      flat_mat = matrix.reshape(nbatch, dim, dim)
      flat_rhs = rhs.reshape(nbatch, dim, rhs.shape[-1])
      result = np.empty(flat_rhs.shape, dtype=flat_rhs.dtype)
      if np.size(result):
          # ValueError: On entry to STRTRS parameter number 7 had an illegal value.
          for i, (mat, rh) in enumerate(zip(flat_mat, flat_rhs)):
              result[i] = scipy_linalg.solve_triangular(
                  mat, rh, lower=lower, trans="C" if adjoint else "N"
              )
      return result.reshape(*rhs.shape)
  
imports: import collections
  import functools
  import numpy
  from tensorflow_probability.python.internal.backend.numpy import _utils
  from tensorflow_probability.python.internal.backend.numpy import ops
label_desc: Use image node_id 24 for calling a global function with example usage: _triangular_solve(matrix, rhs, lower, adjoint, name) and returns: result, _reshape_solve_result