
    hh                     L    d dl Zd dlmZmZ d Zdej                  ddfdddZy)	    N)cKDTreedistancec                    t        |       }|j                  | ||      }t               }d}t        |      D ]  \  }}	||vs|	j	                  |       t        j                  | |   g| |	   d|      j                  d      }
t        |	|
      D cg c]  \  }}||k  s| }	}}|j                  |	       |dz  }|||k\  s n t        j                  | t        |      d      }||d| }|S c c}}w )	a  Returns a subset of coord where a minimum spacing is guaranteed.

    Parameters
    ----------
    coord : ndarray
        The coordinates of the considered points.
    spacing : float
        the maximum allowed spacing between the points.
    p_norm : float
        Which Minkowski p-norm to use. Should be in the range [1, inf].
        A finite large p may cause a ValueError if overflow can occur.
        ``inf`` corresponds to the Chebyshev distance and 2 to the
        Euclidean distance.
    max_out: int
        If not None, at most the first ``max_out`` candidates are
        returned.

    Returns
    -------
    output : ndarray
        A subset of coord where a minimum spacing is guaranteed.

    )rpr   	minkowski)r      N)axis)r   query_ball_pointset	enumerateremover   cdistreshapezipupdatenpdeletetuple)coordspacingp_normmax_outtreeindicesrejected_peaks_indices	nacceptedidx
candidatesdistcdoutputs                 S/var/www/html/dev/engine/venv/lib/python3.12/site-packages/skimage/_shared/coord.py_ensure_spacingr&      s   4 5>D##EW#?G UI$W- Z,,c">>seJ/gbk  ),J(=M1W!MJM #))*5NI"yG';  YYue$:;!DF!M Ns   C2C2r
   2   i  )max_split_sizec                   | }t        |       rt        j                  |       } || g}nct        |       }|g}	|}
||	d   z
  |kD  r2|
dz  }
|	j                  |	d   t	        |
|      z          ||	d   z
  |kD  r2t        j
                  | |	      }t        j                  d| j                  d   f| j                        }|D ]9  }t        t        j                  ||g      |||      }|)t        |      |k\  s8 |S  |S )a  Returns a subset of coord where a minimum spacing is guaranteed.

    Parameters
    ----------
    coords : array_like
        The coordinates of the considered points.
    spacing : float
        the maximum allowed spacing between the points.
    p_norm : float
        Which Minkowski p-norm to use. Should be in the range [1, inf].
        A finite large p may cause a ValueError if overflow can occur.
        ``inf`` corresponds to the Chebyshev distance and 2 to the
        Euclidean distance.
    min_split_size : int
        Minimum split size used to process ``coords`` by batch to save
        memory. If None, the memory saving strategy is not applied.
    max_out : int
        If not None, only the first ``max_out`` candidates are returned.
    max_split_size : int
        Maximum split size used to process ``coords`` by batch to save
        memory. This number was decided by profiling with a large number
        of points. Too small a number results in too much looping in
        Python instead of C, slowing down the process, while too large
        a number results in large memory allocations, slowdowns, and,
        potentially, in the process being killed -- see gh-6010. See
        benchmark results `here
        <https://github.com/scikit-image/scikit-image/pull/6035#discussion_r751518691>`_.

    Returns
    -------
    output : array_like
        A subset of coord where a minimum spacing is guaranteed.

    r	      r   r
   )dtype)lenr   
atleast_2dappendminarray_splitzerosshaper+   r&   vstack)coordsr   r   min_split_sizer   r(   r$   
batch_listcoord_count	split_idx
split_sizebatchs               r%   ensure_spacingr;   ;   s   V F
6{v&! Jf+K'(I'J	"->a
  2Z1P!PQ 	"-> 	:J1fll1o.fllC 	E$		65/*GVWF "s6{g'=M	 M    )numpyr   scipy.spatialr   r   r&   infr;    r<   r%   <module>rA      s4     +3p 66A Ar<   