code: def cosine_similarity(context, node):
      inputs = _get_inputs(context, node, expected=4)
      dim = inputs[-2].val
      eps = inputs[-1].val
      xy = mb.mul(x=inputs[0], y=inputs[1])
      sum_xy = mb.reduce_sum(x=xy, axes=[dim])
  
      xx = mb.mul(x=inputs[0], y=inputs[0])
      sum_xx = mb.reduce_sum(x=xx, axes=[dim])
      yy = mb.mul(x=inputs[1], y=inputs[1])
      sum_yy = mb.reduce_sum(x=yy, axes=[dim])
  
      mul_sum_xy = mb.mul(x=sum_xx, y=sum_yy)
      div_12 = mb.maximum(x=mul_sum_xy, y=eps * eps)
      div_sqrt = mb.sqrt(x=div_12)
  
      cs = mb.real_div(x=sum_xy, y=div_sqrt, name=node.name)
      context.add(cs)
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/frontend/torch/test/test_custom_ops.py
imports: import itertools
  import numpy
  import pytest
  import torch
  import torch.nn
  import coremltools
  from .testing_utils import *
  from coremltools.converters.mil.mil.ops.defs._op_reqs import *
  from coremltools.converters.mil.frontend.torch.torch_op_registry import register_torch_op
  from coremltools.converters.mil.frontend.torch.torch_op_registry import _TORCH_OPS_REGISTRY
  from coremltools.converters.mil.frontend.torch.ops import _get_inputs
  from coremltools.converters.mil.mil import Builder
label_desc: Use image node_id 1 for calling a global function with example usage: cosine_similarity(context, node) without return types