
    bIgyU                    f    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mZ  G d de      Zy)    )annotationsN)Base)expect)get_output_shape_auto_pad!get_output_shape_explicit_paddingget_pad_shapepoolc                  b   e Zd Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Z	edd       Z
edd       Zedd	       Zedd
       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zy)MaxPoolc                    t         j                  j                  ddgdgddgg d      } t        j                  g dg dg d	g d
g dggg      j                  t        j                        }t        j                  g dg dg dg dg dggg      j                  t        j                        }t        | |g|gd       y)winput_shape: [1, 1, 5, 5]
        output_shape: [1, 1, 5, 5]
        pad_shape: [4, 4] -> [2, 2, 2, 2] by axis
        r   xy      r   r   r   inputsoutputskernel_shapepads   r         r            	   
                                                r%   r&   r'   r'   r'   r+   r,   r-   r-   r-   r1   r2   r3   r3   r3   test_maxpool_2d_uint8r   r   nameN)onnxhelper	make_nodenparrayastypeuint8r   noder   r   s      `/var/www/html/answerous/venv/lib/python3.12/site-packages/onnx/backend/test/case/node/maxpool.pyexport_maxpool_2d_uint8zMaxPool.export_maxpool_2d_uint8   s     {{$$5EQ % 
 HH ((,,,

 &
 	
 HH -,,,,

 &
 	
 	tQC!3JK    c                    t         j                  j                  ddgdgddgg d      } t        j                  g dg dg d	g d
g dggg      j                  t        j                        }t        j                  g dg dg dg dg dggg      j                  t        j                        }t        | |g|gd       y)r   r   r   r   r   r   r   r   r   r"   r(   r.   r4   r5   r6    test_maxpool_2d_precomputed_padsr8   Nr:   r;   r<   r=   r>   r?   float32r   rA   s      rC   "export_maxpool_2d_precomputed_padsz*MaxPool.export_maxpool_2d_precomputed_pads>   s     {{$$5EQ % 
 HH ((,,,

 &
 	
 HH -,,,,

 &
 	
 	tQC!3UVrE   c                    t         j                  j                  ddgddgddgg d      } t        j                  g dg d	g d
g dg dggg      j                  t        j                        }t        j                  g dg dg dg dg dggg      j                  t        j                        }t        j                  g dg dg dg dg dggg      j                  t        j                        }t        | |g||gd       y)r   r   r   r   zr   r   r   r   r   r"   r(   r.   r4   r5   r6   )r$   r%   r&   r&   r&   )r*   r+   r,   r,   r,   )r0   r1   r2   r2   r2   ,test_maxpool_with_argmax_2d_precomputed_padsr8   N	r:   r;   r<   r=   r>   r?   rI   int64r   rB   r   r   rL   s       rC   .export_maxpool_with_argmax_2d_precomputed_padsz6MaxPool.export_maxpool_with_argmax_2d_precomputed_padsh   s    {{$$5#JQ % 
 HH ((,,,

 &
 	
 HH -,,,,

 &
 	
 HH -,,,,

 &
 	
 	3F?		
rE   c                 t   t         j                  j                  ddgdgddgddg      } t        j                  g dg dg dg d	g d
ggg      j                  t        j                        }t        j                  ddgddgggg      j                  t        j                        }t        | |g|gd       y)Einput_shape: [1, 1, 5, 5]
        output_shape: [1, 1, 2, 2]
        r   r   r   r   r   r   r   stridesr   r   r"   r(   r.   r   r    r*   r,   #test_maxpool_2d_precomputed_stridesr8   NrH   rA   s      rC   %export_maxpool_2d_precomputed_stridesz-MaxPool.export_maxpool_2d_precomputed_strides   s    
 {{$$secU!QRSUVQW % 
 HH ((,,,

 &
 	
 HHAR)*+,33BJJ?!qc0U	
rE   c                    t         j                  j                  ddgddgddgddgd      } t        j                  g dg d	g d
g dg dggg      j                  t        j                        }t        j                  ddgddgggg      j                  t        j                        }t        j                  ddgddgggg      j                  t        j                        }t        | |g||gd       y)rS   r   r   r   rL   r   r   )r   r   r   rU   storage_orderr   r   r"   r(   r.   r   r    r*   r,   r   r)   r   r+   /test_maxpool_with_argmax_2d_precomputed_stridesr8   NrN   rP   s       rC   1export_maxpool_with_argmax_2d_precomputed_stridesz9MaxPool.export_maxpool_with_argmax_2d_precomputed_strides   s    
 {{$$5#JQF % 
 HH ((,,,

 &
 	
 HHAR)*+,33BJJ?HHB!R)*+,33BHH=3FB		
rE   c                 |   t         j                  j                  ddgdgddgddgd      } t        j                  g dg d	g d
g dg dggg      j                  t        j                        }t        j                  g dg dg dggg      j                  t        j                        }t        | |g|gd       y)zwinput_shape: [1, 1, 5, 5]
        output_shape: [1, 1, 3, 3]
        pad_shape: [2, 2] -> [1, 1, 1, 1] by axis
        r   r   r   r   r   
