o
    Nrfͺ                     @  s  d dl mZ d dlZd dlZd dlmZ d dlZd dlZd dlm	Z	 d dl
mZ d dlmZ d dlmZmZmZmZmZmZmZ d dlmZmZ d d	lmZmZ d
d Zejdd Zdd Zdd Z dd Z!dd Z"dd Z#dd Z$dd Z%dd Z&dd Z'd d! Z(d"d# Z)d$d% Z*d&d' Z+d(d) Z,d*d+ Z-d,d- Z.d.d/ Z/d0d1 Z0d2d3 Z1dGd5d6Z2d7d8 Z3d9d: Z4d;d< Z5d=d> Z6d?d@ Z7dAdB Z8dCdD Z9dEdF Z:dS )H    )annotationsN)partial)tokenizeget_dependencies)get_sync)SubgraphCallablecullfunctions_offusefuse_linearinlineinline_functions)applypartial_by_order)addincc                 C  sD   t | t |u o!| j|jko!t| jt|jko!t| jt|jkS N)typeZoutkeysetinkeysr   dsk)selfother r   e/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/dask/tests/test_optimization.py_subgraph_callables_eq   s   
r   c                 C  s   |  tdt dS )a  Ignore name when comparing instances of :class:`SubgraphCallable`.

    They have UUID-generated names which prevents instances generated by the
    test from comparing equal to reference values. Instead, compare the
    embedded graph using ``tokenize``.
    __eq__N)setattrr   r   )Zmonkeypatchr   r   r   compare_subgraph_callables#   s   r   c                 C  s   | d S )N   r   xr   r   r   double.      r#   c                    s   dt dft dftddfd t d\} }| dt dftddfdks$J |g dgdgdks0J t dt dgks=J t ddgd	  ksJJ t dgdggt ddgks\J tt fd
d d S )N   r"   y
   )r"   r&   zoutr)   )r"   r&   r)   r(   r   c                     s
   t  dS )NZbadkey)r	   r   dr   r   <lambda><   s   
 ztest_cull.<locals>.<lambda>)r   r   r	   pytestZraisesKeyError)Zculleddependenciesr   r*   r   	test_cull2   s   $r0   c                  O  s>   t | i |}|ddur|S t| i |}||ksJ |S )z9Run both ``fuse`` and ``fuse_linear`` and compare resultsrename_keysF)r   getr   )argskwargsZrv1Zrv2r   r   r   fuse2?   s   r5   c                   s     fdd D fS )Nc                   s   i | ]}|t  |qS r   r   ).0kr   r   r   
