
    >ie                       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	m
Z
mZ d dlmZmZ  ej        ddg	          d
             Zd6dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d  Z%d! Z&d" Z'd# Z(d$ Z)d% Z*d& Z+d' Z,d( Z-d) Z.d* Z/d+ Z0d, Z1d- Z2d. Z3ej4        5                    d/d0dg          d1             Z6d2 Z7d3 Z8d4 Z9d5 Z:dS )7    )annotationsN)collections_to_dsk)get_deps)diagnosticsndependenciesorder)addincabcdeedcba)paramsc                    | j         S N)param)requests    5lib/python3.11/site-packages/dask/tests/test_order.pyr   r      s
    =    Fc                ,    t          | |          | k    S )N)reverse)sorted)Lr   s     r   issortedr      s    !W%%%**r   c                     d S r    )argss    r   fr      s    Dr   c           	        | \  }}}}fdt          d          D             }|                    |dft          dfdff|dft          dfdffi           t          |          }t	          |df         |df         z
            dk    sJ t	          |df         |df         z
            dk    sJ fdt          d          D             }|                    |dft          dfdff|dft          dfdffi           t          |          }t	          |df         |df         z
            dk    sJ t	          |df         |df         z
            dk    sJ d S )Nc                &    i | ]}|ft           fS r   r   .0ias     r   
<dictcomp>z7test_ordering_keeps_groups_together.<locals>.<dictcomp>   !    (((!!Q!(((r      r            c                &    i | ]}|ft           fS r   r   r    s     r   r$   z7test_ordering_keeps_groups_together.<locals>.<dictcomp>"   r%   r   )rangeupdater   r   abs)r   bcdeor#   s         @r   #test_ordering_keeps_groups_togetherr3      s   MAq!Q((((uQxx(((AHHq!fq1a&1a&)Aq6A1v1v3FGHHHaAq!Qy1aV9$%%****q!Qy1aV9$%%****((((uQxx(((AHHq!fq1a&1a&)Aq6A1v1v3FGHHHaAq!Qy1aV9$%%****q!Qy1aV9$%%******r   c                n   | \  }}}}}|dft           f|dft           f|dft           |dff|dft           |dff|dft           |dffi}t          |          }||df         ||df         k     sJ |dft           f|dft           f|dft           |dff|dft           |dff|dft           |dffi}t          |          }||df         ||df         k    sJ |dft           f|dft           f|dft           |dff|dft           |dff|dft           |dffi}t          |          }||df         ||df         k     sJ dS )zV

    b0    b1  b2
    |      \  /
    a0      a1

    a0 should be run before a1
    r   r'   r(   Nr   r   r   r#   r.   r/   r0   r1   dskr2   s           r   test_avoid_broker_nodesr8   *   s    MAq!Q	
A	
A	
AQF	
AQF	
AQFC 	c

AaV9q!Qy     
A	
A	
AQF	
AQF	
AQFC 	c

AaV9q!Qy     
A	
A	
AQF	
AQF	
AQFC 	c

AaV9q!Qy      r   c                   | \  }}fddD             }t           dff|df<   |                    fddD                        d|<   t          |          }|df         dk    sJ |df         dk    sJ dS )	z
               a3
              /|
            a2 |
           /|  |
         a1 |  |
        /|  |  |
      a0 |  |  |
      |  |  |  |
      b0 b1 b2 b3
        \ \ / /
           c

    We really want to run b0 quickly
    c                8    i | ]}|ft           |d z
  f|ffS r'   r   )r!   r"   r#   r.   s     r   r$   z1test_base_of_reduce_preferred.<locals>.<dictcomp>f   s2    
>
>
>qAq6A1q5zAq6*
>
>
>r   )r'   r(   r)   r   c                *    i | ]}|ft           d fS r;   r   )r!   r"   r.   r/   s     r   r$   z1test_base_of_reduce_preferred.<locals>.<dictcomp>h   s%    888aAAq	888r   )r   r'   r(   r)   r'   r)   N)r   r,   r   )r   r0   r1   r7   r2   r#   r.   r/   s        @@@r   test_base_of_reduce_preferredr=   U   s      MAq!Q
>
>
>
>
>I
>
>
>Cq!f+CAKJJ88888<888999CFc

AaV9>>>>aV9>>>>>>r   c                4   | \  }}}}}|dft           |dff|dft           |dff|dft           |df|dff|dft           |dff|dft           |dff|dft           |dff|dft           |dff|dfd|dfdi	}t          |          }||df         ||df         k     sJ dS )z
       a1
       |
       a2
       |
       a3    d1
      /  \  /
    b1    c1
    |     |
    b2    c2
          |
          c3
    r'   r(   r)   Nr5   r6   s           r   test_avoid_upwards_branchingr?   q   s     MAq!Q	
AQF	
AQF	
AQFQF#	
AQF	
AQF	
AQF	
AQF	
A	
A
C 	c

AaV9q!Qy      r   c                   | \  }}}}}|dft           |dff|dft           |dff|dft           |df|dff|dft           |dff|dft           f|dft           |dff|dft           |dff|dft           f|dft           |dff|dft           |dff|dft           |dff|dft           |dff|dft           |dffi}t          |          }||df         ||df         k     sJ t          ||df         ||df         z
            dk    sJ dS )a  
         a1
         |
    e2   a2  d2  d3
    |    |    \  /
    e1   a3    d1
     \  /  \  /
      b1    c1
      |     |
      b2    c2
            |
            c3

    Prefer c1 over b1 because c1 will stay in memory less long while b1
    computes
    r'   r(   r)   N)r   r   r-   r6   s           r   $test_avoid_upwards_branching_complexrA      sT   " MAq!Q	
AQF	
AQF	
AQFQF#	
AQF	
A	
AQF	
AQF	
A	
AQF	
AQF	
AQF	
AQF	
AQFC  	c

AaV9q!Qy    q!Qy1aV9$%%******r   c           
         | \  }}}}}|t           |||f|t           ||f|t           |f|d|di}t          |          }||         ||         k     sJ ||         ||         k     sJ dS )a{  
    It's not clear who should run first, e or d

    1.  d is nicer because it exposes parallelism
    2.  e is nicer (hypothetically) because it will be sooner released
        (though in this case we need d to run first regardless)

    Regardless of e or d first, we should run b before c.

            a
          / | \   .
         b  c |
        / \ | /
       e    d
    r'   r(   Nr5   r6   s           r   #test_deep_bases_win_over_dependentsrC      sx      MAq!Qq!QlA1ay!aVQ1a
@Cc

AQ4!A$;;;;Q4!A$;;;;;;r   c                    | \  }}}}}|d|t           |f|t           |f|d|t           |fi}t          |          }||         ||         k     sJ ||         ||         k     sJ dS )zq
        c
        |
    e   b
    |   |
    d   a

    Prefer longer chains first so we should start with c
    r'   Nr5   r6   s           r   test_prefer_deeprE      sr     MAq!QaQFA1vq!QA
7Cc

AQ4!A$;;;;Q4!A$;;;;;;r   c                |    d t          d          D             }t          |          \  }}t          ||           d S )Nc                4    i | ]}d |dz   z  t           d |z  fS )zx%sr'   r
   r!   r"   s     r   r$   z#test_stacklimit.<locals>.<dictcomp>   s+    
