
    |h'                     (    d dl ZddZ G d d      Zy)    Nc                 |   ddl m} t        j                  | j                  t        j
                        st        d      | j                  }| j                  d      } |"t        j                  ||j                        }n+|j                  |k7  rt        d| d|j                   d      	 |j                         }d	|_        |j                  | j                  d      }|j                  |j                  d      } || |||       |S # t        $ r' t        d
|j                   d|j                   d      w xY w)a   Map values from input array from input_vals to output_vals.

    Parameters
    ----------
    input_arr : array of int, shape (M[, ...])
        The input label image.
    input_vals : array of int, shape (K,)
        The values to map from.
    output_vals : array, shape (K,)
        The values to map to.
    out: array, same shape as `input_arr`
        The output array. Will be created if not provided. It should
        have the same dtype as `output_vals`.

    Returns
    -------
    out : array, same shape as `input_arr`
        The array of mapped values.

    Notes
    -----
    If `input_arr` contains values that aren't covered by `input_vals`, they
    are set to 0.

    Examples
    --------
    >>> import numpy as np
    >>> import skimage as ski
    >>> ski.util.map_array(
    ...    input_arr=np.array([[0, 2, 2, 0], [3, 4, 5, 0]]),
    ...    input_vals=np.array([1, 2, 3, 4, 6]),
    ...    output_vals=np.array([6, 7, 8, 9, 10]),
    ... )
    array([[0, 7, 7, 0],
           [8, 9, 0, 0]])
       )
_map_arrayz7The dtype of an array to be remapped should be integer.dtypezbIf out array is provided, it should have the same shape as the input array. Input array has shape z", provided output array has shape .)r   z`If out array is provided, it should be either contiguous or 1-dimensional. Got array with shape z and strides Fcopy)_remapr   np
issubdtyper   integer	TypeErrorshapereshapeempty
ValueErrorviewAttributeErrorstridesastype)	input_arr
input_valsoutput_valsoutr   
orig_shapeout_views          V/var/www/html/test/engine/venv/lib/python3.12/site-packages/skimage/util/_map_array.py	map_arrayr       s9   J #=="**5QRRJ !!"%I
{hhz):):;	j	 66@\ B&&)ii[3
 	


88: ""9??"?J$$SYYU$;Ky(J<J  
669ii[ A{{m1&
 	

s   -D 0D;c                   R    e Zd ZdZd Zd ZddZed        Zd Z	d Z
d	 Zd
 Zd Zy)ArrayMapu  Class designed to mimic mapping by NumPy array indexing.

    This class is designed to replicate the use of NumPy arrays for mapping
    values with indexing:

    >>> values = np.array([0.25, 0.5, 1.0])
    >>> indices = np.array([[0, 0, 1], [2, 2, 1]])
    >>> values[indices]
    array([[0.25, 0.25, 0.5 ],
           [1.  , 1.  , 0.5 ]])

    The issue with this indexing is that you need a very large ``values``
    array if the values in the ``indices`` array are large.

    >>> values = np.array([0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.0])
    >>> indices = np.array([[0, 0, 10], [0, 10, 10]])
    >>> values[indices]
    array([[0.25, 0.25, 1.  ],
           [0.25, 1.  , 1.  ]])

    Using this class, the approach is similar, but there is no need to
    create a large values array:

    >>> in_indices = np.array([0, 10])
    >>> out_values = np.array([0.25, 1.0])
    >>> values = ArrayMap(in_indices, out_values)
    >>> values
    ArrayMap(array([ 0, 10]), array([0.25, 1.  ]))
    >>> print(values)
    ArrayMap:
      0 → 0.25
      10 → 1.0
    >>> indices = np.array([[0, 0, 10], [0, 10, 10]])
    >>> values[indices]
    array([[0.25, 0.25, 1.  ],
           [0.25, 1.  , 1.  ]])

    Parameters
    ----------
    in_values : array of int, shape (K,)
        The source values from which to map.
    out_values : array, shape (K,)
        The destination values from which to map.
    c                 <    || _         || _        d| _        d | _        y )N   )	in_values
out_values_max_str_lines_array)selfr%   r&   s      r   __init__zArrayMap.__init__z   s    "$    c                 F    t        j                  | j                        dz   S )z<Return one more than the maximum label value being remapped.r   )r   maxr%   r)   s    r   __len__zArrayMap.__len__   s    vvdnn%))r+   Nc                     || j                   j                  }t        j                  t        j                  | j
                        dz   |      }| j                   || j
                  <   |S )zReturn an array that behaves like the arraymap when indexed.

        This array can be very large: it is the size of the largest value
        in the ``in_vals`` array, plus one.
        r   r   )r&   r   r   zerosr-   r%   )r)   r   r   outputs       r   	__array__zArrayMap.__array__   sQ     =OO))E"&&014EB!%t~~r+   c                 .    | j                   j                  S N)r&   r   r.   s    r   r   zArrayMap.dtype   s    $$$r+   c                 `    dt        | j                         dt        | j                         dS )Nz	ArrayMap(z, ))reprr%   r&   r.   s    r   __repr__zArrayMap.__repr__   s+    4/043H2IKKr+   c                    t        | j                        | j                  dz   k  rct        t        | j                              }dj	                  dg|D cg c]$  }d| j                  |    d| j
                  |    & c}z         }|S t        t        d| j                  dz              }t        t        | j                   dz  d            }dj	                  dg|D cg c]$  }d| j                  |    d| j
                  |    & c}z   dgz   |D cg c]$  }d| j                  |    d| j
                  |    & c}z         }|S c c}w c c}w c c}w )	Nr   
z	ArrayMap:z  u    → r      z  ...)lenr%   r'   rangejoinr&   list)r)   rowsistringrows0rows1s         r   __str__zArrayMap.__str__   s^   t~~$"5"5"99T^^,-DYYNRSRq)*%0B/CDSTF  q$"5"5":;<E 3 33q8!<=EYYNSTRq)*%0B/CDTU) OTTRq)*%0B/CDTUF  T UTs   )E
)E
)E
c                 $    | j                  |      S r5   )__getitem__)r)   arrs     r   __call__zArrayMap.__call__   s    $$r+   c                    t        j                  |      }|rt        j                  |g      }nft        |t              rV|j
                  xs d}|j                  |j                  n
t        |       }|j                  }t        j                  |||      }|j                  t        k(  rt        j                  |      }t        || j                  j                  |j                  d      | j                         }|r|d   }|S )Nr   Fr
   )r   isscalararray
isinstanceslicestartstopr=   steparanger   boolflatnonzeror    r%   r   r&   )r)   indexscalarrP   rQ   rR   r   s          r   rH   zArrayMap.__getitem__   s    U#HHeW%Eu%KK$1E!&!75::SYD::DIIeT40E;;$NN5)ENN!!%++E!:OO
 a&C
r+   c                     | j                   | j                         | _         || j                   |<   t        j                  | j                         | _        | j                   | j                     | _        y r5   )r(   r3   r   rU   r%   r&   )r)   indicesvaluess      r   __setitem__zArrayMap.__setitem__   sP    ;;..*DK%G4++dnn5r+   )NN)__name__
__module____qualname____doc__r*   r/   r3   propertyr   r9   rF   rJ   rH   r[    r+   r   r"   r"   L   sE    +Z*
 % %L$%,6r+   r"   r5   )numpyr   r    r"   ra   r+   r   <module>rc      s    EP{6 {6r+   