
    9i'                     *    S SK rSS jr " S S5      rg)    Nc                 x   SSK Jn  [        R                  " U R                  [        R
                  5      (       d  [        S5      eU R                  nU R                  S5      n Uc  [        R                  " XRR                  S9nO,UR                  U:w  a  [        SU SUR                   S35      e UR                  5       nS	Ul        UR                  U R                  SS9nUR                  UR                  SS9nU" XX5        U$ ! [         a'    [        S
UR                   SUR                   S35      ef = f)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          W/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/util/_map_array.py	map_arrayr       s6   J #=="**55QRRJ !!"%I
{hhz):):;	j	 66@\ B&&)ii[3
 	


88: ""9??"?J$$SYYU$;KyJ<J  
669ii[ A{{m1&
 	

s   2D 1D9c                   \    \ rS rSrSrS rS rSS jr\S 5       r	S r
S	 rS
 rS rS rSrg)ArrayMapL   u  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                 8    Xl         X l        SU l        S U l        g )N   )	in_values
out_values_max_str_lines_array)selfr&   r'   s      r   __init__ArrayMap.__init__z   s    "$    c                 H    [         R                  " U R                  5      S-   $ )z<Return one more than the maximum label value being remapped.r   )r   maxr&   r*   s    r   __len__ArrayMap.__len__   s    vvdnn%))r-   Nc                     Uc  U R                   R                  n[        R                  " [        R                  " U R
                  5      S-   US9nU R                   X0R
                  '   U$ )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__ArrayMap.__array__   sO     =OO))E"&&014EB!%~~r-   c                 .    U R                   R                  $ N)r'   r   r0   s    r   r   ArrayMap.dtype   s    $$$r-   c                 `    S[        U R                  5       S[        U R                  5       S3$ )Nz	ArrayMap(z, ))reprr&   r'   r0   s    r   __repr__ArrayMap.__repr__   s+    4/043H2IKKr-   c                    [        U R                  5      U R                  S-   ::  af  [        [        U R                  5      5      nSR	                  S/U Vs/ s H%  nSU R                  U    SU R
                  U    3PM'     sn-   5      nU$ [        [        SU R                  S-  5      5      n[        [        U R                  * S-  S5      5      nSR	                  S/U Vs/ s H%  nSU R                  U    SU R
                  U    3PM'     sn-   S/-   U Vs/ s H%  nSU R                  U    SU R
                  U    3PM'     sn-   5      nU$ s  snf s  snf s  snf )	Nr   
z	ArrayMap:z  u    → r      z  ...)lenr&   r(   rangejoinr'   list)r*   rowsistringrows0rows1s         r   __str__ArrayMap.__str__   sj   t~~$"5"5"99T^^,-DYYNRSdRq)*%0B/CDdSTF  q$"5"5":;<E 3 33q8!<=EYYNSTeRq)*%0B/CDeTU) OTTeRq)*%0B/CDeTUF  T UTs   ,E
#,E
,E
c                 $    U R                  U5      $ r9   )__getitem__)r*   arrs     r   __call__ArrayMap.__call__   s    $$r-   c                 0   [         R                  " U5      nU(       a  [         R                  " U/5      nOq[        U[        5      (       a\  UR
                  =(       d    SnUR                  b  UR                  O
[        U 5      nUR                  n[         R                  " X4U5      nUR                  [        :X  a  [         R                  " U5      n[        UU R                  R                  UR                  SS9U R                   5      nU(       a  US   nU$ )Nr   Fr
   )r   isscalararray
isinstanceslicestartstoprC   steparanger   boolflatnonzeror    r&   r   r'   )r*   indexscalarrX   rY   rZ   r   s          r   rO   ArrayMap.__getitem__   s    U#HHeW%Eu%%KK$1E!&!75::SYD::DIIe40E;;$NN5)ENN!!%++E!:OO
 a&C
r-   c                     U R                   c  U R                  5       U l         X R                   U'   [        R                  " U R                   5      U l        U R                   U R                     U l        g r9   )r)   r6   r   r]   r&   r'   )r*   indicesvaluess      r   __setitem__ArrayMap.__setitem__   sN    ;;..*DK%G4++dnn5r-   )r)   r(   r&   r'   )NN)__name__
__module____qualname____firstlineno____doc__r+   r1   r6   propertyr   r>   rL   rQ   rO   rd   __static_attributes__ r-   r   r"   r"   L   sE    +Z*
 % %L$%,6r-   r"   r9   )numpyr   r    r"   rm   r-   r   <module>ro      s    EP{6 {6r-   