def _triangular_solve(a: TfVal, b: TfVal, *, left_side: bool, lower: bool, transpose_a: bool, conjugate_a: bool, unit_diagonal: bool, _in_avals: Sequence[core.ShapedArray], _out_aval: core.ShapedArray):
    if unit_diagonal:
        (a_aval, _) = _in_avals
        a_shape = _eval_shape(a_aval.shape)
        a = tf.linalg.set_diag(a, tf.ones(a_shape[:(- 1)], dtype=a.dtype))
    if (not left_side):
        rank = len(a.shape)
        transpose_dimensions = (list(range((rank - 2))) + [(rank - 1), (rank - 2)])
        a = tf.transpose(a, transpose_dimensions)
        b = tf.transpose(b, transpose_dimensions)
        lower = (not lower)
    if (a.dtype in [tf.complex64, tf.complex128]):
        if ((transpose_a and (not conjugate_a)) or ((not transpose_a) and conjugate_a)):
            a = tf.math.conj(a)
    result = tf.linalg.triangular_solve(a, b, lower=lower, adjoint=transpose_a)
    if (not left_side):
        result = tf.transpose(result, transpose_dimensions)
    return result
def _triangular_solve(a: TfVal, b: TfVal, *, left_side: bool, lower: bool, transpose_a: bool, conjugate_a: bool, unit_diagonal: bool, _in_avals: Sequence[core.ShapedArray], _out_aval: core.ShapedArray):
    if unit_diagonal:
        (a_aval, _) = _in_avals
        a_shape = _eval_shape(a_aval.shape)
        a = tf.linalg.set_diag(a, tf.ones(a_shape[:(- 1)], dtype=a.dtype))
    if (not left_side):
        rank = len(a.shape)
        transpose_dimensions = (list(range((rank - 2))) + [(rank - 1), (rank - 2)])
        a = tf.transpose(a, transpose_dimensions)
        b = tf.transpose(b, transpose_dimensions)
        lower = (not lower)
    if (a.dtype in [tf.complex64, tf.complex128]):
        if ((transpose_a and (not conjugate_a)) or ((not transpose_a) and conjugate_a)):
            a = tf.math.conj(a)
    result = tf.linalg.triangular_solve(a, b, lower=lower, adjoint=transpose_a)
    if (not left_side):
        result = tf.transpose(result, transpose_dimensions)
    return result