docstr: Cosine similarity between some reference mics and some target mics
  
  ref: shape (nmic1, L, seg1)
  target: shape (nmic2, L, seg2)
docstr_tok: ["Cosine","similarity","between","some","reference","mics","and","some","target","mics","ref",":","shape","(","nmic1",",","L",",","seg1",")","target",":","shape","(","nmic2",",","L",",","seg2",")"]
code: def seq_cos_sim(self, ref, target):
      """Cosine similarity between some reference mics and some target mics
  
      ref: shape (nmic1, L, seg1)
      target: shape (nmic2, L, seg2)
      """
  
      assert ref.size(1) == target.size(
          1
      ), "Inputs should have same length."
      assert ref.size(2) >= target.size(
          2
      ), "Reference input should be no smaller than the target input."
  
      seq_length = ref.size(1)
  
      larger_ch = ref.size(0)
      if target.size(0) > ref.size(0):
          ref = ref.expand(
              target.size(0), ref.size(1), ref.size(2)
          ).contiguous()  # nmic2, L, seg1
          larger_ch = target.size(0)
      elif target.size(0) < ref.size(0):
          target = target.expand(
              ref.size(0), target.size(1), target.size(2)
          ).contiguous()  # nmic1, L, seg2
  
      # L2 norms
      ref_norm = F.conv1d(
          ref.view(1, -1, ref.size(2)).pow(2),
          torch.ones(ref.size(0) * ref.size(1), 1, target.size(2)).type(
              ref.type()
          ),
          groups=larger_ch * seq_length,
      )  # 1, larger_ch*L, seg1-seg2+1
      ref_norm = ref_norm.sqrt() + self.eps
      target_norm = (
          target.norm(2, dim=2).view(1, -1, 1) + self.eps
      )  # 1, larger_ch*L, 1
      # cosine similarity
      cos_sim = F.conv1d(
          ref.view(1, -1, ref.size(2)),
          target.view(-1, 1, target.size(2)),
          groups=larger_ch * seq_length,
      )  # 1, larger_ch*L, seg1-seg2+1
      cos_sim = cos_sim / (ref_norm * target_norm)
  
      return cos_sim.view(larger_ch, seq_length, -1)
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from espnet2.enh.layers import dprnn
label_desc: Use image node_id 5 for calling the FaSNet_base obj's underlying member method code with example usage: obj.seq_cos_sim(ref, target) and returns: cos_sim