SAME_UPPER)r   r   r   rU   auto_padr   r   r"   r(   r.   )r   r    r!   )r*   r,   r-   )r0   r2   r3   &test_maxpool_2d_precomputed_same_upperr8   NrH   rA   s      rC   (export_maxpool_2d_precomputed_same_upperz0MaxPool.export_maxpool_2d_precomputed_same_upper   s     {{$$5EQF! % 
 HH ((,,,

 &
 	
 HH
L,?@ABII"**U!qc0X	
rE   c                 t   t         j                  j                  ddgdgdg      } t        j                  j                  ddd      j                  t        j                        }t        j                  |      }d	}dg}dg}t        ||dd	 ||      \  }}|}t        |||||d
      }	t        | |g|	gd       y	)zAinput_shape: [1, 3, 32]
        output_shape: [1, 3, 31]
        r   r   r   r   r   r   r   r   r       NMAXtest_maxpool_1d_defaultr8   r:   r;   r<   r=   randomrandnr?   rI   shaper   r	   r   
rB   r   x_shaper   r   rU   	out_shape_paddedr   s
             rC   export_maxpool_1d_defaultz!MaxPool.export_maxpool_1d_default  s    
 {{$$5E	 % 
 IIOOAq"%,,RZZ8((1+s#8'!"+|W
	1 ,EJtQC!3LMrE   c                 t   t         j                  j                  ddgdgddg      } t        j                  j                  dddd      j                  t        j                        }t        j                  |      }d	}d
}d}t        ||dd	 ||      \  }}|}t        |||||d      }	t        | |g|	gd       y	)zIinput_shape: [1, 3, 32, 32]
        output_shape: [1, 3, 31, 31]
        r   r   r   r   rb   r   r   rc   Nr   r   r   r   rd   test_maxpool_2d_defaultr8   rf   rj   s
             rC   export_maxpool_2d_defaultz!MaxPool.export_maxpool_2d_default  s    
 {{$$5EQ	 % 
 IIOOAq"b)00<((1+8'!"+|W
	1 ,EJtQC!3LMrE   c                 ~   t         j                  j                  ddgdgg d      } t        j                  j                  ddddd      j                  t        j                        }t        j                  |      }d	}g d}g d
}t        ||dd	 ||      \  }}|}t        |||||d      }	t        | |g|	gd       y	)zQinput_shape: [1, 3, 32, 32, 32]
        output_shape: [1, 3, 31, 31, 31]
        r   r   r   r   r   r   rb   r   r   rc   Nr   r   r   r   rd   test_maxpool_3d_defaultr8   rf   rj   s
             rC   export_maxpool_3d_defaultz!MaxPool.export_maxpool_3d_default4  s    
 {{$$5E"	 % 
 IIOOAq"b"-44RZZ@((1+ 8'!"+|W
	1 ,EJtQC!3LMrE   c            	     8   t         j                  j                  ddgdgddgd      } t        j                  j                  ddd	d	      j                  t        j                        }t        j                  |      }d
}d}t        d|dd ||      }t        d|dd |||      }|d   dz  }|d   |z
  }|d   dz  }	|d   |	z
  }
t        j                  |dd||f|	|
ffdt        j                        }||	||
g}t        |||||d|      }t        | |g|gd       y)z{input_shape: [1, 3, 32, 32]
        output_shape: [1, 3, 32, 32]
        pad_shape: [1, 1] -> [0, 1, 0, 1] by axis
        r   r   r   r   r]   r   r   r   r^   r   r   rc   rq   rr   Nr   r   r   constantmodeconstant_valuesrd   test_maxpool_2d_same_upperr8   r:   r;   r<   r=   rg   rh   r?   rI   ri   r   r   padnanr	   r   )rB   r   rk   r   rU   rl   	pad_shapepad_top