C
C
C5AE?S%!),
C
C
Cr   i'  )r+   r   r   )r   r7   dependencies
dependentss       r   test_stacklimitrL      sA    
C
CeEll
C
C
CC'}}L*,
+++++r   c                   | \  }}}}}d t          d          D             }t          |          }t          |          |d<   t          |          }ddi}	|	                    d t          |          D                        ||	k    sJ d S )Nc                &    i | ]}d |ft           |fS )xrH   rI   s     r   r$   z*test_break_ties_by_str.<locals>.<dictcomp>   s"    
1
1
1!C8c1X
1
1
1r   
   yc                    i | ]\  }}||	S r   r   )r!   r"   ks      r   r$   z*test_break_ties_by_str.<locals>.<dictcomp>   s    888daQ888r   )r+   r   listr   r,   	enumerate)
r   r#   r.   r/   r0   r1   r7   x_keysr2   expecteds
             r   test_break_ties_by_strrX      s    MAq!Q
1
1uRyy
1
1
1CC[[FF||CHc

ARyHOO88i&7&7888999======r   c                X    t          t          dft          dft          ddfd           d S )Nr'   r(   rO   rQ   r   )rO   rZ   z)r   r
   r	   )r   s    r   )test_order_doesnt_fail_on_mixed_type_keysr\      s/    	aS!HCh3G
H
HIIIIIr   c                 D  
 t          j        d          } d\  }}| j                            ||fd          x}}t	          d          D ]K}|d d d d d f         |d d d d d f         z                      d          }|                    d          }L||d d d f         z                      d          }t          |                                          }t          |          

fd	|
                                D             }	t          
fd
|	D                       t          |	          dz  k    sJ 
fd|
                                D             }	t          
fd|	D                       t          |	          dz  k    sJ t          |	          |	k    sJ d S )N
dask.array)   c   )r'   N)sizechunksr(   r   axis)r'   r(   c                     g | ]
}|         S r   r   )r!   rS   r2   s     r   
<listcomp>z test_gh_3055.<locals>.<listcomp>  s    )))!1)))r   c              3  D   K   | ]}|t                    d z  k     V  dS r(   Nlenr!   rO   r2   s     r   	<genexpr>ztest_gh_3055.<locals>.<genexpr>  1      ))!q3q66A:~))))))r   r)   c                *    g | ]}|D ]
}|         S r   r   )r!   kkrS   r2   s      r   rf   z test_gh_3055.<locals>.<listcomp>  s*    999"b9919999r   c              3  D   K   | ]}|t                    d z  k    V  dS rh   ri   rk   s     r   rl   ztest_gh_3055.<locals>.<genexpr>  rm   r   )pytestimportorskiprandomnormalr+   cumsumsumdict__dask_graph__r   __dask_keys__rj   r   )daABorigrO   _rQ   wr7   r   r2   s             @r   test_gh_3055r      s   		\	*	*BDAqyaVI>>>D11XX  qqq$z]Qqqq!!!Tz]*222::HH!H	
Qqqq$wZ&))A
q!!
"
"Cc

A))))q(()))A))))q)))))CFFQJ66669999**,,999A))))q)))))CFFQJ6666!99>>>>>>r   c                N    | \  }}}}}|d|dfd||dfdi}t          |           d S )Nr'   r(   r)   r   )r   r#   r.   r/   r0   r1   r7   s          r   test_type_comparisions_okr     s<    MAq!Qa!QQ1Iq
)C	#JJJJJr   c                    | \  }}}}}|t           f|t           |f|t           |f|t           |f|t           |fi}t          |          }||         ||         k    sJ ||         ||         k    sJ dS )z9

       a
       |
    d  b  e
     \ | /
       c

    Nr5   r6   s           r    test_favor_longest_critical_pathr     sx     MAq!QqdA1vq1a&!aVQA
?Cc

AQ4!A$;;;;Q4!A$;;;;;;r   c                   | \  }}}}}d ||||fD             \  }}}}	|t           f|t           f|t           f|t           f|t           ||f|t           ||f|t           |f|t           ||f|	t           |fi	}
t          |
          }t          t          |
          d                   dk    sJ ||         ||         k     r||	         ||         k     s&||         ||         k     r||         ||         k     sJ dS dS )zX
            aa
           / |
      b   d  bb dd
     / \ /|  | /
    a   c e  cc

    c              3      K   | ]	}|d z  V  
dS rh   r   )r!   rO   s     r   rl   z,test_run_smaller_sections.<locals>.<genexpr>/  s&      22a!e222222r   r'   r&   N)r   r   maxr   )r   r#   r.   r/   r0   r1   aabbccddr7   r2   s               r   test_run_smaller_sectionsr   %  s    MAq!Q22aAq\222NBB 	
A4	A4	A4
QD	Aq!9	Aq!9
QG
Q2J
QG
C 	c

A{3"##q(((( bEAaDLLQrUQqT\\qtad{{qtae||||\\||r   c                   | \  }}fddD             \  }}}fddD             \  }}}fddD             \  }	}
}||||||||
|	g	}g fd}| ||          f| ||          |f| ||          |f| ||          f| ||          ||f| ||          |f| ||          f|
 ||
          ||f|	 ||	          |
fi	}t          |           t          j        ||||	g           |k    sJ dS )z

            c1
            |
        b1  c2
        |  /|
    a1  b2  c3
    |  /|
    a2  b3
    |
    a3

    Prefer to finish a1 stack before proceeding to b2
    c              3  "   K   | ]	}|z   V  
