class_docstr: Speaker Diarization model
  
  If "attractor" is "None", SA-EEND will be used.
  Else if "attractor" is not "None", EEND-EDA will be used.
  For the details about SA-EEND and EEND-EDA, refer to the following papers:
  SA-EEND: https://arxiv.org/pdf/1909.06247.pdf
  EEND-EDA: https://arxiv.org/pdf/2005.09921.pdf, https://arxiv.org/pdf/2106.10654.pdf
code: def calc_diarization_error(pred, label, length):
      # Note (jiatong): Credit to https://github.com/hitachi-speech/EEND
  
      (batch_size, max_len, num_output) = label.size()
      # mask the padding part
      mask = np.zeros((batch_size, max_len, num_output))
      for i in range(batch_size):
          mask[i, : length[i], :] = 1
  
      # pred and label have the shape (batch_size, max_len, num_output)
      label_np = label.data.cpu().numpy().astype(int)
      pred_np = (pred.data.cpu().numpy() > 0).astype(int)
      label_np = label_np * mask
      pred_np = pred_np * mask
      length = length.data.cpu().numpy()
  
      # compute speech activity detection error
      n_ref = np.sum(label_np, axis=2)
      n_sys = np.sum(pred_np, axis=2)
      speech_scored = float(np.sum(n_ref > 0))
      speech_miss = float(np.sum(np.logical_and(n_ref > 0, n_sys == 0)))
      speech_falarm = float(
          np.sum(np.logical_and(n_ref == 0, n_sys > 0))
      )
  
      # compute speaker diarization error
      speaker_scored = float(np.sum(n_ref))
      speaker_miss = float(np.sum(np.maximum(n_ref - n_sys, 0)))
      speaker_falarm = float(np.sum(np.maximum(n_sys - n_ref, 0)))
      n_map = np.sum(
          np.logical_and(label_np == 1, pred_np == 1), axis=2
      )
      speaker_error = float(np.sum(np.minimum(n_ref, n_sys) - n_map))
      correct = float(
          1.0 * np.sum((label_np == pred_np) * mask) / num_output
      )
      num_frames = np.sum(length)
      return (
          correct,
          num_frames,
          speech_scored,
          speech_miss,
          speech_falarm,
          speaker_scored,
          speaker_miss,
          speaker_falarm,
          speaker_error,
      )
  
imports: from contextlib import contextmanager
  from itertools import permutations
  from typing import Dict, Optional, Tuple
  import numpy
  import torch
  import torch.nn.functional
  from packaging.version import parse
  from typeguard import check_argument_types
  from espnet2.asr.encoder.abs_encoder import AbsEncoder
  from espnet2.asr.frontend.abs_frontend import AbsFrontend
  from espnet2.asr.specaug.abs_specaug import AbsSpecAug
  from espnet2.diar.attractor.abs_attractor import AbsAttractor
  from espnet2.diar.decoder.abs_decoder import AbsDecoder
  from espnet2.layers.abs_normalize import AbsNormalize
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.train.abs_espnet_model import AbsESPnetModel
  from espnet.nets.pytorch_backend.nets_utils import to_device
label_desc: Use image node_id 10 for calling the ESPnetDiarizationModel obj's underlying member method code with example usage: obj.calc_diarization_error(pred, label, length) and returns: correct,  num_frames,  speech_scored,  speech_miss,  speech_falarm,  speaker_scored,  speaker_miss,  speaker_falarm,  speaker_error