pad_bottompad_left	pad_rightrn   r   r   s                 rC   export_maxpool_2d_same_upperz$MaxPool.export_maxpool_2d_same_upperL  sN    {{$$5EQ! % 
 IIOOAq"b)00<((1+-'!"+|W
	 "'!"+|Wi
	 A,!#q\G+
Q<1$aL8+	Vgz2Xy4IJFF	
 :y9,E4PtQC!3OPrE   c            	     8   t         j                  j                  ddgdgddgd      } t        j                  j                  ddd	d	      j                  t        j                        }t        j                  |      }d
}d}t        d|dd ||      }t        d|dd |||      }|d   dz  }|d   |z
  }|d   dz  }	|d   |	z
  }
t        j                  |dd||f|
|	ffdt        j                        }||
||	g}t        |||||d|      }t        | |g|gd       y)z{input_shape: [1, 3, 32, 32]
        output_shape: [1, 3, 32, 32]
        pad_shape: [1, 1] -> [1, 0, 1, 0] by axis
        r   r   r   r   
SAME_LOWERr{   r   r   rc   rq   rr   Nr   r|   r}   r~   rd   test_maxpool_2d_same_lowerr8   r   )rB   r   rk   r   rU   rl   r   r   r   r   r   rn   r   r   s                 rC   export_maxpool_2d_same_lowerz$MaxPool.export_maxpool_2d_same_lowerr  sN    {{$$5EQ! % 
 IIOOAq"b)00<((1+-'!"+|W
	 "'!"+|Wi
	 q\Q&
A,+aLA%	Q<)+Vgz2Xy4IJFF	
 :y9,E4PtQC!3OPrE   c            	        t         j                  j                  ddgdgddgg d      } t        j                  j                  dddd      j                  t        j                        }t        j                  |      }d	}d
}dx}x}x}}||||g}	t        |	|dd ||      \  }
}	t        j                  |dd||f||ffdt        j                        }t        |||||
d|	      }t        | |g|gd       y)z{input_shape: [1, 3, 28, 28]
        output_shape: [1, 3, 30, 30]
        pad_shape: [4, 4] -> [2, 2, 2, 2] by axis
        r   r   r   r   r   r   r      r   r   rr   r   Nr|   r}   r~   rd   test_maxpool_2d_padsr8   )r:   r;   r<   r=   rg   rh   r?   rI   ri   r   r   r   r	   r   )rB   r   rk   r   rU   r   r   r   r   r   rl   rn   r   s                rC   export_maxpool_2d_padszMaxPool.export_maxpool_2d_pads  s    {{$$5EQ % 
 IIOOAq"b)00<((1+677
7W7y8:y9;'!"+|W
	4 Vgz2Xy4IJFF	
 ,E4PtQC!3IJrE   c                 z   t         j                  j                  ddgdgddgddg      } t        j                  j                  dddd      j                  t        j                        }t        j                  |      }d	}d
}d}t        ||dd	 ||      \  }}|}t        |||||d      }t        | |g|gd       y	)zIinput_shape: [1, 3, 32, 32]
        output_shape: [1, 3, 10, 10]
        r   r   r   r   r   rT   r   rc   N)r   r   r   r   rd   test_maxpool_2d_stridesr8   rf   )	rB   r   rk   r   r   rU   rl   rn   r   s	            rC   export_maxpool_2d_stridesz!MaxPool.export_maxpool_2d_strides  s    
 {{$$secU!QRSUVQW % 
 IIOOAq"b)00<((1+;'!"+|W
	4 ,EJtQC!3LMrE   c                 p   t         j                  j                  ddgdgddgddgd      } t        j                  g dg d	g d
g dggg      j                  t        j                        }t        j                  ddgddgggg      j                  t        j                        }t        | |g|gd       y)Einput_shape: [1, 1, 4, 4]
        output_shape: [1, 1, 2, 2]
        r   r   r   r   r   Tr   r   r   rU   	ceil_moder   r   r   r   r   r   r   r   r    r!   r#   r$   r%   r&   r'   r)   r#   r$   r'   r)   test_maxpool_2d_ceilr8   NrH   rA   s      rC   export_maxpool_2d_ceilzMaxPool.export_maxpool_2d_ceil  s    
 {{$$5EQF % 
 HH %$'(		
 &
 	
 HHR2r(+,-.55bjjAtQC!3IJrE   c                 \   t         j                  j                  ddgdgddgddgd      } t        j                  ddgdd	gggg      j                  t        j                        }t        j                  dgggg      j                  t        j                        }t        | |g|gd
       y)zEinput_shape: [1, 1, 2, 2]
        output_shape: [1, 1, 1, 1]
        r   r   r   r   r   Tr   r   r   .test_maxpool_2d_ceil_output_size_reduce_by_oner8   NrH   rA   s      rC   0export_maxpool_2d_ceil_output_size_reduce_by_onez8MaxPool.export_maxpool_2d_ceil_output_size_reduce_by_one  s    
 {{$$5EQF % 
 HHAA'()*11"**=HHugY&&rzz23CA		
rE   c            	     t   t         j                  j                  ddgdgddgddgddg      } t        j                  g dg dg d	g d
ggg      j                  t        j                        }t        j                  ddgddgggg      j                  t        j                        }t        | |g|gd       y)r   r   r   r   r   r   r   r   r   rU   	dilationsr   r   r   r   r#   r$   r'   r)   test_maxpool_2d_dilationsr8   NrH   rA   s      rC   export_maxpool_2d_dilationsz#MaxPool.export_maxpool_2d_dilations  s    
 {{$$5EQF!f % 
 HH %$'(		
 &
 	
 HHR2r(+,-.55bjjAtQC!3NOrE   c            
        t         j                  j                  ddgdgg dg dg d      } t        j                  g dg dg d	g d
gg dg dg d	g d
gg dg dg d	g d
gg dg dg d	g d
gggg      j                  t        j                        }t        j                  ddgddggddgddggggg      j                  t        j                        }t        | |g|gd       y)Kinput_shape: [1, 1, 4, 4, 4]
        output_shape: [1, 1, 2, 2, 2]
        r   r   r   rv   rw   r   r   r   r   r   r#   r$   r'   r)   test_maxpool_3d_dilationsr8   NrH   rA   s      rC   export_maxpool_3d_dilationsz#MaxPool.export_maxpool_3d_dilations  s   
 {{$$5E" % 
 HH
 )(+,	 )(+,	 )(+,	 )(+,	'
> &
? 	
@ HH"bB8,Bx"b.BCDEFMMJJ
 	tQC!3NOrE   c            
        g d} g d}g d}d}t         j                  j                  ddgdgg dg d|       }t        j                  g dg d	g d
