
    0-Ph                     D    d dl Zd dlmZmZ d Zdej        ddfdddZdS )	    N)cKDTreedistancec                 "   t          |           }|                    | |          }t                      }d}t          |          D ]\  }}	||vr|	                    |           t          j        | |         g| |	         d|                              d          }
fdt          |	|
          D             }	|	                    |	           |dz  }|||k    r nt          j        | t          |          d	          }|
|d|         }|S )
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   c                 &    g | ]\  }}|k     |S  r   ).0cdspacings      U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/_shared/coord.py
<listcomp>z#_ensure_spacing.<locals>.<listcomp>+   s"    MMM1W!       N)axis)r   query_ball_pointset	enumerateremover   cdistreshapezipupdatenpdeletetuple)coordr   p_normmax_outtreeindicesrejected_peaks_indices	nacceptedidx
candidatesdistoutputs    `          r   _ensure_spacingr+      sA   4 5>>D##EW#??G UUI$W--  Z,,,c""">seJ/  gbkk  NMMMJ(=(=MMMJ #))*555NI"yG';'; Yue$:;;!DDDF!Mr   r   2   i  )max_split_sizec                    | }t          |           rt          j        |           } || g}nxt          |           }|g}	|}
||	d         z
  |k    r@|
dz  }
|	                    |	d         t	          |
|          z              ||	d         z
  |k    @t          j        | |	          }t          j        d| j        d         f| j                  }|D ]?}t          t          j
        ||g          |||          }|t          |          |k    r n@|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.

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