§
    )Áôg”  ã                   ó8   — d dl Z d dlZd dlmZ ddgZd„ Zdd„ZdS )	é    N)Ú
as_stridedÚview_as_blocksÚview_as_windowsc                 ó.  — t          |t          ¦  «        st          d¦  «        ‚t          j        |¦  «        }|dk                         ¦   «         rt          d¦  «        ‚|j        | j        k    rt          d¦  «        ‚t          j        | j	        ¦  «        }||z   
                    ¦   «         dk    rt          d¦  «        ‚t          ||z  ¦  «        t          |¦  «        z   }t          | j        |z  ¦  «        | j        z   }t          | ||¬¦  «        }|S )aB  Block view of the input n-dimensional array (using re-striding).

    Blocks are non-overlapping views of the input array.

    Parameters
    ----------
    arr_in : ndarray, shape (M[, ...])
        Input array.
    block_shape : tuple
        The shape of the block. Each dimension must divide evenly into the
        corresponding dimensions of `arr_in`.

    Returns
    -------
    arr_out : ndarray
        Block view of the input array.

    Examples
    --------
    >>> import numpy as np
    >>> from skimage.util.shape import view_as_blocks
    >>> A = np.arange(4*4).reshape(4,4)
    >>> A
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11],
           [12, 13, 14, 15]])
    >>> B = view_as_blocks(A, block_shape=(2, 2))
    >>> B[0, 0]
    array([[0, 1],
           [4, 5]])
    >>> B[0, 1]
    array([[2, 3],
           [6, 7]])
    >>> B[1, 0, 1, 1]
    13

    >>> A = np.arange(4*4*6).reshape(4,4,6)
    >>> A  # doctest: +NORMALIZE_WHITESPACE
    array([[[ 0,  1,  2,  3,  4,  5],
            [ 6,  7,  8,  9, 10, 11],
            [12, 13, 14, 15, 16, 17],
            [18, 19, 20, 21, 22, 23]],
           [[24, 25, 26, 27, 28, 29],
            [30, 31, 32, 33, 34, 35],
            [36, 37, 38, 39, 40, 41],
            [42, 43, 44, 45, 46, 47]],
           [[48, 49, 50, 51, 52, 53],
            [54, 55, 56, 57, 58, 59],
            [60, 61, 62, 63, 64, 65],
            [66, 67, 68, 69, 70, 71]],
           [[72, 73, 74, 75, 76, 77],
            [78, 79, 80, 81, 82, 83],
            [84, 85, 86, 87, 88, 89],
            [90, 91, 92, 93, 94, 95]]])
    >>> B = view_as_blocks(A, block_shape=(1, 2, 2))
    >>> B.shape
    (4, 2, 3, 1, 2, 2)
    >>> B[2:, 0, 2]  # doctest: +NORMALIZE_WHITESPACE
    array([[[[52, 53],
             [58, 59]]],
           [[[76, 77],
             [82, 83]]]])
    zblock needs to be a tupler   z0'block_shape' elements must be strictly positivez9'block_shape' must have the same length as 'arr_in.shape'z-'block_shape' is not compatible with 'arr_in'©ÚshapeÚstrides)Ú
isinstanceÚtupleÚ	TypeErrorÚnpÚarrayÚanyÚ
ValueErrorÚsizeÚndimr   Úsumr	   r   )Úarr_inÚblock_shapeÚ	arr_shapeÚ	new_shapeÚnew_stridesÚarr_outs         ú[/var/www/html/bac/bac_backend/python/env/lib/python3.11/site-packages/skimage/util/shape.pyr   r      s  € õB �k¥5Ñ)Ô)ð 5ÝÐ3Ñ4Ô4Ð4å”(˜;Ñ'Ô'€KØ�qÒ×ÒÑÔð MÝÐKÑLÔLÐLàÔ˜6œ;Ò&Ð&ÝÐWÑXÔXÐXå”˜œÑ&Ô&€IØ�KÑ×$Ò$Ñ&Ô&¨!Ò+Ð+ÝÐHÑIÔIÐIõ �i ;Ñ.Ñ/Ô/µ%¸Ñ2DÔ2DÑD€IÝ˜œ¨Ñ4Ñ5Ô5¸¼ÑF€Kå˜ y¸+ÐFÑFÔF€Gà€Nó    é   c                 ó†  — t          | t          j        ¦  «        st          d¦  «        ‚| j        }t          |t
          j        ¦  «        r|f|z  }t          |¦  «        |k    st          d¦  «        ‚t          |t
          j        ¦  «        r|dk     rt          d¦  «        ‚|f|z  }t          |¦  «        |k    rt          d¦  «        ‚t          j	        | j
        ¦  «        }t          j	        ||j        ¬¦  «        }||z
  dk                          ¦   «         rt          d¦  «        ‚|dz
  dk                          ¦   «         rt          d	¦  «        ‚t          d
„ |D ¦   «         ¦  «        }t          j	        | j        ¦  «        }| |         j        }t          j	        | j
        ¦  «        t          j	        |¦  «        z
  t          j	        |¦  «        z  dz   }t          t          |¦  «        t          |¦  «        z   ¦  «        }	t          t          |¦  «        t          |¦  «        z   ¦  «        }
