
    Cd                       d dl mZ d dlmZ d dlmZ d dlZd dlm	Z	 d dl
mZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d Zd Zd Ze	d#d            Z ee          Ze	d$d            Zd Z   ej!        dd           e e ej"                  d                    Z#  ej!        dd           e e ej$                  d                    Z%  ej!        dd           e e ej&                  d                    Z' ee          Z( e(ej'        ej&                  Z&  ej!        dd           e e ej)                                      Z* e(ej+        ej)                  Z,e*j-        @e*j-        .                    dd          e*_-        e*j-        .                    dd           e*_-        d! Z+d" Z)e*j-        e+_-        e,j-        e)_-        dS )%    )annotationspartial)productN)curry)array_creation_dispatch)Arraynormalize_chunks)meta_from_array)tokenize)	blockwise)ArrayChunkShapeDep)funcnamec           	        t          |t          j                  r|                                }t          |t          t
          f          s|f}|                    dd           }|                    dd          }|                    dd           }| | |g|R i |j        }t          j        |          }t          |||          }|p&t          |           dz   t          | |||||          z   }|||||dS )Nnamechunksautodtyper   -)shaper   kwargsr   r   )
isinstancenpndarraytolisttuplelistpopr   r
   r   r   )funcargsr   r   r   r   r   s          /lib/python3.11/site-packages/dask/array/wrap.py_parse_wrap_argsr#      s   %$$ eeT]++ ::fd##DZZ&))FJJw%%E}U,T,,,V,,2HUOOEfe5999F 8D>>C'(eVUD&+ + D
       c           
        d|vr|d         |dd         }}n|                     d          }t          |t                    rt          d          t	          | |||          }|d         }|d         }|d         }|d         }|d	         }t          | fd|i|} t          t          t          |                              x}}	t          | ||t          |          |	i 
          }
t          |
||||                    dd                    S )=
    Transform np creation function into blocked version
    r   r      NzTDask array input not supported. Please use tuple, list, or a 1D numpy array instead.r   r   r   r   )	numblocksmeta)r   r)   )r   r   r	   	TypeErrorr#   r   r   rangelencore_blockwiser   get)r    r!   r   r   parsedr   r   r   out_inddep_indgraphs              r"   wrap_func_shape_as_first_argr3   0   s6    f1gtABBxt

7##% 
C
 
 	

 dD&%88F7OE7OEHF&>DHF4//u///DeCJJ//000Gg6""  E fE

648P8PQQQQr$   c                z    d         }t          |          }                    d|j                  }t           |          }|d         }|d         |d         }|d         }|d         t	          |ggd |D             R  }	t	          | }
t          |
          }
fd|
D             }t          t          |
                    D ]\  }}|||         d<    fd	t          ||
          D             }t          t          |	|                    }t          ||||
                              
          S )r&   r   r   r   r   r   r   c                F    g | ]}t          t          |                    S  )r+   r,   ).0bds     r"   
<listcomp>z"wrap_func_like.<locals>.<listcomp>c   s$    ===U3r77^^===r$   c                    g | ]}S r6   r6   )r7   _r   s     r"   r9   z"wrap_func_like.<locals>.<listcomp>f   s    	!	!	!Q&	!	!	!r$   c              3  D   K   | ]\  }}t          fd i|fz   V  dS )r   Nr   )r7   ksr!   r   r    s      r"   	<genexpr>z!wrap_func_like.<locals>.<genexpr>i   sD      TT&1aWT,,,!,,.5TTTTTTr$   )r)   )r   r.   r   r#   r   r   	enumeratezipdictr	   astype)r    r!   r   xr)   r   r/   r   r   keysshapeskwir>   valsdskr   s   ```             @r"   wrap_func_likerK   T   sX    	QA1DJJw((EdD&%88F7OE7OEHF&>DHFD6>==f===>>>DfF&\\F	!	!	!	!&	!	!	!B$v,,''  11gTTTTTTCFOOTTTD
s4