<dictcomp>J   s    zwith_deps.<locals>.<dictcomp>r   r8   r   r8   r   	with_depsI   s   r:   c                  C  s  t } tdftdftdftddfddd}| |d	d
tttttddffffdddks-J | |dd
tttttddffffddddksGJ tdftdftdftdftddfddd}| |d	d
ttdfttdffttddffdddksyJ | |dd
ttdfttdffttddffdddddksJ tdftdftdftdftdftddftdftdfddd
}| |d	d
ttttdffftdfttddfftdftdfdksJ | |dd
ttttdffftdfttddfftdftdfddddd	ksJ tdftdftdftdftdfdd}| |d	d
ttdftdfttdfftdfdks0J | |dd
ttd ftd fttd fftdfd!d d"ksNJ dtdftddfd#}| |d	d
ttdftddfd$ksnJ | |dd
ttdftd%d%fd%d&ksJ d S )'Nr"   r&   r(   abr%   r    wr"   r&   r(   r;   r<   Fr1   )r>   r;   r<   Tz-y-x-w)r@   r;   r<   r>   )NEWr>   r"   r&   r(   r;   r<   )rA   r>   r&   r;   r<   z-yx-w)rA   rC   rB   r;   r<   r>   r&   r>   cr+   )
vur>   r"   r&   r(   r;   r<   rD   r+   )rF   rE   r&   r;   r<   c-ad-bx-w-u)	rI   rE   rB   rG   rH   r;   r<   rF   r&   r   )r;   r<   rD   r+   r"   r&   )r;   r<   r+   r"   y-xc-d)r;   r<   rK   rJ   r+   r"   r;   r<   rD   r<   rD   a-brN   rD   r<   )r5   r   r   r:   )r   r+   r   r   r   	test_fuseM   s   


	

	


	 
rP   c               	   C  s  t } dtdftdfd}dg}| ||ddttdftdfdks#J | ||ddttdftd	fd	d
ks8J tdftdftdftddfddd}ddg}| ||ddttdfttdfftddfdddksjJ | ||ddttdfttdfftddfddddksJ d S )Nr%   r;   r<   rL   Fr?   rM   TrN   rO   r"   r&   r(   r    r=   )r>   r"   r(   r;   r<   rJ   )r>   rJ   r(   r;   r<   r"   )r5   r   r:   r   )r   r+   keysr   r   r   test_fuse_keys   s:   

 

rR   c                    sz   d  fdd} d| dft ddftdfd}t dhdhdhd}t|dd	g|d
d }ddlm} ||d	dks;J d S )NFc                   s    rt d | d S )NTr%   )RuntimeErrorr!   Zalready_calledr   r   inc_only_once   s   zDtest_donot_substitute_same_key_multiple_times.<locals>.inc_only_once*   ABC)rW   rX   rY   DrZ   )rQ   r/   r   )r2   r%   )r   r   r   r   	dask.corer2   )rU   r   r/   Z	fused_dskr2   r   rT   r   -test_donot_substitute_same_key_multiple_times   s"   r\   c               	   C  s  dt dft dftddfd} t| dt dft dftddfdks"J t| g ddt dft t dfftdt t dfffdks?J dt dftddfd	} t| dt dftddfd	ks[J t| dd
dt dftdt dffd	kspJ t| ddddt dftdt dffd	ksJ dddg dttdfdfd} t| ddddg dttg dfdfdksJ t| ddddddg dttdfdfdksJ d S )Nr%   r;   r<   rD   r;   r<   rD   r+   rL   r"   r&   )r"   r&   r(   )rQ   F)rQ   inline_constantsr+   r;   r<   rD   r+   e)r%   r%   r%   )r^   )r%   r<   rD   )r   r   r   lenr*   r   r   r   test_inline  s>   (
"*rb   c               
   C  st   d\} }}}dt ||f|t| f|t|f| d|di}t|g thd}dt t| f|f|t|f| d|di}||ks8J d S NZxyidr)   r%   Zfast_functions)r   r   r#   r   )r"   r&   ir+   r   resultexpectedr   r   r   test_inline_functions3  s
   &"rh   c                  C  sT   ddt tddftdfd} t| g thd}|d t| d fks"J d|vs(J d S )Nr%   r    r"   r;   )r"   r&   r;   r<   rd   r<   )r   r   r   r   r   rf   r   r   r   (test_inline_ignores_curries_and_partials<  s   rj   c                  C  sf   G dd d} |  }dt df|dft dfd}t|g t hd}|d ||d fks+J d|vs1J d S )	Nc                   @  s   e Zd Zdd Zdd ZdS )z?test_inline_functions_non_hashable.<locals>.NonHashableCallablec                 S  s   |d S )Nr%   r   )r   r;   r   r   r   __call__F  r$   zHtest_inline_functions_non_hashable.<locals>.NonHashableCallable.__call__c                 S  s   t d)NzNot hashable)	TypeError)r   r   r   r   __hash__I  r$   zHtest_inline_functions_non_hashable.<locals>.NonHashableCallable.__hash__N)__name__
