code: def _interpolate(
      latents1: Tensor,
      latents2: Tensor,
      epsilon: float = 1e-4,
      interpolation_method: Literal[
          "lerp", "slerp_any", "slerp_unit"
      ] = "lerp",
  ) -> Tensor:
      """Interpolate between two sets of latents.
  
      Inspired by: https://github.com/toshas/torch-fidelity/blob/master/torch_fidelity/noise.py
  
      Args:
          latents1: First set of latents.
          latents2: Second set of latents.
          epsilon: Spacing between the points on the path between latent points.
          interpolation_method: Interpolation method to use. Choose from 'lerp', 'slerp_any', 'slerp_unit'.
  
      """
      eps = 1e-7
      if latents1.shape != latents2.shape:
          raise ValueError("Latents must have the same shape.")
      if interpolation_method == "lerp":
          return latents1 + (latents2 - latents1) * epsilon
      if interpolation_method == "slerp_any":
          ndims = latents1.dim() - 1
          z_size = latents1.shape[-1]
          latents1_norm = latents1 / (latents1**2).sum(
              dim=-1, keepdim=True
          ).sqrt().clamp_min(eps)
          latents2_norm = latents2 / (latents2**2).sum(
              dim=-1, keepdim=True
          ).sqrt().clamp_min(eps)
          d = (latents1_norm * latents2_norm).sum(dim=-1, keepdim=True)
          mask_zero = (
              latents1_norm.norm(dim=-1, keepdim=True) < eps
          ) | (latents2_norm.norm(dim=-1, keepdim=True) < eps)
          mask_collinear = (d > 1 - eps) | (d < -1 + eps)
          mask_lerp = (mask_zero | mask_collinear).repeat(
              [1 for _ in range(ndims)] + [z_size]
          )
          omega = d.acos()
          denom = omega.sin().clamp_min(eps)
          coef_latents1 = ((1 - epsilon) * omega).sin() / denom
          coef_latents2 = (epsilon * omega).sin() / denom
          out = coef_latents1 * latents1 + coef_latents2 * latents2
          out[mask_lerp] = _interpolate(
              latents1, latents2, epsilon, interpolation_method="lerp"
          )[mask_lerp]
          return out
      if interpolation_method == "slerp_unit":
          out = _interpolate(
              latents1=latents1,
              latents2=latents2,
              epsilon=epsilon,
              interpolation_method="slerp_any",
          )
          return out / (out**2).sum(
              dim=-1, keepdim=True
          ).sqrt().clamp_min(eps)
      raise ValueError(
          f"Interpolation method {interpolation_method} not supported. Choose from 'lerp', 'slerp_any', 'slerp_unit'."
      )
  
file_path: torchmetrics/src/torchmetrics/functional/image/perceptual_path_length.py
imports: import math
  from typing import Literal, Optional, Tuple, Union
  import torch
  from torch import Tensor, nn
  from torchmetrics.functional.image.lpips import _LPIPS
  from torchmetrics.utilities.imports import _TORCHVISION_AVAILABLE
label_desc: Use image node_id 3 for calling a global function with example usage: _interpolate(latents1, latents2, epsilon, interpolation_method) and returns: unknown, out, unknown