def cosine_distance(x: torch.Tensor, z: Optional[torch.Tensor] = None) -> torch.Tensor:
    """Calculate cosine distance between x and z.
    @TODO: Docs. Contribution is welcome.
    """
    x = F.normalize(x)

    if z is not None:
        z = F.normalize(z)
    else:
        z = x.clone()

    return torch.sub(1, torch.mm(x, z.transpose(0, 1)))
Calculate cosine distance between x and z.
    @TODO: Docs. Contribution is welcome.
    
catalyst/contrib/losses/functional.py