__module____qualname__rk   rm   r   r   r   r   NonHashableCallableE  s    rq   r%   r;   r<   rD   r]   rd   r   r   )rq   Znohashr   rf   r   r   r   "test_inline_functions_non_hashableD  s   rs   c                  C  s.   t dfdd} t| g t hd}|| ksJ d S )Nr&   r%   r"   r&   rd   rr   ri   r   r   r   /test_inline_doesnt_shrink_fast_functions_at_topU  s   ru   c               
   C  sx   d\} }}}dt ||gf|t| f|t|f| d|di}dt t| f|gf|t|f| d|di}t|g thd}||ks:J d S rc   )sumr   r#   r   )r"   r&   re   r+   r   rg   rf   r   r   r   test_inline_traverses_lists[  s
   ($rw   c                  C  s^   t dftdfd} t| g t gdtt dffiksJ t| dgt gtdft dfdks-J d S )Nr%   r"   rt   r&   )r&   r"   )r   r#   r   r8   r   r   r   *test_inline_functions_protects_output_keysc  s   "*rx   c                  C  s   dd } dd }t | df| hksJ t | |dff| |hks!J t | |dfgf| |hks0J t | |dfgggf| |hksAJ t dt ksJJ t | t ksSJ t | f| hks]J d S )Nc                 S     | S r   r   r!   r   r   r   r,   j      z#test_functions_of.<locals>.<lambda>c                 S  ry   r   r   r!   r   r   r   r,   k  rz   r%   )r
   r   r;   r<   r   r   r   test_functions_ofi  s   "r|   c                  C  sD   dddg dt tdfdfd} t| ddg\}}t|dh|d d S )	Nr%   r;   r<   rL   r+   r_   r`   r/   )r   ra   r	   r   )r+   d2r/   r   r   r   test_inline_cull_dependenciesu  s   r   c                  C  s  dd } d| df| ddf| ddfd}t |dd	d
