
    1-PhG                     "    d dl ZddlmZ ddZdS )    N   )_spathFc           	         |dk     r
|| j         z  }d|z  dz   f| j         dz
  z  }t          j        |          |z
  }t          j        ||t          j        |          d          }t          j                            |          }t          j        || j         |fd          j        }| j	        d|         | j	        |dz   d         z   }t          j        |          }	t          j                            |          }
t          j        |	|t          j
        |          d          }t          j        || j         |
fd          j        }t          j        |	|t          j        |d|	j        	          d          }t          j        || j         |
fd          j        }t          j        | |
          }|                    ||d          \  }}|D ])}|t!          |                   }|t          j        k    r n*|                    |          }|s[t          j        |          }t          j        |ddd|f         |dd|dz   df         gd          }t          j        |          }||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)find_all_ends)ndimnpindicesinsertonesmultiplyreducereshapeTshapezerosfullr   r   MCP_Diff
find_coststupleinf	tracebackarrayconcatenatesqueeze)arrreachr   output_indexlistoffset_ind_shapeoffset_indicesoffset_sizer   non_axis_shapenon_axis_indicesnon_axis_sizestart_indicesstartsend_indicesendsmcostsr   endcosts                       S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/graph/spath.pyshortest_pathr4      s~   H axxE	A'38a<8Z 011E9NY~tRW=M5N5NUVWWWN+$$%566Kj#(K)@LLLNG
 Yuu%	$(**(==Nz.11K&&~66MI.bh~6N6NUVWWWMZ-'@LLLNF)
*:*@AAA	  K :kCHm#<CHHHJD 	W---A||FD|FFE9   U3ZZ 26>>E C  I *HY''	Nqqq%4%x )AAAtaxzzM":;!
 
 
	 Jy))	d?    )r   r   F)numpyr    r   r4    r5   r3   <module>r9      sG             N N N N N Nr5   