class_docstr: Contrastive loss function.
class_docstr_tok: ["Contrastive","loss","function","."]
code: def forward(self, inputs):
      xp = backend.get_array_module(*inputs)
      self.retain_inputs((0, 1, 2))
      x0, x1, y = inputs
  
      diff = x0 - x1
      dist_sq = xp.sum(diff**2, axis=1)
      dist = xp.sqrt(dist_sq)
      mdist = self.margin - dist
      dist = xp.maximum(mdist, 0)
      loss = (y * dist_sq + (1 - y) * dist * dist) * 0.5
      if self.reduce == "mean":
          loss = xp.sum(loss) / x0.shape[0]
      return (xp.array(loss, dtype=x0.dtype),)
  
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 3 for calling the Contrastive obj's underlying member method code with example usage: obj.forward(inputs) and returns: xp