
    
Ng*                     \    d dl mZ d dlZd dlmZ  G d d          Z G d de          ZdS )    )TupleN)OpRunc                   "    e Zd ZddZdefdZdS )PreCalcr   c	                 v    || _         || _        || _        || _        || _        || _        || _        || _        d S )Npos1pos2pos3pos4w1w2w3w4)	selfr	   r
   r   r   r   r   r   r   s	            [/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnx/reference/ops/op_roi_align.py__init__zPreCalc.__init__   s>    				    returnc                     d| j          d| j         d| j         d| j         d| j         d| j         d| j         d| j         dS )NzPreCalc(,)r   )r   s    r   __repr__zPreCalc.__repr__   sa    r$)rrdirr$)rrdirr$'rrTXT[rr^b^errhlhorrrrr   N)r   r   r   r   r   r   r   r   )__name__
__module____qualname__r   strr    r   r   r   r      sJ           s# s s s s s sr   r   c                       e Zd Zededededededededefd	            Zed
eeeeef         dedededef
d            Z	 	 	 	 	 	 ddZ	dS )RoiAlignheightwidthpooled_heightpooled_widthiy_upperix_upperroi_bin_grid_hroi_bin_grid_wc                    d}t          |          D ]}t          |          D ]}t          |          D ]}|||z  z   |dz   |z  |
z  z   }t          |          D ]w}|||	z  z   |dz   |	z  |z  z   }|}|}|dk     s|| k    s|dk     s||k    rF||         }d|_        d|_        d|_        d|_        d|_        d|_        d|_        d|_        |dz  }yt          |d          }t          |d          }t          |          }t          |          }|| dz
  k    r
| dz
  x}}|}n|dz   }||dz
  k    r
|dz
  x}}|}n|dz   }||z
  }||z
  }d|z
  }d|z
  }||z  }||z  } ||z  }!||z  }"t                      }||z  |z   |_        ||z  |z   |_        ||z  |z   |_        ||z  |z   |_        ||_        | |_        |!|_        |"|_        |||<   |dz  }yd S )Nr         ?g               ?)ranger	   r
   r   r   r   r   r   r   maxintr   )#r!   r"   r#   r$   r%   r&   roi_start_hroi_start_w
bin_size_h
bin_size_wr'   r(   pre_calcpre_calc_indexphpwiyyyixxxxypcy_lowx_lowy_highx_highlylxhyhxr   r   r   r   s#                                      r   !pre_calc_for_bilinear_interpolatez*RoiAlign.pre_calc_for_bilinear_interpolate   s     && F	, F	,BL)) E, E,// D, D,B#z/*8z1NBC 
 $Hoo >, >,' :o.!Cx:5FG  t88q6zzQXXU!).!9B&'BG&'BG&'BG&'BG$%BE$%BE$%BE$%BE*a/N$1II1II #A #A FQJ..-3aZ7FU %AA%*QYF EAI---2QY6FU %AA%*QYFYY 2X 2X"W"W"W"W %YY"'%-%"7"'%-&"8"(5.5"8"(5.6"9 " " " "350&!+}>,D,E,F	, F	,r   output_shapenum_roi_cols
half_pixelc                    | d         }| d         }| d         }| d         }t          |          D ]B}||z  |z  |z  }||z  }||         }|
rdnd}||dz            |z  |z
  }||dz            |z  |z
  }||dz            |z  |z
  }||dz            |z  |z
  }||z
  }||z
  }|