d S r   r   r    s     r   rl   z2test_local_parents_of_reduction.<locals>.<genexpr>S  '      ''A!a%''''''r   123c              3  "   K   | ]	}|z   V  
d S r   r   r!   r"   r.   s     r   rl   z2test_local_parents_of_reduction.<locals>.<genexpr>T  r   r   c              3  "   K   | ]	}|z   V  
d S r   r   )r!   r"   r/   s     r   rl   z2test_local_parents_of_reduction.<locals>.<genexpr>U  r   r   c                      fd}|S )Nc                 2                                    d S r   )append)r   logrO   s    r   r~   z5test_local_parents_of_reduction.<locals>.f.<locals>._\  s    JJqMMMMMr   r   )rO   r~   r   s   ` r   r   z*test_local_parents_of_reduction.<locals>.f[  s)    	 	 	 	 	 	 r   N)r   daskget)r   r0   r1   a1a2a3b1b2b3c1c2c3rW   r   r7   r#   r.   r/   r   s                  @@@@r   test_local_parents_of_reductionr   C  s    MAq!Q'''''''JBB'''''''JBB'''''''JBBBBBB3H
C     	QQrUUH
QQrUUBK
QQrUUBK
QQrUUH
QQrUUBO
QQrUUBK
QQrUUH
QQrUUBO
QQrUUBK
C 
#JJJHS2r2,(??????r   c                f   | \  }}}fddD             \	  }}}}}}}	}
}fddD             \  }}}}|t           f|t           f|t           f|t           f|t           |f|t           |f|t           ||f|t           |f|t           ||f|t           |f|	t           ||f|
t           |f|t           |fi}t          |          dt          fddD                       cxk     rdk     sn J dt          fd	dD                       cxk     rd
k     sn J t          ||||g                   dk    sJ dS )z

    a1  a2  a3  a4  a5  a6  a7 a8  a9
     \  |  /  \ |  /  \ |  / \ |  /
        b1      b2      b3     b4

    Want to finish off a local group before moving on.
    This is difficult because all groups are connected.
    c              3  "   K   | ]	}|z   V  
d S r   r   r    s     r   rl   z(test_nearest_neighbor.<locals>.<genexpr>~  s'      )E)EA!a%)E)E)E)E)E)Er   	123456789c              3  "   K   | ]	}|z   V  
d S r   r   r   s     r   rl   z(test_nearest_neighbor.<locals>.<genexpr>  s'      ,,a!e,,,,,,r   1234r)   c              3  V   K   | ]#}|z            t                    d z  k     V  $dS rh   ri   )r!   r"   r#   r2   s     r   rl   z(test_nearest_neighbor.<locals>.<genexpr>  s:      >>Q1QU8c!ffqj(>>>>>>r      r'   c              3  V   K   | ]#}|z            t                    d z  k     V  $dS rh   ri   )r!   r"   r.   r2   s     r   rl   z(test_nearest_neighbor.<locals>.<genexpr>  s:      99Q1QU8c!ffqj(999999r   r&   r   N)r   r   rv   min)r   r/   r~   r   r   r   a4a5a6a7a8a9r   r   r   b4r7   r#   r.   r2   s                    @@@r   test_nearest_neighborr   s  s    MAq!Q)E)E)E)E)E)E)E&BBBBB,,,,V,,,NBB 	QD
QD
QD
QD
QG
QG
QBK
QG
QBK
QG
QBK
QG
QGC  	c

As>>>>>+>>>>>BBBBBBBBBBs99999&99999====A======S"b"b!""#q((((((r   c                 l    t           ft           ft           fd} t          |           }|ddddk    sJ dS )z#Prefer ordering tasks by name first)r#   r'   r#   r(   r#   r)   r   r'   r(   Nr5   r7   r2   s     r   test_string_orderingr     sC    TaTaT
:
:Cc

A1Q77777777r   c                     t           dft           dft           dft           fd} t          |           }|dddddk    sJ dS )	z=Prefer ordering tasks by name first even when in dependenciesr.   )r   r   r   r.   r   r'   r(   r)   )r.   r   r   r   Nr5   r   s     r   test_string_ordering_dependentsr     sO    X!SaXQD
Q
QCc

Aa1Q????????r   c                <   | \  }}}}}|dfd|dfd|dfd|dft           |df|df|dff|dfd|dfd|dft           |df|df|dffi}t          |          }||df         ||df         k     sJ ||df         ||df         k     sJ ||df         ||df         k     sJ d S )Nr   r'   r(   r5   )r   r#   r.   r/   r~   r7   r2   s          r   test_prefer_short_narrowr     s    MAq!Q	
A	
A	
A	
AQFQFQF+	
A	
A	
AQFQFQF+C 	c

AaV9q!Qy    aV9q!Qy    aV9q!Qy      r   c                   | \  }}}}}||z   }|d|dft           |ddf|dft           |ddf|dfd|dft           |df|df|dff|dft           |ddf|dft           |ddf|dft           |df|df|dffi}t          |          }||df         ||df         k     sJ ||df         ||df         k     sJ ||df         ||df         k     sJ ||df         ||df         k     sJ ||df         ||df         k     sJ dS )a  
    From https://github.com/dask/dask-ml/issues/206#issuecomment-395869929

    Two cases, one where chunks of an array are independent, and one where the
    chunks of an array have a shared source. We handled the independent one
    "well" earlier.

    Good:

                    c2
                   / \ \
                  /   \ \
                c1     \ \
              / | \     \ \
            c0  a0 b0   a1 b1

    Bad:

                    c2
                   / \ \
                  /   \ \
                c1     \ \
              / | \     \ \
            c0  a0 b0   a1 b1
                   \ \   / /
                    \ \ / /
                      a-b


    The difference is that all the `a` and `b` tasks now have a common
    ancestor.

    We would like to choose c1 *before* a1, and b1 because

    * we can release a0 and b0 once c1 is done
    * we don't need a1 and b1 to compute c1.
    r   r'   r(   Nr5   )r   r#   r.   r/   r~   abr7   r2   s           r   test_prefer_short_ancestorr     sl   L MAq!Q	
QB 	A	
AB1	
AB1	
A	
AQFQFQF+	
AB1	
AB1	
AQFQFQF+	C 	c

AaV9q!Qy    aV9q!Qy    aV9q!Qy    aV9q!Qy    aV9q!Qy      r   c                j   | \  }}}}}i |dft           f|dft           |dff|dft           |dff|dft           |df|dff|dft           f|dft           |df|df|dff|dft           f|dft           |dff|dft           |dff|dft           |df|df|dff|dft           f|dft           |df|df|dff|dft           f|dft           |dff|dft           |dff|dft           |df|dff}t          |          }||df         ||df         k     s||df         ||df         k     sJ dS dS )z
      b1      b3      b5
       |\    / | \  / |
      c1  c2  c3  c4  c5
       |/  | \ | / | \|
      d1  d2  d3  d4  d5
       |       |      |
      e1      e2      e5

    Want to finish b1 before we start on e5
    r'   r(   r)   r&      Nr5   r6   s           r   test_map_overlapr     s    MAq!Q	
A	
AQF 
AQF 
AQFQF#	
 
A 
AQFQFQF+ 
A 
AQF 
AQF 
AQFQFQF+ 
A 
AQFQFQF+ 
A 
AQF 
AQF  
AQFQF#!C& 	c

AaV9q!Qy  Aq!fI1a&	$9$9$9$9  $9$9r   c                   | \  }}}i dft           fdft           fdft           fdft           fdft           fdft           fdft           fdft           fd	ft           fd
ft           fdft           dffdft           dfdffd
ft           dfdfdffdft           dfdfdffdft           d
fdfdffdft           dfd
fdffdft           dfdfd
ffd	ft           dfdfdffdft           d	fdfdffdft           dfd	fdffi}t          |          }t          fd|                                D                       }t          fd|                                D                       }|d         dv sJ |d         dk    r|g dk    sJ |g dk    sJ dS |g dk    sJ |g dk    sJ dS )zSee https://github.com/dask/dask/issues/5584#issuecomment-554963958

    We were using key names to infer structure, which could result in funny behavior.
    r   r'   r(   r)   r&   r      r      	   c              3  4   K   | ]\  \  }}}|k    |V  d S r   r   )r!   letterr~   valr#   s       r   rl   z.test_use_structure_not_keys.<locals>.<genexpr>6  0      EE(S1EEr   c              3  4   K   | ]\  \  }}}|k    |V  d S r   r   )r!   r   r~   r   r.   s       r   rl   z.test_use_structure_not_keys.<locals>.<genexpr>7  r   r   >   r'   r)   )
r   r'   r(   r&   r   r   rP            )
r)   r   r   r                     )
r   r(   r&   r   r   rP   r   r   r   r   )
r'   r)   r   r   r   r   r   r   r   r   Nr   r   r   items)r   r~   r7   r2   AsBsr#   r.   s         @@r   test_use_structure_not_keysr     s   
 MAq!Q	
A	
A 
A 
A	
 
A 
A 
A 
A 
A 
A 
AQF 
AQFQF# 
AQFQFQF+ 
AQFQFQF+ 
AQFQFQF+  
AQFQFQF+!" 
AQFQFQF+#$ 
AQFQFQF+	
AQFQFQF+	
AQFQFQF+) C, 	c

A	EEEEAGGIIEEE	E	EB	EEEEAGGIIEEE	E	EBa5F????	!uzz77777779999999998888888888888888r   c                   | \  }}}}d}|dft           df|dft           df|dft           dfdft           |df|df|dffi}t          d|          D ];}t           |dff|||f<   t           |dff|||f<   t           |dz
  f||f||ff||f<   <t          |          }g d}	t          fd|                                D                       }
|	|
k    sJ dS )zFFrom https://github.com/dask/dask-ml/issues/206#issuecomment-395873372rP   r   r'   r(   )
r)   r   r   r   r   r               c              3  4   K   | ]\  \  }}}|k    |V  d S r   r   )r!   r   numvr0   s       r   rl   z9test_dont_run_all_dependents_too_early.<locals>.<genexpr>R  s0      GG*-636Q;;A;;;;GGr   N)r   r+   r   r   r   )r   r#   r.   r/   r1   depthr7   r"   r2   rW   actualr0   s              @r   &test_dont_run_all_dependents_too_earlyr   A  s%   MAq!QE	
AA	
AA	
AA	
AQFQFQF+	C 1e__ 6 61a&kQF1a&kQF1a!e*q!fq!f5QFc

A444HGGGGaggiiGGGGGFvr   c           	       	
 | \  }}}
z   	

z   i |dfd|dft           |dff|dft           |dff|dft           |dff|dft           |dff|dft           |dffdft           |dffdft           dff	dft           |dff	dft           	dff	dft           df	dff
dft           |dff
dft           
dffdft           |dffdft           dffdft           
dfdff|dft           |df|df|df	dfdff}t          |          }g d}t          	
fd|                                D                       }||k    sJ ||df         ||df         dz
  k    sJ dS )a=  From https://github.com/dask/dask/pull/5646#issuecomment-562700533

    Sometimes we need larger or wider DAGs to test behavior.  This test
    ensures we choose the branch with more work twice in successtion.
    This is important, because ``order`` may search along dependencies
    and then along dependents.

    r   r'   r(   r)   )
r'   r(   r)   r&   r   r   r   r   r   rP   c              3  8   K   | ]\  \  }}}|hv |V  d S r   r   )r!   r   r~   r   r0   r   r1   ees       r   rl   z7test_many_branches_use_ndependencies.<locals>.<genexpr>x  s=      RR.+61qAr1b>9Q9QA9Q9Q9Q9QRRr   Nr   )r   r#   r.   r/   r7   r2   rW   r   r0   r   r1   r   s           @@@@r   $test_many_branches_use_ndependenciesr   V  sj    MAq!Q	
QB	
QB	
A	
AQF 
AQF 
AQF	
 
AQF 
AQF 
AQF 
AQF 
Q!aV 
Q!b!W 
Q!aVb!W% 
AQF 
AQF 
Q!aV 
Q!b!W  
Q!aVb!W%!" 
AQFQFQFRGb!W=#C& 	c

A...HRRRRRRRAGGIIRRRRRFXaV91a&	A%%%%%%r   c                    t          j        t          d          5  t          j        dt
          dfid           d d d            n# 1 swxY w Y   t          j        t          d          5  t          dt
          dfi           d d d            n# 1 swxY w Y   t          j        t          d          5  t          dt
          dfi           d d d            n# 1 swxY w Y   t          j        t          d          5  t          t
          dft
          dft
          dfd           d d d            n# 1 swxY w Y   t          j        t          d          5  t          t
          dft
          dft
          ddfd	d
           d d d            n# 1 swxY w Y   t          j        t          d          5  t          t
          dft
          dft
          ddft
          dfd
           d d d            d S # 1 swxY w Y   d S )NzCycle detected)matchr#   r#   r   r.   r/   )r#   r.   r/   r0   r'   )r#   r.   r/   r0   )rq   raisesRuntimeErrorr   r   r   r   r   r   r   test_order_cycler   }  sw   	|+;	<	<	< ' '#3x#&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' '	|+;	<	<	<  sQHo              	|+;	<	<	< ) )x!X'((() ) ) ) ) ) ) ) ) ) ) ) ) ) )	|+;	<	<	< = =QHAs81c(;;<<<= = = = = = = = = = = = = = =	|+;	<	<	< J JQHAs81c3-aHHIIIJ J J J J J J J J J J J J J J	|+;	<	<	< Q QQHAs81c3-q#hOOPPPQ Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Qsk   AAA-BBB8CC!$C!)D88D<?D<+FFF;2G::G>G>c                 0    t          i           i k    sJ d S r   r   r   r   r   test_order_emptyr     s    99??????r   c                   | \  }}}}}i |dfd|dft           |dff|dft           |dff|dft           |dff|dft           |df|dff|dft           |dff|dft           |dff|dft           |dff|d	ft           |dff|dfd|dft           |dff|dft           |dff|dft           |dff|dft           |dff|dft           |dff|dft           |dff|dft           |dff}t          |          }||df         dk    sJ ||df         ||df         k    sJ ||df         ||df         k    sJ ||df         ||df         k    sJ d
S )ax  

    a7 a8  <-- do these last
    | /
    a6                e6
    |                /
    a5   c5    d5  e5
    |    |    /   /
    a4   c4 d4  e4
    |  \ | /   /
    a3   b3---/
    |
    a2
    |
    a1
    |
    a0  <-- start here

    Test that we are able to switch to better dependents.
    In this graph, we expect to start at a0.  To compute a4, we need to compute b3.
    After computing b3, three "better" paths become available.
    Confirm that we take the better paths before continuing down `a` path.

    This test is pretty specific to how `order` is implemented
    and is intended to increase code coverage.
    r   r'   r(   r)   r&   r   r   r   r   Nr5   r6   s           r   test_switching_dependentsr     s0   6 MAq!Q	
A	
AQF 
AQF 
AQF	
 
AQFQF# 
AQF 
AQF 
AQF 
AQF 
A 
AQF 
AQF 
AQF 
AQF 
AQF  
AQF!" 
AQF#C& 	c

AaV9>>>>aV9q!Qy    aV9q!Qy    aV9q!Qy      r   c                   d}| \  }}}}}i }||||g}|D ]}	|                     |	dft          df|	dft          |	dff|	ddft          |	dff|	ddft          |	dffi           t          |          D ]~\  }
}|                     |	d|
ft          |	ddf|ddff|	d|
ft          |	d|
ff|	d|
dft          |	d|
ff|	d|
dft          |	d|
ff|	d|
dft          |	d|
dff|	d|
dft          |	d|
dffi           t          |          }d}|D ]G}	t	          t          |                    D ](}
||	d|
df         ||	d|
df         z
  }|dk    sJ ||z  })H|d	k    sJ t          ||
          d         }t          |          |k    sJ t          |          }|D ]5}	t	          t          |                    D ]}
t          |	d|
dff||	d|
df<   6t          |          }d}|D ]G}	t	          t          |                    D ](}
||	d|
df         ||	d|
df         z
  }|dk    sJ ||z  })H|dk    sJ t          ||
          d         }t          |          |k    sJ t          |          }|D ](}	t	          t          |                    D ]	}
||	d|
df= 
)t          |          }d}|D ]G}	t	          t          |                    D ](}
||	d|
df         ||	d|
df         z
  }|dk    sJ ||z  })H|dk    sJ t          ||
          d         }t          |          |k    sJ t          |          }|D ](}	t	          t          |                    D ]	}
||	d|
df= 
)t          |          }t          ||
          d         }t          |          |k    sJ |D ]M}	t	          t          |                    D ].}
t          ||	d|
df         ||	d|
df         z
            dk    sJ /NdS )zFrom https://github.com/dask/dask/issues/5859#issuecomment-608422198

    See the visualization of `(maxima, argmax)` example from the above comment.

    This DAG has enough structure to exercise more parts of `order`

    r   r   r'   r(   r)   r&   r   r   8   r2   r   K   -   rP   N)
r,   r   rU   r   r+   rj   r   r   rw   r-   )r   max_pressurer#   r.   r/   r0   r1   r7   abcrO   r"   rQ   r2   totalr   pressuredsk2dsk3dsk4s                      r    test_order_with_equal_dependentsr    s?    LMAq!Q
CaA,C  

AAAQFAq	A1v;Aq	A1v;		
 	
 	
 cNN 
	 
	DAqJJ1IAq!9q!Qi81IAq!9~1aL1q!Qi.1aL1q!Qi.1aL1q!Ql"31aL1q!Ql"3	 	 	 	
	 	c

AE  s3xx 	 	AQ1aL/Aq!QlO3C7777SLEE	 B;;;;3!$$$Q'Hx==L(((( 99D 3 3s3xx 	3 	3A"#aAq\!2D!Q1	3dAE  s3xx 	 	AQ1aL/Aq!QlO3C7777SLEE	 B;;;;41%%%a(Hx==L(((( 99D # #s3xx 	# 	#AaAq\""	#dAE  s3xx 	 	AQ1aL/Aq!QlO3C7777SLEE	 B;;;;41%%%a(Hx==L(((( ::D # #s3xx 	# 	#AaAq\""	#dA41%%%a(Hx==L(((( @ @s3xx 	@ 	@Aq!Q1Aq!Q<899R?????	@@ @r   c                     dddt           ddft           ddfddd	d
dt           ddft           ddfddt           ddddfd} t          |           }|d         |d         k     sJ dS )a  
    https://github.com/dask/dask/issues/6745

    We have

    1. A terminal node that depends on the entire graph ('s')
    2. Some shared dependencies near the roots ('a1', 'a4')
    3. But the left and right halves are disconnected, other
       than the terminal node.

                       s
               /   /       \   \
              /   /         \   \
            s00  s10       s01  s11
             |    |         |    |
            b00  b10       b01  b11
            / \  / \       / \ / \
           a0  a1  a2    a3  a4  a5

    Previously we started at 'a', and worked up to 's00'. We'd like to finish
    's00' completely, so we progress to 's' and work through its dependencies.

    Ideally, we would choose 's10', since we've already computed one of its
    (eventual) dependencies: 'a1'. However, all of 's00' through 's11' had
    equal metrics so we fell back to the name tie-breaker and started on
    's01' (via 'a3', a4', 'b01', ...).
    )r   r;   )r(   r   r   r   r.   r   r.   r'   )r)   )r&   )r   r   r#   r&   r#   r   r.   r(   r.   r)   storer   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  Nr5   r   s     r   test_terminal_node_backtrackr  "  s    < h)h)!!h)h)!!
# C2 	c

AX;8$$$$$$r   c                   t          j        d          t          j        d          }dd lfdt          d          D             }                    |d                              d          }|                    |           }|                    |d	          }|                    d
||j	        d          }|
                    |dd          }t          |j                  d D             }t          |fd          fd|D             fd|D             t          fd                                D                       }	t          fd                                D                       }
|	|
k     sJ d S )Nr^   zarrr   c                d    g | ],}                                         d           d          -S ))n   r&   d   r(   rb   )
from_arrayones)r!   r"   rz   nps     r   rf   z0test_array_store_final_order.<locals>.<listcomp>c  s5    RRRAbmmBGGH--hm??RRRr   r&   rc   r  T)	overwritedest)namedatarb   r  F)lockcomputec                r    g | ]4}t          |t                    |d                              d          2|5S )r   z
store-map-)
isinstancetuple
startswith)r!   rS   s     r   rf   z0test_array_store_final_order.<locals>.<listcomp>m  s<    UUUAjE22Uqt|7T7TUaUUUr   c                    |          S r   r   )rS   r2   s    r   <lambda>z.test_array_store_final_order.<locals>.<lambda>n  s    AaD r   )keyc                8    g | ]}|d          d          k    |S r   r!   rS   first_stores     r   rf   z0test_array_store_final_order.<locals>.<listcomp>o  s+    FFFaQrUk"o-E-E-E-E-Er   c                8    g | ]}|d          d          k    |S r(  r   r*  s     r   rf   z0test_array_store_final_order.<locals>.<listcomp>p  s+    III"R0H0H10H0H0Hr   c              3  *   K   | ]\  }}|v 	|V  d S r   r   )r!   rS   r   connected_storess      r   rl   z/test_array_store_final_order.<locals>.<genexpr>r  s2      IIda18H3H3H3H3H3H3HIIr   c              3  *   K   | ]\  }}|v 	|V  d S r   r   )r!   rS   r   disconnected_storess      r   rl   z/test_array_store_final_order.<locals>.<genexpr>s  s2      OOAa;N6N6N16N6N6N6NOOr   )rq   rr   numpyr+   concatenaterechunkDirectoryStoregroup
empty_like	chunksizer  r   r   r   r   r   )tmpdirr  arraysrO   r  rootr  r0   storesconnected_maxdisconnected_minr.  rz   r0  r+  r  r2   s              @@@@@@r   test_array_store_final_orderr>  [  s    
	\	*	*Bv&&DRRRRRqRRRF
vA&&..x88A''E::et:,,D??Qq{d?SSD	5%00AafA VUUUUFf....111KFFFF6FFFIIIIfIIIIIIIaggiiIIIIIMOOOOOOOOO+++++++r   c                    i dt           ddfdt           ddfdt           dd	fd
t           ddfdt           ddfdt           ddfdt           ddfdt           ddfdt           dd
fdt           dfdt           dfdt           dfdt           dfdt           dfdt           dfd t           d!fd"t           d#fi d$t           d%fd&t           d'fd(t           d)fdt           d*fd	t           d+fdt           d,fdt           d-fdt           d.fdt           d/fdt           d0fdt           d1fdt           d2fdt           d3fd4t           d(fd5t           dfd6t           d4d5fdt           d3fi d7t           ddfd't           d,fdt           d1fd!t           d0fd8t           ddfd9t           d8d:fd:t           d&d$fd;t           d7d<fdt           d-fdt           d*fdt           d+fd=t           d"d fd)t           d>d=fdt           d.fd#t           d2fd%t           d/fd<t           ddfi d>t           d;d9fd1t           d?fd+t           d@fd-t           dAfd*t           dBfd/t           dCfd2t           dDfd3t           dEfd.t           dFfd,t           dGfd0t           dHfd?t           t           fdFt           t           fdDt           t           fdEt           t           fdHt           t           fdBt           t           ft           t           ft           t           ft           t           ft           t           fdI} t          |           \  t          |           fdJ                                D             }fdKfdL|D             }t	          |                                          }t          |dMdN                   dOk    st          |          dPk    sJ dMS dMS )Qa  https://github.com/dask/dask/pull/7929

    This graph begins with many motifs like the following:

    |      |
    c1    c2
      \ /
       b
       |
       a

    We want to compute c2 and c3 pretty close together, because if we choose to
    compute c1, then we should also compute c2 so we can release b.  Being
    greedy here allows us to release memory sooner and be more globally optimal.
    a00a06a08a01a28a26a02a24a21a03a22a25a04a29a20a05a23a27a07a09a43a10a36a11a33a12a47a13a44a14a42a15a37a16a48a17a49a18a35a19a46a55a53a60a54a59a56a61a52a57a58a30a31a32a34a38a39a40a41a50a45a51a62a68a70a67a71a64a65a63a69a66)r  r  r  r  c                N    h | ]!\  }}|         |                                 "S r   )pop)r!   r&  depsrJ   s      r   	<setcomp>zAtest_eager_to_compute_dependent_to_free_parent.<locals>.<setcomp>  s0    WWWic4\RUEVWtxxzzWWWr   c                J    | \  }}t          |         |         z
            S r   )r-   )r  r#   r.   r2   s      r   costz<test_eager_to_compute_dependent_to_free_parent.<locals>.cost  s&    11Q4!A$;r   c                4    i | ]}| |                   S r   r   )r!   r&  r  rK   s     r   r$   zBtest_eager_to_compute_dependent_to_free_parent.<locals>.<dictcomp>  s)    CCCCS$$z#//CCCr   Nr)        )r   r   r   r   r   valuesrv   )r7   parentscost_of_pairscostsr  rJ   rK   r2   s       @@@@r   .test_eager_to_compute_dependent_to_free_parentr  w  s6    I5% I5% I 	5% I 	5% 	I
 	5% I 	5% I 	5% I 	5% I 	5% I 	5zI 	5zI 	5zI 	5zI 	5zI 	5zI  	5z!I" 	5z#I I$ 	5z%I& 	5z'I( 	5z)I* 	5z+I, 	5z-I. 	5z/I0 	5z1I2 	5z3I4 	5z5I6 	5z7I8 	5z9I: 	5z;I< 	5z=I> 	5z?I@ 	5zAIB 	5% CID 	5zEI I IF 	5% GIH 	5zIIJ 	5zKIL 	5zMIN 	5% OIP 	5% QIR 	5% SIT 	5% UIV 	5zWIX 	5zYIZ 	5z[I\ 	5% ]I^ 	5% _I` 	5zaIb 	5zcId 	5zeIf 	5% gI I Ih 	5% iIj 	5zkIl 	5zmIn 	5zoIp 	5zqIr 	5zsIt 	5zuIv 	5zwIx 	5zyIz 	5z{I| 	5z}I~ 	1vI@ 	1vAIB 	1vCID 	1vEIF 	1vGIH 	1vII IJ 1v1v1v1vQI I ICT  (}}L*c

AWWWW:+;+;+=+=WWWG          DCCCC7CCCM=''))**EuSbSz??b  CJJ"$4$4$4$4  $4$4r   c                8   | \  }}}}}|dft           f|dft           f|dft           f|dft           f|dft           f|dft           |df|df|dff|dft           |df|df|dff|dft           |df|df|dff|dft           |df|dff|dft           |dffi
}t          |          }||df         t          |          dz
  k    sJ ||df         t          |          dz
  k    sJ ||df         t          |          dz
  k    sJ t          |          \  }}	|	g dk    sJ 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i
k    sJ 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i
k    sJ 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i
k    sJ 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i
k    sJ 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i
k    sJ dS )z
        a1  b1  c1  d1  e1
        /|\ /|\ /|\ /|  /
       / | X | X | X | /
      /  |/ \|/ \|/ \|/
    a0  b0  c0  d0  e0
    r   r'   r(   r)   )
r   r'   r(   r)   r(   r)   r(   r)   r(   r'   c                $    i | ]\  }}||j         S r   r   r!   r&  r   s      r   r$   z$test_diagnostics.<locals>.<dictcomp>  s     888xsCC888r   r&   r   r   r   r   r   c                $    i | ]\  }}||j         S r   )ager  s      r   r$   z$test_diagnostics.<locals>.<dictcomp>  s     666XS#C666r   c                $    i | ]\  }}||j         S r   )num_dependencies_freedr  s      r   r$   z$test_diagnostics.<locals>.<dictcomp>  !    IIISC+IIIr   c                $    i | ]\  }}||j         S r   )num_data_when_runr  s      r   r$   z$test_diagnostics.<locals>.<dictcomp>  s!    DDD83C&DDDr   c                $    i | ]\  }}||j         S r   )num_data_when_releasedr  s      r   r$   z$test_diagnostics.<locals>.<dictcomp>*  r  r   N)r   r   rj   r   r   )
r   r#   r.   r/   r0   r1   r7   r2   infomemory_over_times
             r   test_diagnosticsr    sI    MAq!Q	
A	
A	
A	
A	
A	
AQFQFQF+	
AQFQFQF+	
AQFQFQF+	
AQFQF#	
AQFC 	c

AaV9C1$$$$aV9C1$$$$aV9C1$$$$(--D
=======884::<<888	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A=     76666	
A	
A	
A	
A	
A	
A	
A	
A	
A	
A;     JIDJJLLIII	
A	
A	
A	
A	
A	
A	
A	
A	
A	
AN     EDtzz||DDD	
A	
A	
A	
A	
A	
A	
A	
A	
A	
AI     JIDJJLLIII	
A	
A	
A	
A	
A	
A	
A	
A	
A	
AN      r   c                 X   t          d          \  } }}}}i }t          d          D ]}| d|ft          f| d|ft          f|d|ft          | d|ff|d|ft          | d|f| d|ff|d|ft          | d|ff|d|ft          |d|ff|d|ft          |d|ff|d|ft          |d|ffi}|                    |           t          d          D ]-}|                    ||ft          ||df||df||dffi           .t	          |          }t          ||          \  }	}
t          |
          dk    sJ d S )Nr   r)   r   r'   r(   r   r   )rT   r+   r   r,   r   r   r   )r#   r.   r/   r0   r1   r7   ixpartr2   r~   r   s              r   test_xarray_like_reductionr  8  s   MMMAq!Q
CAhh   2J2J2JQ2J2JQ2JAr
32JQ2J2JQ2J2JQ2J2JQ2J

 	

4Ahh 
 


B!aQZ!RaQZ@	
 	
 	
 	

 	c

AcQ'''KAxx==Ar   optimizeTc                   t          j        d          }dd lm} d}|                    t          g d|j                            |dddfd	          fg d|j                            |dddfd	          f
                    }|dz  }|j        |j        z  |d<   |	                    d          }t          t          |g|                     }t          t          |                                g|                     }t          |d                   t          |d                   k    sJ t          |d                   dk     sJ d S )Nxarrayr   i  )timefacejr"   r'       )rP   r'   r)  r)  r  )anom_uanom_vr(   uvr  )optimize_graph2   )rq   rr   
