code: def cw_log_loss(output, target, targeted=False, buff=1e-5):
      """
      :param outputs: pre-softmax/logits.
      :param target: true labels.
      :return: CW loss value.
      """
      num_classes = output.size(1)
      label_mask = to_one_hot(target, num_classes=num_classes).float()
      correct_logit = torch.log(
          torch.sum(label_mask * output, dim=1) + buff
      )
      wrong_logit = torch.log(
          torch.max((1.0 - label_mask) * output, dim=1)[0] + buff
      )
  
      if targeted:
          loss = -0.5 * F.relu(wrong_logit - correct_logit + 50.0)
      else:
          loss = -0.5 * F.relu(correct_logit - wrong_logit + 50.0)
      return loss
  
imports: from math import inf
  from typing import Optional
  import torch
  import torch.nn.functional
  from advertorch.attacks.base import Attack
  from advertorch.attacks.base import LabelMixin
  from .utils import _check_param, _flatten, _make_projector
  from advertorch.utils import to_one_hot
label_desc: Use image node_id 1 for calling a global function with example usage: cw_log_loss(output, target, targeted, buff) and returns: loss