t|ks J t |ddd
t|ks-J t |dd	d
td| | df| ddffdksEJ t |ddd
td| | df| ddffddks^J d| df| ddf| dddf| dddfd}t |dd	d
t|ksJ t |ddd
t|ksJ t |dd	d
td| | df| ddf| dddffdksJ t |ddd
td| | df| ddf| dddffddksJ d| df| df| dddfd}t |dd	d
t|ksJ t |ddd
t|ksJ t |dd	d
td| d| df| dffdks
J t |ddd
td| d| df| dffddks$J d| df| df| ddf| df| df| ddfd}t |dd	d
t|ksJJ t |ddd
t|ksXJ t |dd	d
td| | df| dff| | df| dffdksxJ t |ddd
td| | df| dff| | df| dffdddksJ d| df| df| df| df| ddf| ddf| ddfd }t |dd	d
t|ksJ t |ddd
t|ksJ td| | df| dff| | df| dff| ddfd!}t |dd	d
|ksJ t |dd	d
|ksJ td| | df| dff| | df| dff| ddfd"d#d$}t |ddd
|ks,J t |ddd
|ks8J t |dd	d
td| | | df| dff| | df| dfffd%ksZJ t |ddd
td| | | df| dff| | df| dfffd&d'ks}J i ddd| dfd| dfd| dfd| dfd(| dfd)| dfd*| dfd+| dfd| ddfd| ddfd,| d(d)fd-| d*d+fd| ddfd| d,d-fd.| ddf}t |dd	d
t|ksJ t |ddd
t|ksJ td| | df| dff| | df| dff| | df| dff| | df| dff| ddf| d,d-f| ddfd/}t |dd	d
|ks.J t |dd	d
|ks:J td| | df| dff| | df| dff| | df| dff| | df| dff| ddf| d,d-f| ddfd"d#d0d1d2}t |ddd
|ks|J t |ddd
|ksJ td| | | df| dff| | df| dfff| | | df| dff| | df| dfff| ddfd3}t |dd	d
|ksJ t |d4d	d
|ksJ td| | | df| dff| | df| dfff| | | df| dff| | df| dfff| ddfd5d6d7}t |ddd
|ks
J t |d4dd
|ksJ t |d8d	d
td| | | | df| dff| | df| dfff| | | df| dff| | df| dffffd9ksLJ t |d8dd
td| | | | df| dff| | df| dfff| | | df| dff| | df| dffffd:d;ksJ i ddd| dfd| dfd| dfd| dfd(| dfd)| dfd*| dfd+| dfd<| dfd=| dfd>| dfd?| dfd@| dfdA| dfdB| dfdC| df| ddf| ddf| d(d)f| d*d+f| d<d=f| d>d?f| d@dAf| dBdCf| ddf| d,d-f| dDdEf| dFdGf| ddf| dHdIf| dJdKfdL}t |dd	d
t|ks%J t |ddd
t|ks3J ti ddd| | df| dffd| | df| dffd,| | df| dffd-| | df| dffdD| | df| dffdE| | df| dffdF| | df| dffdG| | df| dffd| ddfd| d,d-fdH| dDdEfdI| dFdGfdJ| ddfdK| dHdIfdM| dJdKf}t |dd	d
|ksJ t |dd	d
|ksJ ti ddd"| | df| dffd#| | df| dffd0| | df| dffd1| | df| dffdN| | df| dffdO| | df| dffdP| | df| dffdQ| | df| dffd| ddfd| d,d-fdH| dDdEfdI| dFdGfdJ| ddfdK| dHdIfdM| dJdKfdd"d#d0d1dNdOdPdQdR}t |ddd
|ksfJ t |ddd
|ksrJ td| | | df| dff| | df| dfff| | | df| dff| | df| dfff| | | df| dff| | df| dfff| | | df| dff| | df| dfff| ddf| dHdIf| dJdKfdS}t |dd	d
|ksJ t |d4d	d
|ksJ td| | | df| dff| | df| dfff| | | df| dff| | df| dfff| | | df| dff| | df| dfff| | | df| dff| | df| dfff| ddf| dHdIf| dJdKfd5d6dTdUdV}t |ddd
|ksNJ t |d4dd
|ksZJ td| | | | df| dff| | df| dfff| | | df| dff| | df| dffff| | | | df| dff| | df| dfff| | | df| dff| | df| dffff| dJdKfdW}t |d8d	d
|ksJ t |dXd	d
|ksJ td| | | | df| dff| | df| dfff| | | df| dff| | df| dffff| | | | df| dff| | df| dfff| | | df| dff| | df| dffff| dJdKfdYdZd[}t |d8dd
|ks,J t |dXdd
|ks8J t |d\d	d
td| | | | | df| dff| | df| dfff| | | df| dff| | df| dffff| | | | df| dff| | df| dfff| | | df| dff| | df| dfffffd]ksJ t |d\dd
td| | | | | df| dff| | df| dfff| | | df| dff| | df| dffff| | | | df| dff| | df| dfff| | | df| dff| | df| dfffffd^d_ksJ d| dfd`}t |dd	d
tda| dfik	sJ t |ddd
t| dfdbdck	s!J d| df| daf| dfdd}t |dd	d
tde| | | dfffik	sDJ t |ddd
t| | | dfffdfdgk	s[J d| df| ddaf| ddfdd}t |dd	d
td| d| d| dfffd%k	sJ t |ddd
td| d| d| dfffdhdik	sJ d| df| df| df| df| df| dJdfdj}td| df| | | | dffff| dJdfdk}t |dd	d
|k	sJ t |dd	d
|k	sJ td| df| | | | dffff| dJdfdldm}t |ddd
|k
sJ t |ddd
|k
sJ t |dd	d
td| | | | | dffff| dffd]k
s/J t |ddd
td| | | | | dffff| dffdndok
sNJ d| df| df| ddf| ddf| ddf| ddJdfdj}td| df| d| d| d| dffff| ddJdfdk}t |dd	d
|k
sJ t |dd	d
|k
sJ td| df| d| d| d| dffff| ddJdfdldm}t |ddd
|k
sJ t |ddd
|k
sJ t |dd	d
td| d| d| d| d| dffff| dffd]k
sJ t |ddd
td| d| d| d| d| dffff| dffdndoksJ d| df| df| df| df| df| df| df| df| d,f| dddHf| d.f| dMfdp}t |dd	d
td| | | dfff| | | dfff| | | dfff| | | dddHfffdqkskJ t |ddd
td| | | dfff| | | dfff| | | dfff| | | dddHfffdrdsdtdudv	ksJ d| df| daf| dadf| def| d.f| dedMfdw}t |dd	d
t| df| da| daff| de| | defffdxksJ t |ddd
t| df| da| daff| de| | defffdbdydudzksJ d S ){Nc                  W  ry   r   r   r3   r   r   r   f}     z,test_fuse_reductions_single_input.<locals>.fr%   r;   b1b2)r;   r   r   rD   gffffff?F	ave_widthr1   Tr    )r;   rD   b1-b2-c)r;   r   rD   b3)r;   r   r   r   rD   333333@   
b1-b2-b3-c)r;   r   rD   rD   d1r~   )r;   r   r   rD   r   r~   r`   )r;   rD   r`   d1-d2-e)r;   r   r   rD   r`   b4c1c2)r;   r   r   r   r   r   r   r+   )r;   r   r   r+   b1-b2-c1b3-b4-c2)r;   r   r   r+   r   r   )r;   r+   b1-b2-b3-b4-c1-c2-d)r;   r   r+   Zb5Zb6Zb7Zb8c3c4r`   )r;   r   r   r   r   r   r~   r`   b5-b6-c3b7-b8-c4)r;   r   r   r   r   r   r~   r`   r   r   r   r   )r;   r   r~   r`   gffffff@b1-b2-b3-b4-c1-c2-d1b5-b6-b7-b8-c3-c4-d2)r;   r   r   r`   r   r~   g@)r;   r`   +b1-b2-b3-b4-b5-b6-b7-b8-c1-c2-c3-c4-d1-d2-e)r;   r   r`   Zb9Zb10Zb11Zb12Zb13Zb14Zb15Zb16c5c6c7c8d3d4e1e2)r   r   r   r   r   r   r   r   r   r~   r   r   r   r   r   r   z	b10-b9-c5z
b11-b12-c6z
b13-b14-c7z
b15-b16-c8)r   r   r   r   r   r   r   )r;   r   r~   r   r   r   r   r   b10-b11-b12-b9-c5-c6-d3b13-b14-b15-b16-c7-c8-d4)r;   r   r   r   r   r   r   r   r   r~   r   r   )r;   r   r   r   g@,b1-b2-b3-b4-b5-b6-b7-b8-c1-c2-c3-c4-d1-d2-e13b10-b11-b12-b13-b14-b15-b16-b9-c5-c6-c7-c8-d3-d4-e2)r;   r   r   r   r   r   g      @)r;   r   bb1-b10-b11-b12-b13-b14-b15-b16-b2-b3-b4-b5-b6-b7-b8-b9-c1-c2-c3-c4-c5-c6-c7-c8-d1-d2-d3-d4-e1-e2-f)r;   r   r   r{   r<   rN   )rN   r<   r]   r+   a-b-c-d)r   r+   b-c-d)r;   r   r+   )r;   r   r   r   r   r   r   )r;   r   r   r   b1-c1-d1-e1)r;   r   r   r   r   b1-b2-c1-d1-e1-f)r;   r   r   )r;   r   r   r   r   r   r   r   r~   r   r`   r   g)r;   r   r~   r   r   b1-c1-d1b2-c2-d2b3-c3-d3e-f-g)	r;   r   r   r   r   r   r~   r   r   )r;   r<   rD   r+   r`   r   r   )r<   r+   r   rK   )rN   rK   r   r<   r+   r   r   r:   r   r+   rg   r   r   r   !test_fuse_reductions_single_input|  s  



"

	&

*	







$$$$
$$	
"	







	







$$$$ $$$$$$$$$$$$$$$$$,	&	"	
	

	*
		&r   c                  C  s   dd } d| df| df| dt ddd t ddd ffd	| | d
| dgfff| ddf| dt ddd t ddd ff| df| df| dt ddd t ddd ff| ddf| dfd}h d}t||ddd}|t|d ksiJ d S )Nc                  W  ry   r   r   r   r   r   r   r     r   ztest_fuse_stressed.<locals>.fr%   )cholesky-26a6b670a8aabb7e2f8936db7ccb6a88r   r   /cholesky-upper-26a6b670a8aabb7e2f8936db7ccb6a88r   r%   /array-original-27b9f9d257a80fa6adae06a98faf71ebr   r'   r   r   r%   &array-27b9f9d257a80fa6adae06a98faf71ebr%   r%   z0cholesky-lt-dot-26a6b670a8aabb7e2f8936db7ccb6a88r%   r   r%   r   r   r%   r      r   r%   r%   )r'   r'   r   r   r%   r   r   r   )r   r   r   r   r   r   r   r%   r   r   r   r   r   r%   r%   r   r   r   r   >   r   r   r   r   r    T)rQ   r   r1   )slicer   r:   )r   r+   rQ   rvr   r   r   test_fuse_stressed  s\   	:r   c                  C  s  dd } dd| ddf| dfd}t |dd	d
td| | ddffiks$J t |ddd
t| | ddffddks9J t |dd	d
tdd| | ddffdksOJ t |ddd
tdd| | ddffddksfJ dd| df| ddf| df| dddfd}t|}t |dd	d
|ksJ t |dd	d
|ksJ t |ddd
|ksJ t |ddd
|ksJ t |dd	d
tdd| | df| ddf| dffdksJ t |ddd
tdd| | df| ddf| dffddksJ dd| df| ddf| df| ddf| ddfd}t |dd	d
t|ksJ t |ddd
t|ksJ t |dd	d
tdd| ddf| | dfdf| d| dffdks7J t |ddd
tdd| ddf| | dfdf| d| dffdddksZJ dd| df| ddf| df| ddf| ddf| dd fd!}t |dd	d
t|ksJ t |ddd
t|ksJ t |dd	d
tdd| ddf| | | dfdf| d| dfffd"ksJ t |ddd
tdd| ddf| | | dfdf| d| dfffd#d$ksJ d S )%Nc                  W  ry   r   r   r   r   r   r   r     r   z.test_fuse_reductions_multiple_input.<locals>.fr%   r    a1a2r<   )r   r   r<   rD   Fr   rD   T	a1-a2-b-c)r   rD   )r   r   rD   b-c)r   r   r   rD   r   r   r   )r   r   r   r   r   rD   r   r   r   )r   r   r   rD   )r   r   r   r   r   r   r   )r   r   r   r   r   b1-c1b3-c2)r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r+   )r   r   r   r+   b1-b3-c1-c2-d)r   r   r   r   r+   r   r   r   r   r   #test_fuse_reductions_multiple_input  s   (



 


		
r   r    c                 C  s   | | | S r   r   rL   r   r   r   func_with_kwargs  s   r   c                  C  s  g d} t tddgft tdgtdgddft tddgtdgdftd	ftd
dfd	ddtdt| ffgttdftd	dgffd}t|dddgdd}|jdksOJ t|dksWJ t|dddgdd}||ksgJ t|dddgdd}||kswJ t	td d d gsJ t	|t	|ksJ |
 }|ddd |ddtt|dgd dgd ksJ |dd|ddksJ tt|}||ksJ t	|t	|ksJ |dd|ddksJ d S )N)r%   r    r   in1r    in2)r%   r      )functionr   rD   )r   r   r;   rD   r+   r<   r   )r;   r<   rD   r+   r`   r   hr   testnamer   r%   )r   r   r   )r   r   r   r   r   rv   r   r   reprhashcopyupdater   r	   pickleloadsdumps)Znon_hashabler   r   f2f3dsk2r   r   r   test_SubgraphCallable  sD   
