False`, and ``f = float(len(D)) / float(len(R))`` is the
ratio between number of objects from data and random.

The algorithm implemented here is loosely based on the dual-tree
algorithm described in [1]_. We switch between two different
pair-cumulation scheme depending on the setting of ``cumulative``.
The computing time of the method we use when for
``cumulative == False`` does not scale with the total number of bins.
The algorithm for ``cumulative == True`` scales linearly with the
number of bins, though it is slightly faster when only
1 or 2 bins are used. [5]_.

As an extension to the naive pair-counting,
weighted pair-counting counts the product of weights instead
of number of pairs.
Weighted pair-counting is used to estimate marked correlation functions
([3]_, section 2.2),
or to properly calculate the average of data per distance bin
(e.g. [4]_, section 2.1 on redshift).

.. [1] Gray and Moore,
       "N-body problems in statistical learning",
       Mining the sky, 2000,
       https://arxiv.org/abs/astro-ph/0012333

.. [2] Landy and Szalay,
       "Bias and variance of angular correlation functions",
       The Astrophysical Journal, 1993,
       http://adsabs.harvard.edu/abs/1993ApJ...412...64L

.. [3] Sheth, Connolly and Skibba,
       "Marked correlations in galaxy formation models",
       Arxiv e-print, 2005,
       https://arxiv.org/abs/astro-ph/0511773

.. [4] Hawkins, et al.,
       "The 2dF Galaxy Redshift Survey: correlation functions,
       peculiar velocities and the matter density of the Universe",
       Monthly Notices of the Royal Astronomical Society, 2002,
       http://adsabs.harvard.edu/abs/2003MNRAS.346...78H

.. [5] https://github.com/scipy/scipy/pull/5647#issuecomment-168474926

Examples
--------
You can count neighbors number between two kd-trees within a distance:

>>> import numpy as np
>>> from scipy.spatial import KDTree
>>> rng = np.random.default_rng()
>>> points1 = rng.random((5, 2))
>>> points2 = rng.random((5, 2))
>>> kd_tree1 = KDTree(points1)
>>> kd_tree2 = KDTree(points2)
>>> kd_tree1.count_neighbors(kd_tree2, 0.2)
1

This number is same as the total pair number calculated by
`query_ball_tree`:

>>> indexes = kd_tree1.query_ball_tree(kd_tree2, r=0.2)
>>> sum([len(i) for i in indexes])
1

)