dask.arrayarrayDatasetrw   rs   r  r  meanr   r   to_dask_dataframer   )	r  xrrz   ra   dsquadr  
diag_arraydiag_dfs	            r   test_array_vs_dataframer  T  su   
 
	X	&	&BD	***	  $3!5o NN
 +**	  $3!5o NN		
 		
 		

 
B q5DRY&DJ99VD/xPPPQQJD22445hOOO G wqz??c*Q-000000z!}""""""r   c            
         t          j        d          } t          j        d          }dd lm} ddlm} |j                            dd |d          dz  f	          }|j        d         d
z  }|                    |ddgdd| 	                    |j        d                   |z  fi          }|j                            dd	          }|                    |ddgdd| 	                    d          dz  fi          }|
                    d                              d          }|
                    d          |z
  }|                    d          }	t          |	                                          \  }
}t          |          dk    sJ d S )Nr1  r  r   )parse_bytes)i  i   r'   10MiBr   r  r&   r  rO   day)dimscoords)r   r'   r'   r'   r   r(   )dimr   )rq   rr   r  r  
dask.utilsr  rs   shape	DataArrayarangegroupbyr  r   rx   r   )r  r  rz   r  r  ngroupsarrclimanom	anom_meanr~   r   s               r   test_anom_meanr  v  s   		W	%	%B		X	&	&B&&&&&&9;;w''1,-   D
 jmq G
