U
    ?h                     @   s"   d dl ZddlmZ dddZdS )	    N   )_spathFc                 C   s  |dk r|| j 7 }d| d f| j d  }t|| }tj||t|dd}tj|}tj|| j |fddj}| j	d| | j	|d d  }t|}	tj|}
tj|	|t
|dd}tj|| j |
fddj}tj|	|tj|d|	jd	dd}tj|| j |
fddj}tj| |d
}|j||dd\}}|D ]$}|t| }|tjkr8 q^q8||}|st|}tj|ddd|f |dd|d df gdd}t|}||fS )aB  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.

    r      r   )axisF)orderNr   )dtype)offsetsF)Zfind_all_ends)ndimnpindicesinsertZonesmultiplyreduceZreshapeTshapeZzerosfullr	   r   ZMCP_DiffZ
find_coststupleinf	tracebackarrayZconcatenateZsqueeze)Zarrreachr   Zoutput_indexlistZoffset_ind_shapeZoffset_indicesoffset_sizer
   Znon_axis_shapeZnon_axis_indicesZnon_axis_sizeZstart_indicesZstartsZend_indicesZendsmZcostsr   endZcost r   E/var/www/html/venv/lib/python3.8/site-packages/skimage/graph/spath.pyshortest_path   sR    $
  
 



r   )r   r   F)numpyr    r   r   r   r   r   r   <module>   s   