CdFU););<<<<r$   c                    |t          | |fi |}nt          | |fi |}d}|j        (|d|j        iz  |j        z   |_        d|j        z   |_        |S )Nz
    Blocked variant of %(name)s

    Follows the signature of %(name)s exactly except that it also features
    optional keyword arguments ``chunks: int, tuple, or dict`` and ``name: str``.

    Original signature follows below.
    r   blocked_)r   __doc____name__)	wrap_funcr    	func_liker   ftemplates         r"   wraprT   p   sv    It..v..Iy33F33H |66E	$-/
Hr$   r6   c                X    |dk    rdnd}t          j         | |g|R d|i||          S )Nr6   r'   r   )r   broadcast_to)r    r   r)   r!   r   
null_shapes         r"   _broadcast_trick_innerrX      sF     {{J?44HtHHH:HHH%PPPr$   c                T    t          |           }| j        |_        | j        |_        |S )a  
    Provide a decorator to wrap common numpy function with a broadcast trick.

    Dask arrays are currently immutable; thus when we know an array is uniform,
    we can replace the actual data by a single value and have all elements point
    to it, thus reducing the size.

    >>> x = np.broadcast_to(1, (100,100,100))
    >>> x.base.nbytes
    8

    Those array are not only more efficient locally, but dask serialisation is
    aware of the _real_ size of those array and thus can send them around
    efficiently and schedule accordingly.

    Note that those array are read-only and numpy will refuse to assign to them,
    so should be safe.
    )rX   rN   rO   )r    inners     r"   broadcast_trickr[      s(    & #4((ELEM]ENLr$   numpyones)backendr   f8r   zerosempty)rQ   fullz*array([0.1,  0.1,  0.1,  0.1,  0.1,  0.1])z%array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1])z >>> np.full_like(y, [0, 0, 255])zB>>> np.full_like(y, [0, 0, 255])  # doctest: +NORMALIZE_WHITESPACEc                    t          j        |          dk    r%t          dt          |          j         d          |                    dd           -t          |d          r|j        |d<   nt          |          |d<   t          || |d|S )Nr   $fill_value must be scalar. Received 	 instead.r   )r   
fill_value)	r   ndim
ValueErrortyperO   r.   hasattrr   _full)r   rf   r!   r   s       r"   rb   rb      s     
wzaW4
3C3C3LWWW
 
 	
 zz'4  (:w'' 	/(.F7OO":..F7O$e
EEfEEEr$   c                    t          j        |          dk    r%t          dt          |          j         d          t          || |d|S )Nr   rd   re   )arf   )r   rg   rh   ri   rO   
_full_like)rm   rf   r!   r   s       r"   	full_likero      sn    	wzaW4
3C3C3LWWW
 
 	
 	
  	  r$   )N)r6   )/
__future__r   	functoolsr   	itertoolsr   r\   r   tlzr   dask.array.backendsr   dask.array.corer	   r
   dask.array.utilsr   	dask.baser   dask.blockwiser   r-   dask.layersr   
dask.utilsr   r#   r3   rK   rT   wrX   r[   register_inplace	ones_liker]   
zeros_liker`   
empty_likera   w_likero   rk   rb   rn   rN   replacer6   r$   r"   <module>r      sv   " " " " " "                       7 7 7 7 7 7 3 3 3 3 3 3 3 3 , , , , , ,       6 6 6 6 6 6 * * * * * *        <!R !R !RH= = =8    & 	D	%&& Q Q Q Q  2//	   !OOBL!!...0 0	00		 	 	 !OOBM""$///	1 	1	00		 	 	 !OOBM""$///	1 	1 
n		 VBH666

	00		 	 	 !OOBL!!""	$ 	$ VBGr|444
 	=M))4/ EM M))*L EMF F F
 
 
 }&	   r$   