g dgg dg d	g d
g dgg dg d	g d
g dgg dg d	g d
g dgggg      j                  t        j                        }|j                  dd }t        d|||| |      \  }}|}	t        |	ddg||||d||       }
t        ||g|
gd       y)r   rv   rw   Fr   r   r   r   r   r   r   r   r   Nr   r   rd   r   &test_maxpool_3d_dilations_use_ref_implr8   )r:   r;   r<   r=   r>   r?   rI   ri   r   r	   r   )r   r   rU   r   rB   r   rk   rl   r   rn   r   s              rC   (export_maxpool_3d_dilations_use_ref_implz0MaxPool.export_maxpool_3d_dilations_use_ref_implR  s=   
 	 	{{$$5E" % 
 HH
 )(+,	 )(+,	 )(+,	 )(+,	'
> &
? 	
B ''!"+;'<)y
	4 G	
 	!qc0X	
rE   c            
        d} d}d}d}d}t         j                  j                  ddgdg||||	      }t        j                  j
                  d
d
g|  j                  t        j                        }t        d | ||||      \  }}t        j                  |dd|d   |d   f|d
   |d   f|d   |d   ffdd      }	t        |	d
d
g| |||d||      }
t        ||g|
gd       y )N)rc   rc   rc   rv   )r   r   r   )r   r   r   Tr   r   r   )r   r   r   rU   r   r   r   r   r|   r   r   r   r   r   r}   r~   rd   r   ,test_maxpool_3d_dilations_use_ref_impl_larger8   )r:   r;   r<   r=   rg   rh   r?   rI   r   r   r	   r   )rk   r   r   rU   r   rB   r   rl   r   rn   r   s              rC   .export_maxpool_3d_dilations_use_ref_impl_largez6MaxPool.export_maxpool_3d_dilations_use_ref_impl_large  s0   	 	{{$$5E% % 
 IIOOAq+7+222::>;'<)y
	4 a$q'"a$q'"a$q'" 
 G	
 	3C?		
rE   N)returnNone)__name__
__module____qualname__staticmethodrD   rJ   rQ   rW   r[   r`   ro   rt   ry   r   r   r   r   r   r   r   r   r   r    rE   rC   r   r      s   'L 'LR 'W 'WR 9
 9
v 
 
4 !
 !
F 
 
@ N N. N N. N N. #Q #QJ #Q #QJ K K@ N N( K K8 
 
, P P8 0P 0Pd C
 C
J 1
 1
rE   r   )
__future__r   numpyr=   r:   onnx.backend.test.case.baser   onnx.backend.test.case.noder   !onnx.reference.ops.op_pool_commonr   r   r   r	   r   r   rE   rC   <module>r      s.    #   , . w

d w

rE   