
    bi                       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jB                  dd       e e ejD                        d            Z#  ejB                  dd       e e ejH                        d            Z%  ejB                  dd       e e ejL                        d            Z' ee      Z( e(ejN                  ejL                        Z&  ejB                  dd       e e ejR                                    Z* e(ejV                  ejR                        Z,e*jZ                  Be*jZ                  j]                  dd      e*_-        e*jZ                  j]                  dd      e*_-        d  Z+d! Z)e*jZ                  e+_-        e,jZ                  e)_-        y)$    )annotationspartial)productN)curry)array_creation_dispatch)Arraynormalize_chunks)meta_from_array)tokenize)	blockwise)ArrayChunkShapeDep)funcnamec           	        t        |t        j                        r|j                         }t        |t        t
        f      s|f}|j                  dd       }|j                  dd      }|j                  dd       }| | |g|i |j                  }t        j                  |      }t        |||      }|xs 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          J/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/dask/array/wrap.py_parse_wrap_argsr#      s    %$eeT]+::fd#DZZ&)FJJw%E}U,T,V,22HHUOEfe59F 8D>C'(eVUD&+ D
      c           
        d|vr|d   |dd }}n|j                  d      }t        |t              rt        d      t	        | |||      }|d   }|d   }|d   }|d   }|d	   }t        | fd|i|} t        t        t        |                  x}}	t        | ||t        |      |	i 
      }
t        |
||||j                  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   s     f1gtABxt

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

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

648PQQr$   c                <    d   }t        |      }|j                  d|j                        }t         ||      }|d   }|d   |d   }|d   }|d   }t	        |gg|D 	cg c]  }	t        t        |	             c}	 }
t	        | }t        |      }|D cg c]  }| }}t        t        |            D ]  \  }}|||   d<     fdt        ||      D        }t        t        |
|            }t        ||||j                              S c c}	w c c}w )	r&   r   r   r   r   r   r   c              3  H   K   | ]  \  }}t        fd i|fz     yw)r   Nr   ).0ksr!   r   r    s      r"   	<genexpr>z!wrap_func_like.<locals>.<genexpr>i   s,     T&1aWT,,!,.5Ts   ")r)   )r   r.   r   r#   r   r+   r,   r   	enumeratezipdictr	   astype)r    r!   r   xr)   r   r/   r   r   bdkeysshapes_kwir8   valsdskr   s   ``                @r"   wrap_func_likerG   T   s"    	QA1DJJw(EdD&%8F7OE7OEHF&>DHFD6>f=U3r7^=>DfF&\F 	!Q&	!B	!$v,' 11gTCFOTD
s4
CdFU);<< > 
"s   #D
	Dc                    |t        | |fi |}nt        | |fi |}d}|j                  7|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"   wraprP   p   sp    It.v.Iy3F3H ||66E	$--/
Hr$   c                X    |dk(  rdnd}t        j                   | |g|d|i||      S )N r'   r   )r   broadcast_to)r    r   r)   r!   r   
null_shapes         r"   _broadcast_trick_innerrU      s6     {J??4HtH:HH%PPr$   c                `    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.
    )rU   rJ   rK   )r    inners     r"   broadcast_trickrX      s)    & #4(ELLEM]]ENLr$   numpyones)backendr   f8r   zerosempty)rM   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k7  r"t        dt        |      j                   d      |j                  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typerK   r.   hasattrr   _full)r   rc   r!   r   s       r"   r_   r_      s     
wwza24
3C3L3L2MYW
 	
 zz'":w'(..F7O":.F7O$e
EfEEr$   c                    t        j                  |      dk7  r"t        dt        |      j                   d      t        || |d|S )Nr   ra   rb   )arc   )r   rd   re   rf   rK   
_full_like)rj   rc   r!   r   s       r"   	full_likerl      sZ    	wwza24
3C3L3L2MYW
 	
 	
 	 r$   )N)rR   )/
__future__r   	functoolsr   	itertoolsr   rY   r   tlzr   dask.array.backendsr   dask.array.corer	   r
   dask.array.utilsr   	dask.baser   dask.blockwiser   r-   dask.layersr   
dask.utilsr   r#   r3   rG   rP   wrU   rX   register_inplace	ones_likerZ   
zeros_liker]   
empty_liker^   w_likerl   rh   r_   rk   rJ   replacerR   r$   r"   <module>r      s   "     7 3 ,  6 * <!RH=8  & 		%& Q Q2///	 OBLL!.0	000		 OBMM"$/	1	000		 OBMM"$/	1 
n	 BHH6

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