s t          |d          }t          |d          }||z  }||z  }|dk    rt          |          n#t          t          j        ||z                      }|dk    rt          |          n#t          t          j        ||z                      }t          t          ||z  d                    }d t          ||z  |z  |z            D             } t
                              |||||||||||||            t          |          D ]}!||!|z  |z  z   }"t          ||z  |!z   |z  |z            }#d}$t          |          D ]}%t          |          D ]l}&|"|%|z  z   |&z   }'d}(|	d	k    rt          |          D ]})t          |          D ]u}*| |$         }+|(|+j        ||#|+j        z            z  |+j	        ||#|+j
        z            z  z   |+j        ||#|+j        z            z  z   |+j        ||#|+j        z            z  z   z  }(|$dz  }$v|(|z  }(nd
},t          |          D ]})t          |          D ]}*| |$         }+t          |+j        ||#|+j        z            z  |+j	        ||#|+j
        z            z  |+j        ||#|+j        z            z  |+j        ||#|+j        z            z            }-|,s|-}(d},nt          |(|-          }(|$dz  }$|(||'<   nDd S )Nr   r+         r*   g        r,   c                 *    g | ]}t                      S r   )r   ).0is     r   
<listcomp>z.RoiAlign.roi_align_forward.<locals>.<listcomp>   s,        		  r   avgFT)r-   r.   r/   npceilr    rG   r   r	   r   r
   r   r   r   r   ).rH   bottom_dataspatial_scaler!   r"   sampling_ratiobottom_roisrI   top_datamoderJ   batch_indices_ptrn_roischannelsr#   r$   nindex_noffset_bottom_roisroi_batch_indoffsetr1   r0   	roi_end_w	roi_end_h	roi_width
roi_heightr2   r3   r'   r(   countr4   c	index_n_coffset_bottom_datar5   r6   r7   index
output_val_iy_ixr>   max_flagvals.                                                 r   roi_align_forwardzRoiAlign.roi_align_forwardv   s    a?$Q#A v s	5 s	5A(l\1MAG "#\!1-a0M '/SSCF%&81&<=MPVVK%&81&<=MPVVK#$6$:;mKfTI#$6$:;mKfTI!K/I"[0J 2	3//	 S11
#m3J"\1J
 "A%% N###m!;<<==  "A%% N###\!9::;;  N^;Q??@@E "^3lB]R   H 66    8__ 45 45#a,&6&FF	%("X-1V;eC& &" "#.. ,5 ,5B#L11 +5 +5 )B,= = B%(
5==',^'<'< 8 8+0+@+@ !8 !8C)1.)AB$.(**56H276R*S)T*,%*56H276R*S+T)T +-%*56H276R*S+T	)T +-%*56H276R*S+T)T	%&J %3a$7NN!8 '%/JJ',H',^'<'< 8 8+0+@+@ !8 !8C)1.)AB*-(**56H276R*S)T(**56H276R*S)T(**56H276R*S)T(**56H276R*S)T	+& 	+&C ,4 %J58
3758S5I5I
$2a$7NN#!8& +5W+5,545s	5 s	5r   Nc
                    |p| j         }|p| j        }|p| j        }|p| j        }|p| j        }|	p| j        }	|j        d         }
|j        d         }|j        d         }||
||f}t          j        ||j	                  
                                }|                     ||
                                |	|j        d         |j        d         ||
                                |||                                |                                dk    |
                                           |                    |                              |j	                  fS )Nr+   r   )dtyperL   rM   rJ   )coordinate_transformation_moderZ   output_heightoutput_widthrW   rV   shaperS   emptyrs   flattenrq   lowerreshapeastype)r   Xroisbatch_indicesrt   rZ   ru   rv   rW   rV   num_channelsnum_roisrI   y_dimsYs                  r   _runzRoiAlign._run   sJ    *H)n4Kn& ty%;);#8t'8'>4+>%;);wqz &q)z!}L-FHV17+++3355IIKKGAJGAJLLNNJJLL*0022lB!!##	
 	
 	
 		&!!((1133r   )NNNNNN)
r   r   r   staticmethodr/   rG   r   boolrq   r   r   r   r   r    r       s       V,V,V, V, 	V,
 V, V, V, V, V, V, \V,p G5Cc3./G5 	G5
 G5 G5 G5 G5 G5 \G5\ (,(4 (4 (4 (4 (4 (4r   r    )typingr   numpyrS   onnx.reference.op_runr   r   r    r   r   r   <module>r      s              ' ' ' ' ' 's s s s s s s sL4 L4 L4 L4 L4u L4 L4 L4 L4 L4r   