ó
 ‰\c           @   s%   d  d l  Z d „  Z e d „ Z d S(   iÿÿÿÿNc            s¡  t  j |  ƒ }  t |  ƒ } t  j t  j |  ƒ ƒ } t  j |  ƒ } t t  j |  ƒ ƒ } | | k rt t d ƒ f | S| | d | t  j	 | ƒ } | | k  j
 ƒ  r"xz t | ƒ D]i } | | | | <t t  j | | d ƒ ƒ } | | d | | d | | d )| | k j ƒ  r² Pq² q² Wn  | d j t ƒ } t  j | ƒ j t ƒ } g  t | | ƒ D] \ }	 }
 t |	 d |
 ƒ ^ q]‰  t ‡  f d †  | Dƒ ƒ ‰  ˆ  S(   sÆ  Find `n_points` regularly spaced along `ar_shape`.

    The returned points (as slices) should be as close to cubically-spaced as
    possible. Essentially, the points are spaced by the Nth root of the input
    array size, where N is the number of dimensions. However, if an array
    dimension cannot fit a full step size, it is "discarded", and the
    computation is done for only the remaining dimensions.

    Parameters
    ----------
    ar_shape : array-like of ints
        The shape of the space embedding the grid. ``len(ar_shape)`` is the
        number of dimensions.
    n_points : int
        The (approximate) number of points to embed in the space.

    Returns
    -------
    slices : tuple of slice objects
        A slice along each dimension of `ar_shape`, such that the intersection
        of all the slices give the coordinates of regularly spaced points.

        .. versionchanged:: 0.14.1
            In scikit-image 0.14.1 and 0.15, the return type was changed from a
            list to a tuple to ensure `compatibility with Numpy 1.15`_ and
            higher. If your code requires the returned result to be a list, you
            may convert the output of this function to a list with:

            >>> result = list(regular_grid(ar_shape=(3, 20, 40), n_points=8))

            .. _compatibility with NumPy 1.15: https://github.com/numpy/numpy/blob/master/doc/release/1.15.0-notes.rst#deprecations

    Examples
    --------
    >>> ar = np.zeros((20, 40))
    >>> g = regular_grid(ar.shape, 8)
    >>> g
    (slice(5, None, 10), slice(5, None, 10))
    >>> ar[g] = 1
    >>> ar.sum()
    8.0
    >>> ar = np.zeros((20, 40))
    >>> g = regular_grid(ar.shape, 32)
    >>> g
    (slice(2, None, 5), slice(2, None, 5))
    >>> ar[g] = 1
    >>> ar.sum()
    32.0
    >>> ar = np.zeros((3, 20, 40))
    >>> g = regular_grid(ar.shape, 8)
    >>> g
    (slice(1, None, 3), slice(5, None, 10), slice(5, None, 10))
    >>> ar[g] = 1
    >>> ar.sum()
    8.0
    g      ð?i   i   c         3   s   |  ] } ˆ  | Vq d  S(   N(    (   t   .0t   i(   t   slices(    s9   lib/python2.7/site-packages/skimage/util/_regular_grid.pys	   <genexpr>Q   s    N(   t   npt
   asanyarrayt   lent   argsortt   sortt   floatt   prodt   slicet   Nonet   onest   anyt   ranget   allt   astypet   intt   roundt   zipt   tuple(   t   ar_shapet   n_pointst   ndimt   unsort_dim_idxst   sorted_dimst
   space_sizet	   stepsizest   dimt   startst   startt   step(    (   R   s9   lib/python2.7/site-packages/skimage/util/_regular_grid.pyt   regular_grid   s,    91c         C   sY   t  |  | ƒ } t j |  d | ƒ} d t j t j | | j ƒ | | j ƒ | | <| S(   se  Return an image with ~`n_points` regularly-spaced nonzero pixels.

    Parameters
    ----------
    ar_shape : tuple of int
        The shape of the desired output image.
    n_points : int
        The desired number of nonzero points.
    dtype : numpy data type, optional
        The desired data type of the output.

    Returns
    -------
    seed_img : array of int or bool
        The desired image.

    Examples
    --------
    >>> regular_seeds((5, 5), 4)
    array([[0, 0, 0, 0, 0],
           [0, 1, 0, 2, 0],
           [0, 0, 0, 0, 0],
           [0, 3, 0, 4, 0],
           [0, 0, 0, 0, 0]])
    t   dtypei   (   R    R   t   zerost   reshapet   aranget   sizet   shape(   R   R   R!   t   gridt   seed_img(    (    s9   lib/python2.7/site-packages/skimage/util/_regular_grid.pyt   regular_seedsU   s
    (   t   numpyR   R    R   R)   (    (    (    s9   lib/python2.7/site-packages/skimage/util/_regular_grid.pyt   <module>   s   	Q