
    1-Ph'                     0    d dl ZddZ G d d          ZdS )    Nc                 Z   ddl m} t          j        | j        t          j                  st          d          | j        }|                     d          } |t          j	        ||j                  }n&|j        |k    rt          d| d|j         d	          	 |                                }d
|_        n.# t          $ r! t          d|j         d|j         d	          w xY w|                    | j        d          }|                    |j        d          } || |||           |S )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.N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          W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/util/_map_array.py	map_arrayr       s   J #"""""="*55 SQRRRJ !!"%%I
{hz):;;;	j	 	 36@3 3&)i3 3 3
 
 	


88:: 
 
 
&69i& &{& & &
 
 	

 ""9?"??J$$SYU$;;KJy(J<<<Js   B7 7+C"c                   Z    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dS )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 | _        d S )N   )	in_values
out_values_max_str_lines_array)selfr%   r&   s      r   __init__zArrayMap.__init__z   s#    "$    c                 :    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    vdn%%))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.
        Nr   r   )r&   r   r   zerosr-   r%   )r)   r   r   outputs       r   	__array__zArrayMap.__array__   sK     =O)E"&0014EBB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/    K4//KK43H3HKKKKr+   c                     t           j                   j        dz   k    rGt          t           j                            }d                    dg fd|D             z             }nt          t          d j        dz                      }t          t           j         dz  d                    }d                    dg fd|D             z   dgz    fd	|D             z             }|S )
Nr   
z	ArrayMap:c                 L    g | ] }d j         |          dj        |          !S z  u    → r%   r&   .0ir)   s     r   
<listcomp>z$ArrayMap.__str__.<locals>.<listcomp>   s8    SSSDq)DD0BDDSSSr+   r      c                 L    g | ] }d j         |          dj        |          !S r=   r>   r?   s     r   rB   z$ArrayMap.__str__.<locals>.<listcomp>   8    TTTDq)DD0BDDTTTr+   z  ...c                 L    g | ] }d j         |          dj        |          !S r=   r>   r?   s     r   rB   z$ArrayMap.__str__.<locals>.<listcomp>   rE   r+   )lenr%   r'   rangejoinlist)r)   rowsstringrows0rows1s   `    r   __str__zArrayMap.__str__   s   t~$"5"999T^,,--DYYSSSSdSSST FF
 q$"5":;;<<E 33q8!<<==EYYTTTTeTTTU) UTTTeTTTU F r+   c                 ,    |                      |          S r5   )__getitem__)r)   arrs     r   __call__zArrayMap.__call__   s    $$$r+   c                    t          j        |          }|rt          j        |g          }nXt          |t                    rC|j        pd}|j        |j        nt          |           }|j        }t          j	        |||          }|j
        t          k    rt          j        |          }t          || j                            |j
        d          | j                  }|r|d         }|S )Nr   Fr
   )r   isscalararray
isinstanceslicestartstoprG   steparanger   boolflatnonzeror    r%   r   r&   )r)   indexscalarrY   rZ   r[   r   s          r   rQ   zArrayMap.__getitem__   s    U## 	1HeW%%EEu%% 	1K$1E!&!75::SYYD:DIeT400E;$N5))EN!!%+E!::O
 
  	a&C
r+   c                     | j         |                                 | _         || j         |<   t          j        | j                   | _        | j         | j                 | _        d S r5   )r(   r3   r   r^   r%   r&   )r)   indicesvaluess      r   __setitem__zArrayMap.__setitem__   sN    ;..**DK%G44+dn5r+   )NN)__name__
__module____qualname____doc__r*   r/   r3   propertyr   r9   rO   rS   rQ   rd    r+   r   r"   r"   L   s        + +Z  * * *
 
 
 
 % % X%L L L  $% % %  ,6 6 6 6 6r+   r"   r5   )numpyr   r    r"   rj   r+   r   <module>rl      sf       E E E EP{6 {6 {6 {6 {6 {6 {6 {6 {6 {6r+   