,,c]		$*Q- 8 87 BCD   C
 9F622D
,,c]		!q 012   C ;;u""v"..D;;u$D		f	%%Ii668899KAxx==Ar   c            	        i dt           ddfdt           ddfdt           dd	fd
t           ddfdt           ddfdt           t           dd dg i fdt           t           dd dg i fdt           t           dd dg i fdt           t           dd dg i fdt           t           dd dg i fdt           dfdt           dfdt           dfdt           dfdt           dfdt           dfdt           dfi dt           dfdt           g dfdt           dfdt           dfdt           dfd t           dfdt           dd gfdt           dfdt           dfd	t           dfdt           dfdt           dfd!t           dfd"t           dfd#t           dfd$t           d
fd%t           dft           g d&ft           d%gft           d'd(gfd)} t          |           }g d*}|D ]*}||         |d         k     sJ ||         |d         k     sJ +d S )+Nr0   r   r   )r#   r   r   )r   r   r   )r0   r'   r   )r#   r'   r   )r   r'   r   r0   r(   r   )r#   r(   r   )r   r(   r   )r0   r)   r   )r#   r)   r   )r   r)   r   r0   r&   r   )r#   r&   r   )r   r&   r   random_sampler  )r1   r   r   )g1r   )r1   r'   r   )g3r   )b0r   r   )r  r'   r   )r  r(   r   c0r   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  r   r   r   r   r'   r   )r  r  )g2r   )r  r  r  r  r5   )r7   r2   (nodes_to_finish_before_loading_more_datans       r   test_anom_mean_rawr    sF   &al3&al3& 	al3& 	al3	&
 	al3& 	aOT62rB& 	aOT62rB& 	aOT62rB& 	aOT62rB& 	aOT62rB& 	a^& 	a^& 	q+&& 	q+&& 	q+&&  	q,'!&" 	q,'#& &$ 	q,'%&& 	AAAAB'&( 	q+&)&* 	q+&+&, 	q,'-&. 	q,'/&0 	Al341&2 	q+&3&4 	q+&5&6 	q+&7&8 	q+&9&: 	q+&;&< 	q+&=&> 	q+&?&@ 	q+&A&B 	q+&C&D 	q+&E& &F QQQR,([12K& & &CP 	c