t!          | |	|
¬¦  «        }|S )a~  Rolling window view of the input n-dimensional array.

    Windows are overlapping views of the input array, with adjacent windows
    shifted by a single row or column (or an index of a higher dimension).

    Parameters
    ----------
    arr_in : ndarray, shape (M[, ...])
        Input array.
    window_shape : integer or tuple of length arr_in.ndim
        Defines the shape of the elementary n-dimensional orthotope
        (better know as hyperrectangle [1]_) of the rolling window view.
        If an integer is given, the shape will be a hypercube of
        sidelength given by its value.
    step : integer or tuple of length arr_in.ndim
        Indicates step size at which extraction shall be performed.
        If integer is given, then the step is uniform in all dimensions.

    Returns
    -------
    arr_out : ndarray
        (rolling) window view of the input array.

    Notes
    -----
    One should be very careful with rolling views when it comes to
    memory usage.  Indeed, although a 'view' has the same memory
    footprint as its base array, the actual array that emerges when this
    'view' is used in a computation is generally a (much) larger array
    than the original, especially for 2-dimensional arrays and above.

    For example, let us consider a 3 dimensional array of size (100,
    100, 100) of ``float64``. This array takes about 8*100**3 Bytes for
    storage which is just 8 MB. If one decides to build a rolling view
    on this array with a window of (3, 3, 3) the hypothetical size of
    the rolling view (if one was to reshape the view for example) would
    be 8*(100-3+1)**3*3**3 which is about 203 MB! The scaling becomes
    even worse as the dimension of the input array becomes larger.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Hyperrectangle

    Examples
    --------
    >>> import numpy as np
    >>> from skimage.util.shape import view_as_windows
    >>> A = np.arange(4*4).reshape(4,4)
    >>> A
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11],
           [12, 13, 14, 15]])
    >>> window_shape = (2, 2)
    >>> B = view_as_windows(A, window_shape)
    >>> B[0, 0]
    array([[0, 1],
           [4, 5]])
    >>> B[0, 1]
    array([[1, 2],
           [5, 6]])

    >>> A = np.arange(10)
    >>> A
    array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    >>> window_shape = (3,)
    >>> B = view_as_windows(A, window_shape)
    >>> B.shape
    (8, 3)
    >>> B
    array([[0, 1, 2],
           [1, 2, 3],
           [2, 3, 4],
           [3, 4, 5],
           [4, 5, 6],
           [5, 6, 7],
           [6, 7, 8],
           [7, 8, 9]])

    >>> A = np.arange(5*4).reshape(5, 4)
    >>> A
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11],
           [12, 13, 14, 15],
           [16, 17, 18, 19]])
    >>> window_shape = (4, 3)
    >>> B = view_as_windows(A, window_shape)
    >>> B.shape
    (2, 2, 4, 3)
    >>> B  # doctest: +NORMALIZE_WHITESPACE
    array([[[[ 0,  1,  2],
             [ 4,  5,  6],
             [ 8,  9, 10],
             [12, 13, 14]],
            [[ 1,  2,  3],
             [ 5,  6,  7],
             [ 9, 10, 11],
             [13, 14, 15]]],
           [[[ 4,  5,  6],
             [ 8,  9, 10],
             [12, 13, 14],
             [16, 17, 18]],
            [[ 5,  6,  7],
             [ 9, 10, 11],
             [13, 14, 15],
             [17, 18, 19]]]])
    z `arr_in` must be a numpy ndarrayz2`window_shape` is incompatible with `arr_in.shape`r   z`step` must be >= 1z*`step` is incompatible with `arr_in.shape`)Údtyper   z`window_shape` is too largez`window_shape` is too smallc              3   ó8   K  — | ]}t          d d |¦  «        V — Œd S )N)Úslice)Ú.0Ústs     r   ú	<genexpr>z"view_as_windows.<locals>.<genexpr>ê   s.   è è € Ð8Ð8¨R•5˜˜t RÑ(Ô(Ð8Ð8Ð8Ð8Ð8Ð8r   r   )r
   r   Úndarrayr   r   ÚnumbersÚNumberÚlenr   r   r   r   r   r   r	   Úlistr   )r   Úwindow_shapeÚstepr   r   ÚslicesÚwindow_stridesÚindexing_stridesÚwin_indices_shaper   r	   r   s               r   r   r   `   s  € õ^ �f�bœjÑ)Ô)ð <ÝÐ:Ñ;Ô;Ð;àŒ;€Då�,¥¤Ñ/Ô/ð .Ø$�¨Ñ-ˆÝ�ÑÔ Ò%Ð%ÝÐMÑNÔNÐNå�$�œÑ'Ô'ð Ø�!Š8ˆ8ÝÐ2Ñ3Ô3Ð3Øˆw˜‰~ˆÝ
ˆ4�y„y�DÒÐÝÐEÑFÔFÐFå”˜œÑ&Ô&€IÝ”8˜L°	´Ð@Ñ@Ô@€Là	�\Ñ	! QÒ&×+Ò+Ñ-Ô-ð 8ÝÐ6Ñ7Ô7Ð7à	˜Ñ	˜QÒ×#Ò#Ñ%Ô%ð 8ÝÐ6Ñ7Ô7Ð7õ Ð8Ð8°4Ð8Ñ8Ô8Ñ8Ô8€FÝ”X˜fœnÑ-Ô-€Nà˜f”~Ô-Ðõ 
Œ�&”,Ñ	Ô	¥"¤(¨<Ñ"8Ô"8Ñ	8½R¼XÀd¹^¼^ÑKØ	ñ
Ðõ •dÐ,Ñ-Ô-µ°\Ñ0BÔ0BÑBÑCÔC€IÝ•DÐ)Ñ*Ô*­T°.Ñ-AÔ-AÑAÑBÔB€Gå˜ y¸'ÐBÑBÔB€GØ€Nr   )r   )r%   Únumpyr   Únumpy.lib.stride_tricksr   Ú__all__r   r   © r   r   ú<module>r3      sn   ðØ €€€Ø Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .àÐ.Ð
/€ðUð Uð UðpWð Wð Wð Wð Wð Wr   