code: def triplet_margin_loss(
      anchor,
      positive,
      negative,
      margin=1.0,
      p=2.0,
      eps=1e-06,
      swap=False,
      size_average=None,
      reduce=None,
      reduction="mean",
  ):
      def pairwise_distance(x1, x2, *, p=2.0, eps=1e-06, keepdim=False):
          x1, x2 = torch_frontend.promote_types_of_torch_inputs(x1, x2)
          x1_dim = len(x1.shape)
          x2_dim = len(x2.shape)
          if x1_dim > x2_dim:
              output_dim = x1_dim
          else:
              output_dim = x2_dim
  
          return ivy.vector_norm(
              x1 - x2 + eps,
              ord=p,
              axis=output_dim - 1,
              keepdims=keepdim,
          )
  
      reduction = _get_reduction(reduction, size_average, reduce)
  
      a_dim = anchor.ndim
      p_dim = positive.ndim
      n_dim = negative.ndim
  
      ivy.assertions.check_true(
          a_dim == p_dim and p_dim == n_dim,
          lambda: (
              "The anchor, positive, and negative tensors are expected to have "
              f"the same number of dimensions, but got: anchor {a_dim}D, "
              f"positive {p_dim}D, and negative {n_dim}D inputs"
          ),
      )
  
      dist_positive = pairwise_distance(anchor, positive, p=p, eps=eps)
      dist_negative = pairwise_distance(anchor, negative, p=p, eps=eps)
      if swap:
          dist_swap = pairwise_distance(
              positive, negative, p=p, eps=eps
          )
          dist_negative = ivy.minimum(dist_negative, dist_swap)
      loss = ivy.maximum(
          dist_positive - dist_negative + ivy.array(margin),
          ivy.array(0.0),
      )
  
      loss = reduction(loss).astype(anchor.dtype)
      return loss
  
imports: import ivy
  import ivy.functional.frontends.torch
  from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back
  from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes
label_desc: Use image node_id 26 for calling a global function with example usage: triplet_margin_loss(anchor, positive, negative, margin, p, eps, swap, size_average, reduce, reduction) and returns: loss, ivy