
    bIgdK                    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                  ,   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y)AveragePoolc                    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   g      !@r    )g      #@r!   g      %@r#         '@)r$   g      )@r%         +@r&   )      -@r'   g      /@r)   g     0@)r*   g     1@r+   g     2@r,   $test_averagepool_2d_precomputed_padsr   r   nameNonnxhelper	make_nodenparrayastypefloat32r   noder   r   s      d/var/www/html/answerous/venv/lib/python3.12/site-packages/onnx/backend/test/case/node/averagepool.py&export_averagepool_2d_precomputed_padsz2AveragePool.export_averagepool_2d_precomputed_pads   s     {{$$5EQ % 
 HH ((,,,

 &
 	
 HH ,1020

 &
 	
 	!qc0V	
    c                    t         j                  j                  ddgdgddgg d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   count_include_padr   r   r"   r(   r.   )g)\(@g@g333333@gRQ@gQ	@)g=
ףp=@g@ @g)\(@gGz@)g@g      $@g      *@皙%@rK   )gףp=
@g333333#@g(@g{Gz$@gGz@)g{Gz@rK   rL   g(\!@g\(\@6test_averagepool_2d_precomputed_pads_count_include_padr9   Nr;   rC   s      rE   8export_averagepool_2d_precomputed_pads_count_include_padzDAveragePool.export_averagepool_2d_precomputed_pads_count_include_pad@   s     {{$$5EQ % 
 HH ((,,,

 &
 	
 HH A@CBA

 &
 	
 	3CI		
rG   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)zEinput_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_averagepool_2d_precomputed_stridesr9   Nr;   rC   s      rE   )export_averagepool_2d_precomputed_stridesz5AveragePool.export_averagepool_2d_precomputed_stridesp   s    
 {{$$5EQF % 
 HH ((,,,

 &
 	
 HHAR)*+,33BJJ?3C:		
rG   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   rQ   auto_padr   r   r"   r(   r.   )r   g      @r   )r5   r%   r7   )r,   g     4@r0   *test_averagepool_2d_precomputed_same_upperr9   Nr;   rC   s      rE   ,export_averagepool_2d_precomputed_same_upperz8AveragePool.export_averagepool_2d_precomputed_same_upper   s     {{$$5EQF! % 
 HH ((,,,

 &
 	
 HH%5~FGHIPPJJ
 	3C=		
rG   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AVGtest_averagepool_1d_defaultr9   r<   r=   r>   r?   randomrandnrA   rB   shaper   r	   r   
rD   r   x_shaper   r   rQ   	out_shape_paddedr   s
             rE   export_averagepool_1d_defaultz)AveragePool.export_averagepool_1d_default   s    
 {{$$5E	 % 
 IIOOAq"%,,RZZ8((1+s#8'!"+|W
	1 ,EJtQC!3PQrG   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   rZ   r   r   r[   Nr   r   r   r   r\   test_averagepool_2d_defaultr9   r^   rb   s
             rE   export_averagepool_2d_defaultz)AveragePool.export_averagepool_2d_default   s    
 {{$$5EQ	 % 
 IIOOAq"b)00<((1+8'!"+|W
	1 ,EJtQC!3PQrG   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   rZ   r   r   r[   Nr   r   r   r   r\   test_averagepool_3d_defaultr9   r^   rb   s
             rE   export_averagepool_3d_defaultz)AveragePool.export_averagepool_3d_default   s    
 {{$$5E"	 % 
 IIOOAq"b"-44RZZ@((1+ 8'!"+|W
	1 ,EJtQC!3PQrG   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                        }||	||
f}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   rU   r   r   r   rV   r   r   r[   ri   rj   Nr   r   r   constantmodeconstant_valuesr\   test_averagepool_2d_same_upperr9   r<   r=   r>   r?   r_   r`   rA   rB   ra   r   r   padnanr	   r   )rD   r   rc   r   rQ   rd   	pad_shapepad_top
pad_bottompad_left	pad_rightrf   r   r   s                 rE    export_averagepool_2d_same_upperz,AveragePool.export_averagepool_2d_same_upper   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!3STrG   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                        }||
||	f}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_LOWERrs   r   r   r[   ri   rj   Nr   rt   ru   rv   r\   test_averagepool_2d_same_lowerr9   rz   )rD   r   rc   r   rQ   rd   r}   r   r~   r   r   rf   r   r   s                 rE    export_averagepool_2d_same_lowerz,AveragePool.export_averagepool_2d_same_lower&  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!3STrG   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}d}d}d}||||g}	t        |	|dd ||d      \  }
}	t        j                  |dd|	d   |	d   f|	d   |	d   ffdt        j                        }t        |||||
d|	      }t        | |g|gd       y){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   rj   r   NF	ceil_modert   r   ru   rv   r\   test_averagepool_2d_padsr9   )r<   r=   r>   r?   r_   r`   rA   rB   ra   r   r{   r|   r	   r   )rD   r   rc   r   rQ   r   r~   r   r   r   rd   rf   r   s                rE   export_averagepool_2d_padsz&AveragePool.export_averagepool_2d_padsL  s#    {{$$5EQ % 
 IIOOAq"b)00<((1+
	:y9;'!"+|W
	4 Vd1gtAw/$q'471CDFF	
 ,E4PtQC!3MNrG   c            
        t         j                  j                  ddgdgddgg dd      } t        j                  j                  dddd      j                  t        j                        }t        j                  |      }d	}d
}d	}d}d}d}d}	||	||g}
t        |
|dd |||d      \  }}
t        j                  |dd|
d   |
d   f|
d   |
d   ffdd      }t        |||||d|
d      }t        | |g|gd       y)r   r   r   r   r   r   r   rI   r   rj   r   r   NFr   rt   r   ru   rv   r\   )rJ   *test_averagepool_2d_pads_count_include_padr9   )r<   r=   r>   r?   r_   r`   rA   rB   ra   r   r{   r	   r   )rD   r   rc   	dilationsr   rQ   r   r~   r   r   r   rd   rf   r   s                 rE   ,export_averagepool_2d_pads_count_include_padz8AveragePool.export_averagepool_2d_pads_count_include_pado  s<    {{$$5EQ % 
 IIOOAq"b)00<((1+	
	:y9;'!"+|Wi5
	4 Vd1gtAw/$q'471CD	
 	
 	3C=		
rG   c            	     |   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
}t        d|d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   rP   r   r[   )r   r   r   Nr   Fr   r\   test_averagepool_2d_stridesr9   r^   )	rD   r   rc   r   rQ   rd   r   rf   r   s	            rE   export_averagepool_2d_stridesz)AveragePool.export_averagepool_2d_strides  s    
 {{$$5EQF % 
 IIOOAq"b)00<((1+;'!"+|W
	4 ,E4PtQC!3PQrG   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   rQ   r   r   r   r   r   r   r   r   r   r    r!   r#   r$   r%   r&   r'   r)   r   r4   r$   r6   test_averagepool_2d_ceilr9   Nr;   rC   s      rE   export_averagepool_2d_ceilz&AveragePool.export_averagepool_2d_ceil  s    
 {{$$5EQF % 
 HH %$'(		
 &
 	
 HHC2t*-./077

CtQC!3MNrG   c            	     v   t         j                  j                  ddgdgd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)r   r   r   r   r   r   Tr   r   r   rQ   r   r   r   r   r   r   r   r   r!   r#   test_averagepool_2d_dilationsr9   Nr;   rC   s      rE   export_averagepool_2d_dilationsz+AveragePool.export_averagepool_2d_dilations  s    
 {{$$5EQF!f % 
 HH %$'(		
 &
 	
 HHAR)*+,33BJJ?tQC!3RSrG   c            
        t         j                  j                  ddgdgg dg dg d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)r   r   r   r   rn   ro   Tr   r   r   r   r   r   r   r!   r#   #test_averagepool_3d_dilations_smallr9   Nr;   rC   s      rE   export_averagepool_3d_dilationsz+AveragePool.export_averagepool_3d_dilations  s   
 {{$$5E" % 
 HH
 )(+,	 )(+,	 )(+,	 )(+,	'
> &
? 	
B HH!Q"b*aVb"X,>?@ABII"**U!qc0U	
rG   c                 (   d} d}d}d}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k(  rdnt        j                        }
t        |
ddg| |||d|	||	      }d| d| }t        ||g|g|         y )N)r[   r[   r[   rn   )r   r   r   )r   r   r   r   )r   r   )TFr   r   r   )r   r   r   rQ   r   rJ   r   r   )r   r   rt   r   r   r   r   ru   rv   r\   )r   r   rJ   9test_averagepool_3d_dilations_large_count_include_pad_is__ceil_mode_is_r9   )r<   r=   r>   r?   r_   r`   rA   rB   r   r{   r|   r	   r   )rc   r   r   rQ   rJ   r   rD   r   rd   r   rf   r   	test_names                rE   %export_averagepool_3d_dilations_largez1AveragePool.export_averagepool_3d_dilations_large/  s   	 !' /	F* .F	{{,,!5 E!-#'&7' - 	 IIOOAq373::2::F"C ''#	4 a$q'*a$q'*a$q'* $):a)?ARVV $G$ '&7
 XXiWjjx  zC  yD  E	tQC!9E].F/	FrG   N)returnNone)__name__
__module____qualname__staticmethodrF   rN   rS   rX   rg   rl   rq   r   r   r   r   r   r   r   r   r    rG   rE   r   r      s^   )
 )
V -
 -
^ 
 
B #
 #
J R R. R R. R R. #U #UJ #U #UJ  O  OD 0
 0
d R R. O O8 T T@ 4
 4
l 6F 6FrG   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   rG   rE   <module>r      s0    #   , . S	F$ S	FrG   