
    Ng                     r    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	 d Z
d Zd Zd Z G d	 d
e          ZdS )    N)Base)expect)apply_affine_transformconstruct_original_gridc                    t          j        t          j        |           t          j        |           t          j        |           t          j        |           t          j        |           t          j        |            t          j        |           t          j        |           t          j        |           g	d                              ddd          }t          j        t          j        |          t          j        |          t          j        |          t          j        |          t          j        |          t          j        |          t          j        |           t          j        |          t          j        |          g	d                              ddd          }t          j        t          j        |          |||t          j        |          |||t          j        |          g	d                              ddd          }t          j        |t          j        |          t          j        |          t          j        |          |	t          j        |          t          j        |          t          j        |          |
g	d                              ddd          }t          j        t          j        |||g                                        ddd          }||z  |z  |z  }t          j        |d          }t          j	        ||f          }t          j        |d          }|
                    t           j                  S )Naxis      r      r   )npstack	ones_like
zeros_likecossinreshape	transposearrayhstackastypefloat32)angle1angle2offset_xoffset_yoffset_zshear_xshear_yshear_zscale_xscale_yscale_zrot_xrot_yshearscaletranslationrotation_matrixaffine_matrixs                     b/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnx/backend/test/case/node/affinegrid.pycreate_affine_matrix_3dr.      s    HL  M&!!M&!!M&!!F6NNVF^^OM&!!F6NNF6NN
	
    gb!Q 
 HF6NNM&!!F6NNM&!!L  M&!!VF^^OM&!!F6NN
	
    gb!Q 
 HL!!L!!L!!
	
    gb!Q 
 HM'""M'""M'""M'""M'""M'""
	
    gb!Q 
 ,rx8X(FGGHHPP
Aq K eme+e3Ol?I>>OI<==ML	::M
+++    c                    t          j        t          j        |           t          j        |            t          j        |           t          j        |           gd                              ddd          }t          j        t          j        |          ||t          j        |          gd                              ddd          }t          j        |t          j        |          t          j        |          |gd                              ddd          }	t          j        t          j        ||g                                        ddd          }
||z  |	z  }t          j        |d          }t          j	        ||
f          }t          j        |d          }|
                    t           j                  S )Nr   r	   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r    r!   r#   r$   rotr(   r)   r*   r+   r,   s                r-   create_affine_matrix_2dr2   _   s    (	"&.."&.."&..IPR  gb!Q  H	g		",w2G2GHr  gb!Q 
 H	"-(("-*@*@'JQS  gb!Q 
 ,rx8(<==>>FFr1aPPKEkE)Ol?I>>OI<==ML	::M
+++r/   c            	         t          j        t           j        dz  t           j        dz  g          } t          j        ddg          }t          j        ddg          }t          j        ddg          }t          j        d	d
g          }t          j        ddg          }t          j        ddg          }t          | ||||||          }|S )N   r         @      @ffffff
皙?            ?333333?333333ӿ皙@@?)r   r   pir2   )angler   r   r    r!   r#   r$   theta_2ds           r-   create_theta_2drC   s   s    Hbeai+,,Exc
##Hxs$$Hhc{##GhT{##GhSz""GhSz""G&x7GWg H Or/   c                     t          j        t           j        dz  t           j        dz  g          } t          j        t           j        dz  t           j        dz  g          }t          j        ddg          }t          j        ddg          }t          j        d	d
g          }t          j        ddg          }t          j        ddg          }t          j        ddg          }t          j        d
dg          }t          j        ddg          }	t          j        ddg          }
t          | |||||||||	|
          }|S )Nr4   r      r   r5   r6   r7   r8   gr=   r9   r:   r;   r<   gffffff?gɿr>   r?   g      ?)r   r   r@   r.   )r   r   r   r   r   r    r!   r"   r#   r$   r%   theta_3ds               r-   create_theta_3drG      s$   Xruqy"%!),--FXruqy"%!),--Fxc
##Hxs$$Hxs$$Hhc{##GhT{##GhT{##GhSz""GhSz""GhSz""G& H Or/   c                   >    e Zd Zedd            Zedd            ZdS )
AffineGridreturnNc                  z   t                      } t          |           dddf\  }}}}||f}dD ]}t          j                            dddgdg|	          }t          ||          }t          | |          }	d
}
|dk    r|
dz  }
t          || t          j	        ||||gt          j
                  g|	g|
           d S )Nr      rE   r   r   rI   thetasizegridinputsoutputsalign_cornerstest_affine_grid_2dr   _align_cornersdtyperR   rS   name)rC   lenonnxhelper	make_noder   r   r   r   r   int64)rB   NCHW	data_sizerT   nodeoriginal_gridrP   	test_names              r-    export_2d_no_reference_evaluatorz+AffineGrid.export_2d_no_reference_evaluator   s    "$$]]Aq!+
1aF	# 	 	M;(((+	 )  D 4I}MMM)(MBBD-I!!--	 "(Aq!Q<rx"H"H"HI	    	 	r/   c                     t                      } t          |           ddddf\  }}}}}|||f}dD ]}t          j                            dddgd	g|
          }t          ||          }	t          | |	          }
d}|dk    r|dz  }t          || t          j	        |||||gt          j
                  g|
g|           d S )Nr   r4   rL   rE   rM   rI   rN   rO   rP   rQ   test_affine_grid_3dr   rV   rW   rY   )rG   r[   r\   r]   r^   r   r   r   r   r   r_   )rF   r`   ra   Drb   rc   rd   rT   re   rf   rP   rg   s               r-    export_3d_no_reference_evaluatorz+AffineGrid.export_3d_no_reference_evaluator   s   "$$Hq!Q11aA1I	# 	 	M;(((+	 )  D 4I}MMM)(MBBD-I!!--	 "(Aq!Q?"("K"K"KL	    	 	r/   )rJ   N)__name__
__module____qualname__staticmethodrh   rl    r/   r-   rI   rI      sR           \2    \  r/   rI   )numpyr   r\   onnx.backend.test.case.baser   onnx.backend.test.case.noder   !onnx.reference.ops.op_affine_gridr   r   r.   r2   rC   rG   rI   rq   r/   r-   <module>rv      s   
      , , , , , , . . . . . .       L, L, L,^, , ,(    :3 3 3 3 3 3 3 3 3 3r/   