code: def haplotype_diversity(h):
      
  
      # check inputs
      h = HaplotypeArray(h, copy=False)
  
      # number of haplotypes
      n = h.n_haplotypes
  
      # compute haplotype frequencies
      f = h.distinct_frequencies()
  
      # estimate haplotype diversity
      hd = (1 - np.sum(f**2)) * n / (n - 1)
  
      return hd
docs: Estimate haplotype diversity.
  
      Parameters
      ----------
      h : array_like, int, shape (n_variants, n_haplotypes)
          Haplotype array.
  
      Returns
      -------
      hd : float
          Haplotype diversity.