
    NgVU                     b    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dS )    N)Base)expect)get_output_shape_auto_pad!get_output_shape_explicit_paddingget_pad_shapepoolc                      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dS )MaxPoolreturnNc                     t           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                              t          j                  }t          j        g dg dg dg dg dggg                              t          j                  }t          | |g|gd           dS )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/ai-engine/env/lib/python3.11/site-packages/onnx/backend/test/case/node/maxpool.pyexport_maxpool_2d_uint8zMaxPool.export_maxpool_2d_uint8   s'    {$$5EQ % 
 
 H ((((,,,,,,,,,

 
 &

 	
 H -,,,,,,,,,,,,,,

 
 &

 	
 	tQC!3JKKKKKK    c                     t           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                              t          j                  }t          j        g dg dg dg dg dggg                              t          j                  }t          | |g|gd           dS )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 % 
 
 H ((((,,,,,,,,,

 
 &

 	
 H -,,,,,,,,,,,,,,

 
 &

 	
 	tQC!3UVVVVVVrE   c                     t           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                              t          j                  }t          j        g dg dg dg dg dggg                              t          j                  }t          j        g dg dg dg dg dggg                              t          j                  }t          | |g||gd           dS )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_padsg   s    {$$5#JQ % 
 
 H ((((,,,,,,,,,

 
 &

 	
 H -,,,,,,,,,,,,,,

 
 &

 	
 H -,,,,,,,,,,,,,,

 
 &

 	
 	3F?		
 	
 	
 	
 	
 	
rE   c                  z   t           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                              t          j                  }t          j        ddgddgggg                              t          j                  }t          | |g|gd           dS )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 % 
 
 H ((((,,,,,,,,,

 
 &

 	
 HAR)*+,,33BJ??!qc0U	
 	
 	
 	
 	
 	
rE   c                     t           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                              t          j                  }t          j        ddgddgggg                              t          j                  }t          j        ddgddgggg                              t          j                  }t          | |g||gd           dS )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 % 
 
 H ((((,,,,,,,,,

 
 &

 	
 HAR)*+,,33BJ??HB!R)*+,,33BH==3FB		
 	
 	
 	
 	
 	
rE   c                     t           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                              t          j                  }t          j        g dg dg dggg                              t          j                  }t          | |g|gd           dS )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! % 
 
 H ((((,,,,,,,,,

 
 &

 	
 H


LLL,,,?@ABBII"*UU!qc0X	
 	
 	
 	
 	
 	
rE   c                     t           j                            ddgdgdg          } t          j                            ddd                              t          j                  }t          j        |          }d	}dg}dg}t          ||dd	         ||          \  }}|}t          |||||d
          }	t          | |g|	gd           d	S )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	 % 
 
 IOOAq"%%,,RZ88(1++s#8'!""+|W
 
	1 ,EJJtQC!3LMMMMMMrE   c                     t           j                            ddgdgddg          } t          j                            dddd                              t          j                  }t          j        |          }d	}d
}d}t          ||dd	         ||          \  }}|}t          |||||d          }	t          | |g|	gd           d	S )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	 % 
 
 IOOAq"b))00<<(1++8'!""+|W
 
	1 ,EJJtQC!3LMMMMMMrE   c                     t           j                            ddgdgg d          } t          j                            ddddd                              t          j                  }t          j        |          }d	}g d}g d
}t          ||dd	         ||          \  }}|}t          |||||d          }	t          | |g|	gd           d	S )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_default3  s    
 {$$5E"	 % 
 
 IOOAq"b"--44RZ@@(1++ yy))8'!""+|W
 
	1 ,EJJtQC!3LMMMMMMrE   c            	      z   t           j                            ddgdgddgd          } t          j                            ddd	d	                              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           dS )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_upperK  sy    {$$5EQ! % 
 
 IOOAq"b))00<<(1++-'!""+|W
 
	 "'!""+|Wi
 
	 A,!#q\G+
Q<1$aL8+	Vgz2Xy4IJF	
 
 
 :y9,E4PPtQC!3OPPPPPPrE   c            	      z   t           j                            ddgdgddgd          } t          j                            ddd	d	                              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           dS )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_lowerq  sy    {$$5EQ! % 
 
 IOOAq"b))00<<(1++-'!""+|W
 
	 "'!""+|Wi
 
	 q\Q&
A,+aLA%	Q<)+Vgz2Xy4IJF	
 
 
 :y9,E4PPtQC!3OPPPPPPrE   c            	         t           j                            ddgdgddgg d          } t          j                            dddd                              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           dS )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  s9    {$$5EQ % 
 
 IOOAq"b))00<<(1++677
7W7y8:y9;'!""+|W
 
	4 Vgz2Xy4IJF	
 
 
 ,E4PPtQC!3IJJJJJJrE   c                     t           j                            ddgdgddgddg          } t          j                            dddd                              t          j                  }t          j        |          }d	}d
}d}t          ||dd	         ||          \  }}|}t          |||||d          }t          | |g|gd           d	S )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 % 
 
 IOOAq"b))00<<(1++;'!""+|W
 
	4 ,EJJtQC!3LMMMMMMrE   c                  v   t           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                              t          j                  }t          j        ddgddgggg                              t          j                  }t          | |g|gd           dS )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 % 
 
 H %$'(((		
 
 &

 	
 HR2r(+,-..55bjAAtQC!3IJJJJJJrE   c                  b   t           j                            ddgdgddgddgd          } t          j        ddgdd	gggg                              t          j                  }t          j        dgggg                              t          j                  }t          | |g|gd
           dS )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 % 
 
 HAA'()**11"*==HugY&&rz223CA		
 	
 	
 	
 	
 	
