
    1-Ph                     >    d dl Z dgZd ZddZ	 	 	 	 	 d	dddddZdS )
    Napply_parallelc           	      $   ddl m} g }t           ||dt          |           z  z                      }d}| D ]J}||k     r%||z  }|||z  z   }|dk    r|f}	n|f|dz
  z  |fz   }	n|f}	|                    |	           ||z  }Kt          |          S )a  Split the array into equal sized chunks based on the number of
    available processors. The last chunk in each dimension absorbs the
    remainder array elements if the number of CPUs does not divide evenly into
    the number of array elements.

    Examples
    --------
    >>> _get_chunks((4, 4), 4)
    ((2, 2), (2, 2))
    >>> _get_chunks((4, 4), 2)
    ((2, 2), (4,))
    >>> _get_chunks((5, 5), 2)
    ((2, 3), (5,))
    >>> _get_chunks((2, 4), 2)
    ((1, 1), (4,))
    r   )ceilg      ?   )mathr   intlenappendtuple)
shapencpur   chunksnchunks_per_dimused_chunksiregular_chunkremainder_chunk
chunk_lenss
             [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/util/apply_parallel.py_get_chunksr      s    & F$$tc%jj(89::;;OK ' '0M+q?/BCO!!-/

+-11DE#I 

 Jj!!!&==    c                 j    dd l m} t          | |j                  r| S |                    | |          S )Nr   r   )
dask.arrayarray
isinstanceArray
from_array)r   r   das      r   _ensure_dask_arrayr    2   sC    %"" ==v=...r    )dtypecomputechannel_axisc                R    	 ddl m}
 n# t          $ r t          d          w xY wi |t	          ||
j                   }|	
|	|j        z  }	||j        }	 ddlm	}  |            }n# t          $ r d}Y nw xY w|	a|d|	         ||	dz   d         z   }t          t          ||                    }|                    |	||	                    t          |          }nmt          ||          }n\|	Zt          |          |j        dz
  k    r?t          |          }|                    |	|j        |	                    t          |          }|dk    rd}n|d	k    rd
}n|dk    rd}n|d
}|	qt!          j        |          r|g|j        dz
  z  }t          |          }t          |          |j        dz
  k    r|                    |	d           t          |          } fd}t%          ||          }|                    ||||          }|r|                                }|S )ab  Map a function in parallel across an array.

    Split an array into possibly overlapping chunks of a given depth and
    boundary type, call the given function in parallel on the chunks, combine
    the chunks and return the resulting array.

    Parameters
    ----------
    function : function
        Function to be mapped which takes an array as an argument.
    array : numpy array or dask array
        Array which the function will be applied to.
    chunks : int, tuple, or tuple of tuples, optional
        A single integer is interpreted as the length of one side of a square
        chunk that should be tiled across the array.  One tuple of length
        ``array.ndim`` represents the shape of a chunk, and it is tiled across
        the array.  A list of tuples of length ``ndim``, where each sub-tuple
        is a sequence of chunk sizes along the corresponding dimension. If
        None, the array is broken up into chunks based on the number of
        available cpus. More information about chunks is in the documentation
        `here <https://dask.pydata.org/en/latest/array-design.html>`_. When
        `channel_axis` is not None, the tuples can be length ``ndim - 1`` and
        a single chunk will be used along the channel axis.
    depth : int or sequence of int, optional
        The depth of the added boundary cells. A tuple can be used to specify a
        different depth per array axis. Defaults to zero. When `channel_axis`
        is not None, and a tuple of length ``ndim - 1`` is provided, a depth of
        0 will be used along the channel axis.
    mode : {'reflect', 'symmetric', 'periodic', 'wrap', 'nearest', 'edge'}, optional
        Type of external boundary padding.
    extra_arguments : tuple, optional
        Tuple of arguments to be passed to the function.
    extra_keywords : dictionary, optional
        Dictionary of keyword arguments to be passed to the function.
    dtype : data-type or None, optional
        The data-type of the `function` output. If None, Dask will attempt to
        infer this by calling the function on data of shape ``(1,) * ndim``.
        For functions expecting RGB or multichannel data this may be
        problematic. In such cases, the user should manually specify this dtype
        argument instead.

        .. versionadded:: 0.18
           ``dtype`` was added in 0.18.
    compute : bool, optional
        If ``True``, compute eagerly returning a NumPy Array.
        If ``False``, compute lazily returning a Dask Array.
        If ``None`` (default), compute based on array type provided
        (eagerly for NumPy Arrays and lazily for Dask Arrays).
    channel_axis : int or None, optional
        If None, the image is assumed to be a grayscale (single channel) image.
        Otherwise, this parameter indicates which axis of the array corresponds
        to channels.

    Returns
    -------
    out : ndarray or dask Array
        Returns the result of the applying the operation.
        Type is dependent on the ``compute`` argument.

    Notes
    -----
    Numpy edge modes 'symmetric', 'wrap', and 'edge' are converted to the
    equivalent ``dask`` boundary modes 'reflect', 'periodic' and 'nearest',
    respectively.
    Setting ``compute=False`` can be useful for chaining later operations.
    For example region selection to preview a result or storing large data
    to disk instead of loading in memory.

    r   NzACould not import 'dask'.  Please install using 'pip install dask')	cpu_count   r   wrapperiodic	symmetricreflectedgenearestc                      | gR i S Nr!   )arrextra_argumentsextra_keywordsfunctions    r   wrapped_funcz$apply_parallel.<locals>.wrapped_func   s#    x@o@@@@@@r   r   )boundaryr"   )r   r   ImportErrorRuntimeErrorr   r   ndimr   multiprocessingr&   NotImplementedErrorlistr   insertr   r	   numpyisscalarr    map_overlapr#   )r3   r   r   depthmoder1   r2   r"   r#   r$   r   r   r&   r   spatial_shaper4   darrress   `    ``           r   r   r   ;   s   d
 	  
 
 
R
 
 	


  111#ej0~	 2111119;;DD" 	 	 	DDD	#!-<-059I9K9K3LLM+mT::;;FMM,l(;<<<6]]FF --FF		!c&kkUZ!^&C&CflEK$=>>>vv~~					 >%   	/GuzA~.EUu::a''LLq)))eA A A A A A A eF333D


<U

K
KC kkmmJs    &A, ,A;:A;r/   )Nr   Nr!   N)r=   __all__r   r    r   r!   r   r   <module>rF      s    
) ) )X/ / / / 
	Z Z Z Z Z Z Z Zr   