A0 0 0, 6 % %tan$$$$tan$$$$$% %r   c                    i dt           ddgfdt           g dfdddt           ddfd	t           d
dfdt           ddfdt           ddfdt           ddgfdt           g dfdddt           ddfdt           d
dfdt           ddfdt           ddfdt           dfd
t           dfdt           dfi dt           dfdt           dfdt           dd gfdt           g d!fd d"d#t           dfd$t           dfd%t           dfd&t           dfdt           dfdt           dfdt           dfdt           dfd't           dfdt           t           d'dfgfd"t           t           d'dfgfdt           t           ddfgf} i d(t           d)d*gfd)t           g d+fd*d,d-t           d.d/fd0t           d1d2fd3t           d4d5fd6t           d7d8fd9t           d:d;gfd:t           g d<fd;d=d>t           d/dfd?t           d2dfd@t           d5dfdAt           d8dfd/t           dBdCg fd2t           dBdCg fd5t           dBdCg fi d8t           dBdCg fdDt           dBdCg fdEt           dFdGgfdFt           g dHfdGdIdJt           d.dfdKt           d1dfdLt           d4dfdMt           d7dfd.t           dBdCg fd1t           dBdCg fd4t           dBdCg fd7t           dBdCg fdNt           dBdCg fdIt           t           dNdfgfd,t           t           dNdDfgfd=t           t           dDdfgf}t          t          |           d                   }t          t          |          d                   }||k    sJ d S )ON)z3mean_agg-aggregate-10d721567ef5a0d6a0e1afae8a87c066r   r   r   )5mean_combine-partial-17c7b5c6eed42e203858b3f6dde16003r   r   r   r   )r  r'   r   r   r   )+mean_chunk-98a32cd9f4fadbed908fffb32e0c9679r   r   r   r   r  r'   r   r   r   r  r(   r   r   r   r  r)   r   r   r   )z@mean_chunk-mean_combine-partial-17c7b5c6eed42e203858b3f6dde16003r'   r   r   r   r  ).random_sample-e16bcfb15a013023c98a21e2f03d66a9r   r   r   r   ).random_sample-02eaa4a8dbb23fac4db22ad034c401b3r   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   )z3mean_agg-aggregate-fdb340546b01334890192fcfa55fa0d9r   r   r   )5mean_combine-partial-23adb4747560e6e33afd63c5bb179709r   r   r   r   )r  r'   r   r   r   )+mean_chunk-7edba1c5a284fcec88b9efdda6c2135fr   r   r   r   r  r'   r   r   r   r  r(   r   r   r   r  r)   r   r   r   )z@mean_chunk-mean_combine-partial-23adb4747560e6e33afd63c5bb179709r'   r   r   r   r  r(   r  r  r  r'   )r  r&   r   r   r   )z3mean_agg-aggregate-cc19342c8116d616fc6573f5d20b5762r   r   r   )5mean_combine-partial-0c98c5a4517f58f8268985e7464daacer   r   r   r   )r  r'   r   r   r   )+mean_chunk-540e88b7d9289f6b5461b95a0787af3er   r   r   r   r  r'   r   r   r   r  r(   r   r   r   r  r)   r   r   r   )z@mean_chunk-mean_combine-partial-0c98c5a4517f58f8268985e7464daacer'   r   r   r   r  r  r  r  )r  r&   r   r   r   )z3mean_agg-aggregate-e79dd3b9757c9fb2ad7ade96f3f6c814r   r   r   )5mean_combine-partial-e7d9fd7c132e12007a4b4f62ce443a75r   r   r   r   )r  r'   r   r   r   )+mean_chunk-0df65d9a6e168673f32082f59f19576ar   r   r   r   r  r'   r   r   r   r  r(   r   r   r   r  r)   r   r   r   )z@mean_chunk-mean_combine-partial-e7d9fd7c132e12007a4b4f62ce443a75r'   r   r   r   r   ).random_sample-a155d5a37ac5e09ede89c98a3bfcadffr   r   r   r   ).random_sample-241fdbadc062900adc59d1a79c4c41e1r   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   )z3mean_agg-aggregate-c7647920facf0e557f947b7a6626b7ber   r   r   )5mean_combine-partial-57413f0bb18da78db0f689a096c7fbbfr   r   r   r   )r  r'   r   r   r   )+mean_chunk-d6bd425ea61739f1eaa71762fe3bbbd7r   r   r   r   r	  r'   r   r   r   r	  r(   r   r   r   r	  r)   r   r   r   )z@mean_chunk-mean_combine-partial-57413f0bb18da78db0f689a096c7fbbfr'   r   r   r   r  r
  r  r  r  )rP   r'   r  r  )r  r&   r   r   r   )z3mean_agg-aggregate-05071ebaabb68a64c180f6f443c5c8f4r   r   r   )5mean_combine-partial-a7c475f79a46af4265b189ffdc000bb3r   r   r   r   )r  r'   r   r   r   )+mean_chunk-fd17feaf0728ea7a89d119d3fd172c75r   r   r   r   r  r'   r   r   r   r  r(   r   r   r   r  r)   r   r   r   )z@mean_chunk-mean_combine-partial-a7c475f79a46af4265b189ffdc000bb3r'   r   r   r   r  r  r  r  )r  r&   r   r   r   )r   r   r   )firstotherfirst_pressuresecond_pressures       r   test_flaky_array_reductionr    s+   lHUUK