rE   c            	      z   t           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                              t          j                  }t          j        ddgddgggg                              t          j                  }t          | |g|gd           dS )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 % 
 
 H %$'(((		
 
 &

 	
 HR2r(+,-..55bjAAtQC!3NOOOOOOrE   c            
         t           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                              t          j                  }t          j        ddgddggddgddggggg                              t          j                  }t          | |g|gd           dS )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"IIii % 
 
 H
 )LL(LL+OO,,,	 )LL(LL+OO,,,	 )LL(LL+OO,,,	 )LL(LL+OO,,,	'
 
> &

? 	
@ H"bB8,Bx"b.BCDEFFMMJ
 
 	tQC!3NOOOOOOrE   c            
         g d} g d}g d}d}t           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                              t          j                  }|j        dd         }t          d|||| |          \  }}|}	t          |	ddg|R |||d||           }
t          ||g|
gd           dS )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_implQ  s   
 II	 yy))	{$$5E"II % 
 
 H
 )LL(LL+OO,,,	 )LL(LL+OO,,,	 )LL(LL+OO,,,	 )LL(LL+OO,,,	'
 
> &

? 	
B '!""+;'<)y
 
 
	4 G	
 	
 	
 	!qc0X	
 	
 	
 	
 	
 	
rE   c            
         d} d}d}d}d}t           j                            ddgdg||||	          }t          j        j        d
d
g| R                      t          j                  }t          d | ||||          \  }}t          j	        |dd|d         |d         f|d
         |d         f|d         |d         ffdd          }	t          |	d
d
g| R |||d||          }
t          ||g|
gd           d S )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  sn   	 	{$$5E% % 
 
 IOAq+7+++222:>>;'<)y
 
 
	4 a$q'"a$q'"a$q'" 
 
 
 G	
 	
 	
 	3C?		
 	
 	
 	
 	
 	
rE   )r   N)__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 'L \'LR 'W 'W 'W \'WR 9
 9
 9
 \9
v 
 
 
 \
4 !
 !
 !
 \!
F 
 
 
 \
@ N N N \N. N N N \N. N N N \N. #Q #Q #Q \#QJ #Q #Q #Q \#QJ K K K \K@ N N N \N( K K K \K8 
 
 
 \
, P P P \P8 0P 0P 0P \0Pd C
 C
 C
 \C
J 1
 1
 1
 \1
 1
 1
rE   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

 w

 w

 w

 w

d w

 w

 w

 w

 w

rE   