ó
 ‰\c           @   s2   d  d l  Z d d l m Z d d  e d „ Z d S(   iÿÿÿÿNi   (   t   _spathc         C   se  | d k  r | |  j  7} n  d | d f |  j  d } t j | ƒ | } t j | | t j | ƒ d d ƒ} t j j | ƒ } t j | |  j  | f d d ƒj } |  j	 |  |  j	 | d } t j | ƒ }	 t j j | ƒ }
 t j |	 | t j
 | ƒ d d ƒ} t j | |  j  |
 f d d ƒj } t j |	 | t j | ƒ d d ƒ} t j | |  j  |
 f d d ƒj } t j |  d | ƒ} | j | | d t ƒ\ } } x1 | D]) } | t | ƒ } | t j k r­Pq­q­W| j | ƒ } | s[t j | ƒ } t j | d	 d	 … d	 | … f | d	 d	 … | d d	 … f g d d ƒ} t j | ƒ } n  | | f S(
   sA  Find the shortest path through an n-d array from one side to another.

    Parameters
    ----------
    arr : ndarray of float64
    reach : int, optional
        By default (``reach = 1``), the shortest path can only move
        one row up or down for every step it moves forward (i.e.,
        the path gradient is limited to 1). `reach` defines the
        number of elements that can be skipped along each non-axis
        dimension at each step.
    axis : int, optional
        The axis along which the path must always move forward (default -1)
    output_indexlist: bool, optional
        See return value `p` for explanation.

    Returns
    -------
    p : iterable of int
        For each step along `axis`, the coordinate of the shortest path.
        If `output_indexlist` is True, then the path is returned as a list of
        n-d tuples that index into `arr`. If False, then the path is returned
        as an array listing the coordinates of the path along the non-axis
        dimensions for each step along the axis dimension. That is,
        `p.shape == (arr.shape[axis], arr.ndim-1)` except that p is squeezed
        before returning so if `arr.ndim == 2`, then
        `p.shape == (arr.shape[axis],)`
    cost : float
        Cost of path.  This is the absolute sum of all the
        differences along the path.

    i    i   i   t   axist   ordert   Ft   offsetst   find_all_endsN(   t   ndimt   npt   indicest   insertt   onest   multiplyt   reducet   reshapet   Tt   shapet   zerosR    t   MCP_Difft
   find_costst   Falset   tuplet   inft	   tracebackt   arrayt   concatenatet   squeeze(   t   arrt   reachR   t   output_indexlistt   offset_ind_shapet   offset_indicest   offset_sizeR   t   non_axis_shapet   non_axis_indicest   non_axis_sizet   start_indicest   startst   end_indicest   endst   mt   costsR   t   endt   cost(    (    s2   lib/python2.7/site-packages/skimage/graph/spath.pyt   shortest_path   s<    $$$	$,(   t   numpyR   t    R    R   R+   (    (    (    s2   lib/python2.7/site-packages/skimage/graph/spath.pyt   <module>   s   