class_docstr: Contrastive loss function.
class_docstr_tok: ["Contrastive","loss","function","."]
code: def backward(self, indexes, grad_outputs):
      x0, x1, y = self.get_retained_inputs()
      (gy,) = grad_outputs
      xp = backend.get_array_module(gy.data)
  
      # Recompute intermediate variables as in forward.
      diff = x0 - x1
      dist_sq = chainer.functions.sum(diff**2, axis=1)
      dist = chainer.functions.sqrt(dist_sq)
      mdist = self.margin - dist
  
      y = y.data
      x_dim = x0.shape[1]
      y = xp.repeat(y[:, None], x_dim, axis=1)
      if self.reduce == "mean":
          alpha = gy / y.shape[0]
      else:
          alpha = gy[:, None]
      alpha = chainer.functions.broadcast_to(alpha, y.shape)
      dist = chainer.functions.repeat(dist[:, None], x_dim, axis=1)
      # avoid division by zero, 1e-7 is not sufficiently small value because
      # 1e7 cannot be represented in half precision.
      eps = 5e-3 if dist.dtype == "float16" else 1e-7
      dist = chainer.functions.maximum(
          dist, xp.full(dist.shape, eps, dtype=dist.dtype)
      )
      # similar pair
      gx0 = alpha * y.astype(alpha.dtype) * diff
      # dissimilar pair
      d = chainer.functions.repeat(mdist[:, None], x_dim, axis=1)
      mdist = chainer.functions.maximum(
          d, xp.zeros(shape=d.shape, dtype=d.dtype)
      )
      gx0 += alpha * (1 - y) * mdist * -(diff / dist)
      gx0 = chainer.functions.cast(gx0, x0.dtype)
  
      return gx0, -gx0, None
  
file_path: chainer/chainer/functions/loss/contrastive.py
imports: from chainer import backend
  from chainer import function_node
  import chainer.functions
  from chainer.utils import type_check
label_desc: Use image node_id 4 for calling the Contrastive obj's underlying member method code with example usage: obj.backward(indexes, grad_outputs) and returns: gx0,  unknown,  None