code: def fidelity_based(h1, h2): # 25 us @array, 51 us @list \w 100 bins
      r
      h1, h2 = __prepare_histogram(h1, h2)
      result = scipy.sum(scipy.sqrt(h1 * h2))
      result = 0 if 0 > result else result # for rounding errors
      result = 1 if 1 < result else result # for rounding errors
      return result
docs: r"""
      Fidelity based distance.
      
      Also Bhattacharyya distance; see also the extensions `noelle_1` to `noelle_5`.
      
      The metric between two histograms :math:`H` and :math:`H'` of size :math:`m` is defined as:
      
      .. math::
      
          d_{F}(H, H') = \sum_{m=1}^M\sqrt{H_m * H'_m}
      
      
      *Attributes:*
  
      - not a metric, a similarity
      
      *Attributes for normalized histograms:*
  
      - :math:`d(H, H')\in[0, 1]`
      - :math:`d(H, H) = 1`
      - :math:`d(H, H') = d(H', H)`
      
      *Attributes for not-normalized histograms:*
  
      - not applicable
      
      *Attributes for not-equal histograms:*
  
      - not applicable
      
      Parameters
      ----------
      h1 : sequence
          The first histogram, normalized.
      h2 : sequence
          The second histogram, normalized, same bins as ``h1``.
      
      Returns
      -------
      fidelity_based : float
          Fidelity based distance.
      
      Notes
      -----
      The fidelity between two histograms :math:`H` and :math:`H'` is the same as the
      cosine between their square roots :math:`\sqrt{H}` and :math:`\sqrt{H'}`.