l 	N  P
l" 	N P
#l0 	DJJF
1l: 	DJJF
;lD 	DJJF
ElN 	DJJF
OlX 	IUUK
Ylf 	N  P
glx 	N P
ylF 	DJF
GlP 	DJF
QlZ 	DJF
[ld 	DJF
eln 	GAolp 	GAqlr 	GAsl lt 	GAulv 	GAwlx 	IUUK
ylF 	N  P
GlX 	N P
Ylf 	DJF
gln 	DJF
olv 	DJF
wl~ 	DJF
lF 	GAGlH 	GAIlJ 	GAKlL 	GAMlN 	GAOlP	
  RR	
]lp	
 OQRST
}lD	
 OQRST
Ql lE\bHUUK
b 	N  P
b" 	N P
#b0 	DJJF
1b: 	DJJF
;bD 	DJJF
EbN 	DJJF
ObX 	IUUK
Ybf 	N  P
gbx 	N P
ybF 	DJF
GbP 	DJF
QbZ 	DJF
[bd 	DJF
ebn 	G	I
obz 	G	I
{bF 	G	I
Gb bR 	G	I
Sb^ 	G	I
_bj 	IUUK
kbx 	N  P
ybJ 	N P
KbX 	DJF
Ybb 	DJF
cbl 	DJF
mbv 	DJF
wb@ 	G	I
AbL 	G	I
MbX 	G	I
Ybd 	G	I
ebp 	G	I
qb|	
 OQRST
IbP	
  RR	
]bp	
 OQRST
}b bEF U++A.//N+e,,Q/00O_,,,,,,r   c                    i dt           dfdt           dfdt           dfdt           dfdt           dfdt           t           dfgfdt           t           dfgfd	t           t           dfgfd
t           t           dfgfdddddd
dd	dt           dfdt           dfdt           dfdt           dft           t           ddddfgft           t           ddddfgfddt           ddft           ddft           ddft           ddft           ddft           ddfd
} t          |           t          fdt          d          D                       t	          fdt          d          D                       k     sJ d S )NA0r'   )A1r   )r  r'   )A2r   )r  r'   )B1r   )r  r'   )B2r'   )r  r   )B11r   )r  r'   )B22r   )r  r'   )C1r   )r   r'   )C2r   )r!  r'   Er   r#  r'   EEr   r&  r'   )
r$  r"  r%  r'  )F1r   )r(  r'   )r(  r(   )F2r   )r)  r'   )r)  r(   c              3  ,   K   | ]}d |f         V  dS )r(  Nr   r!   r  r2   s     r   rl   z&test_flox_reduction.<locals>.<genexpr>  s+      00q$}000000r   r)   c              3  ,   K   | ]}d |f         V  dS )r)  Nr   r+  s     r   rl   z&test_flox_reduction.<locals>.<genexpr>  s+      6X6Xq$}6X6X6X6X6X6Xr   )r   r   r   r+   r   r   s    @r   test_flox_reductionr-  f  s   q!fAq6 	Aq6 	Aq6	
 	Aq6 	AI'( 	AI'( 	AI'( 	AI'( 	I 	I 	I 	I 	Az? 	Az?  	Az?!" 	Az?#$ 9iIFGH9iIFGHtZ(tZ(tY'tZ(tZ(tY'7  C: 	c

A0000uQxx0000036X6X6X6XuUVxx6X6X6X3X3XXXXXXXr   )F);
__future__r   rq   r   	dask.baser   	dask.corer   
dask.orderr   r   r   dask.utils_testr	   r
   fixturer   r   r   r3   r8   r=   r?   rA   rC   rE   rL   rX   r\   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r>  r  r  r  markparametrizer  r  r  r  r-  r   r   r   <module>r6     sv   " " " " " "   ( ( ( ( ( (       8 8 8 8 8 8 8 8 8 8 $ $ $ $ $ $ $ $ )***  +*+ + + +	 	 	+ + +"(! (! (!V  8! ! !@$+ $+ $+N  0  $, , ,
 
 
J J J  (    $M M M<- - -`") ") ")J8 8 8@ @ @! ! !$9! 9! 9!x": ": ":J%9 %9 %9P  *$& $& $&NQ Q Q  4! 4! 4!nX@ X@ X@v6% 6% 6%r, , ,8e5 e5 e5PV V Vr  8 	5M # #	 #<  B5% 5% 5%pT- T- T-n Y  Y  Y  Y  Yr   