*r   c                  C  s   t d} d| di}t|dd gdd}t|dd gdd}||ks$J d| dd i}t|dd gdd}||ks<J t|dd gdd}||ksKJ d S )Nnumpyr;   r'   r   r   r%   Ztest2)r-   importorskiparanger   )npdsk1f1r   r   r   f4r   r   r    test_SubgraphCallable_with_numpy  s   
r   c                  C  s  ddt ddfd} tdftdft ddfd}t| dddg}t|dddg}||ks,J t|t|ks6J t|t|ks@J ddt ddfd}t|dddg}|j|jksYJ ||ks_J t|t|ksiJ t|t|kssJ t|ddd	g|jd
}||ksJ t|t|ksJ t|t|ksJ t|dddg|jd
}||ksJ t|t|ksJ t|t|ksJ t| dddg|jd
}||ksJ t|t|ksJ t|t|ksJ t| dddgdd
}	t| dddgdd
}
|	|
ksJ t|	t|
ksJ t|	t|
ksJ tt dddg dd
}tt dddg dd
}||ks1J t|t|ks<J t|t|ksGJ d S )Nr%   r    r+   r`   rL   r   r;   rD   r   r   firstsecondr{   r<   n)r   r   r   r   r   r   object)r   r   r   r   Zdsk1bZf1br   r   Zf5Zf6Zf7Zf8Zf9r   r   r   test_SubgraphCallable_eq  sF   r   c                 C  s`  dt dft dftddft dft dftddft dft d	fd
	}t|ddd}tdtdtdt t dffft t tdt t dfffffdddfd}||ksMJ t|dddd}tdtdtdt t dffft t tdt t dfffffdddfi}||ks|J t|ddd}ttdtdt t dffftdt t dfffdddfdt t dffd}||ksJ t|ddd}g }tdD ]*}|tdt t dffdttddft t tdt t dfffffdd|f| d q||v sJ t|ddgdd}g }tdD ]+}|tdt t dffttddftdt t dfffdd|f| dt t dffd q||v s.J d S )Nr%   x-1inc-1inc-2add-1inc-3inc-4add-2inc-5)	r   r   r   r   r   r   r   r   inc-6r   Tfuse_subgraphsadd-inc-x-1)r   r   r   r   )r   r   F)r   r1   )r   r   r   )r   r   r   )r   r   	inc-add-1)r   r   )r   r   r   r   )r   r   )r   r   r   r   r   )r   r   r   r:   r   	itertoolspermutationsappend)r   r   ressolZsolsr   r   r   r   test_fuse_subgraphs   s   




r  c              
   C  s   dt ddft ddft ddft ddft ddfd}t|dd	d
}ttdt ddft ddft ddft ddft ddfdddfdd}||ksGJ d S )Nr%   r   r   r   add-3add-4)r   r   r   r  r  add-5r  Tr   r   add-x-1)r  r  )r   r   r:   r   )r   r   r  r  r   r   r   3test_fuse_subgraphs_linear_chains_of_duplicate_deps  s2   	r  c                  C  s8   t d} | dtdfd}t|dd |ksJ dS )za
    Some types should stay in the graph bare

    This helps with things like serialization
    r      r"   rt   r&   r   N)r-   r   r   r   r   )r   r   r   r   r   test_dont_fuse_numpy_arrays  s   
r
  c                  C  sf   t jddi! dtdfd} ddi}t| d|d| |fks!J W d    d S 1 s,w   Y  d S )	Nzoptimization.fuse.activeFr%   r;   r{   r<   )r;   r}   )daskconfigr   r   r   )r+   r/   r   r   r   test_fuse_config  s   "r  c               	   C  s^   t dft dft dft dft dftddfdd	d
} t| dd\}}|D ]
}t|dk s,J q"d S )NXv-looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongXw-looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongXx-looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongXy-looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongXz-looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongr;   r<   r%   r    )zXu-looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongr  r  r  r  r  r;   r<   Tr?      )r   r   r   ra   )r+   Zfuseddepskeyr   r   r   test_fused_keys_max_length  s4   r  )r    );
__future__r   r   r   	functoolsr   r-   r  Z	dask.baser   r[   r   Z
dask.localr   Zdask.optimizationr   r	   r
   r   r   r   r   Z
dask.utilsr   r   Zdask.utils_testr   r   r   Zfixturer   r#   r0   r5   r:   rP   rR   r\   rb   rh   rj   rs   ru   rw   rx   r|   r   r   r   r   r   r   r   r   r  r  r
  r  r  r   r   r   r   <module>   s^    $		


v#*#	    YH
k/6!
