o
    0 i                     @   s  d Z ddlZddlZddlZddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZmZmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ ejd ZZeeejZej fd Z!dd Z"dd Z#dd Z$dd Z%dd Z&dsddZ'dsddZ(dd Z)dd Z*eeg d Z+eeg d!Z,eeg d"Z-eeg d#Z.eej/eej d$d% Z0eej1ej d&d' Z2eej3ej d(d) Z4ee5ej d*d+ Z6d,d- Z7eej8ge!R  eej9ge!R  d.d/ Z:eej;ge!R  eej<ge!R  d0d1 Z=d2d3 Z>eej?ej ej@eejAej ej@eej?ej ejBeejAej ejBd4d5 ZCeej?ej@ej eejAej@ej eej?ejBej eejAejBej d6d7 ZDeejEej ej@eejFej ej@eejGej ej@eejHej ej@eejEej ejBeejFej ejBeejGej ejBeejHej ejBd8d9 ZIeejEge!R  eejFge!R  d:d; ZJeejGge!R  d<d= ZKd>d? ZLd@dA ZMdBdC ZNeMdDe	jOZPeMdEe	jQZReNdFZSeNdGZTeNdHZUeNdIZVejWePfejXeRfejYeSfejZeTfej[eUfej\eVffD ]\Z]Z^ee]ge!R  e^ qdJdK Z_dLdM Z`dNdO ZadPdQ ZbdRdS ZcecdTZdecdUZeeej8ej/ej eej9ej/ej dVdW Zfeej8ej ej/eej9ej ej/dXdY Zgeej;ej/ej eej<ej/ej dZd[ Zheej;ej/ej/d\d] Zid^d_ ZjejdDZkejdEZlejdFZmejdGZnejdHZoejdIZpejWekfejXelfejYemfejZenfej[eofej\epffD ]\ZqZ^eeqgej/gd R  e^ qd`da ZrerdbZserdcZtddde ZueudbZveudcZwdfdg ZxexdbZyexdcZzdhdi Z{e{dbZ|e{dcZ}djdk Z~eejej/eejej dldm Zeej/ej@eej ej@dndo Zeej dpeej/dpdqdr Zeejej/ej/ev eejej ej ev eejej/ej/es eejej ej es dS )tz4
Implementation of operations on numpy timedelta64.
    N)Constant)typescgutils)create_constant_array)lower_builtinlower_constantimpl_ret_untracked
lower_cast)npdatetime_helpersnumpy_supportnpyfuncs)overload_method)	IS_32BITS)LoweringError@      c                 C      |  |tt|S )z2
    Multiply *val* by the constant *factor*.
    )mulr   TIMEDELTA64buildervalfactor r   _/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/numba/np/npdatetime.pyscale_by_constant      r   c                 C   r   )z0
    Divide *val* by the constant *factor*.
    )sdivr   r   r   r   r   r   unscale_by_constant"   r   r   c                 C   r   )z(
    Add constant *const* to *val*.
    )addr   r   )r   r   constr   r   r   add_constant)   r   r!   c                 C   s@   t |j|j}|du rd|j d|j }t|t|||S )zk
    Scale the timedelta64 *val* from *srcty* to *destty*
    (both numba.types.NPTimedelta instances)
    Nz cannot convert timedelta64 from  to )r
   get_timedelta_conversion_factorunitr   r   )contextr   r   ZsrctyZdesttyr   msgr   r   r   scale_timedelta0   s   r'   c                 C   s`   t |j|j}|durt||||fS t |j|j}|dur(|t|||fS td||f )ze
    Scale either *left* or *right* to the other's unit, in order to have
    homogeneous units.
    Nzcannot normalize %r and %r)r
   r#   r$   r   RuntimeError)r%   r   leftrightZlefttyZrighttyr   r   r   r   normalize_timedeltas>   s   r+   retc                 C   s    t j| t|d}| t| |S )zM
    Allocate a NaT-initialized datetime64 (or timedelta64) result slot.
    name)r   alloca_oncer   storeNATr   r.   r,   r   r   r   alloc_timedelta_resultO   s   r3   c                 C   s   t j| tjd|d}|S )z8
    Allocate an uninitialized boolean result slot.
       r-   )r   r/   llvmliteirIntTyper2   r   r   r   alloc_boolean_resultX   s   r8   c                 C   s   |  d|tS )z?
    Return a predicate which is true if *val* is not NaT.
    !=)icmp_unsignedr1   )r   r   r   r   r   
is_not_nat`   s   r;   c                 C   sF   t |dksJ t| |d }|dd D ]}| |t| |}q|S )zH
    Return a predicate which is true if all of *vals* are not NaT.
    r4   r   N)lenr;   and_)r   valspredr   r   r   r   are_not_natg   s
   r@   )      rA      rA   rC   rA   rA   rC   rA   rC   rA   )rA      rA   rC   rA   rC   rA   rA   rC   rA   rC   rA   )r   rA   ;   Z   x               i  i0  iN  )r   rA   <   [   y               i  i1  iO  c                 C   s   t |tjS N)
DATETIME64Zastypenpint64)r%   r   tyZpyvalr   r   r   datetime_constant      rX   c                 C   s   |d }t | ||j|S Nr   )r   return_typer%   r   sigargsresr   r   r   timedelta_pos_impl   s   r`   c                 C   s   | |d }t| ||j|S rZ   )negr   r[   r\   r   r   r   timedelta_neg_impl   s   rb   c           	   	   C   s   |\}t |}|t||=\}}| |||| W d    n1 s)w   Y  | ||| W d    n1 sAw   Y  W d    n1 sPw   Y  ||}t| ||j|S rS   )	r3   if_elser   Zis_scalar_negr0   ra   loadr   r[   )	r%   r   r]   r^   r   r,   then	otherwiser_   r   r   r   timedelta_abs_impl   s   
rg   c                 C   sh  |\}t |}ttd}||d||\}}| |ttd| W d   n1 s/w   Y  |Z ||d||@\}	}
|	 |ttd| W d   n1 sZw   Y  |
 |ttd| W d   n1 suw   Y  W d   n1 sw   Y  W d   n1 sw   Y  W d   n1 sw   Y  ||}t| ||j	|S )z
    np.sign(timedelta64)
    r   >r4   N==)
r3   r   r   rc   icmp_signedr0   r:   rd   r   r[   )r%   r   r]   r^   r   r,   zeroZgt_zeroZle_zeroZeq_zeroZlt_zeror_   r   r   r   timedelta_sign_impl   s2   

rm   c           
      C      |\}}|j \}}t|}t|t|||g$ t| ||||j}t| ||||j}||||| W d    n1 s?w   Y  |	|}	t
| ||j|	S rS   )r^   r3   r   	if_likelyr@   r'   r[   r0   r   rd   r   
r%   r   r]   r^   vavbtatbr,   r_   r   r   r   timedelta_add_impl      

ru   c           
      C   rn   rS   )r^   r3   r   ro   r@   r'   r[   r0   subrd   r   rp   r   r   r   timedelta_sub_impl   rv   rx   c           	      C   s   t |}t|t||6 t|tjr(|||j}|	||}t
| ||}n|||}t| ||||}||| W d    n1 sFw   Y  ||S rS   )r3   r   ro   r;   
isinstancer   FloatsitofptypeZfmul_cast_to_timedeltar   r'   r0   rd   )	r%   r   td_argtd_type
number_argnumber_typer[   r,   r   r   r   r   _timedelta_times_number   s   
r   c                 C   :   t | ||d |jd |d |jd |j}t| ||j|S )Nr   r4   r   r^   r[   r   r\   r   r   r   timedelta_times_number   
   r   c                 C   r   Nr4   r   r   r\   r   r   r   number_times_timedelta   r   r   c              	   C   s   |\}}|j d }t|}|t|||t||}t||: t|t	j
r>|||j}	||	|}	t| ||	}	n|||}	t| ||	|j d |j}	||	| W d    n1 s`w   Y  ||}
t| ||j|
S r   )r^   r3   r=   r;   not_r   Zis_scalar_zero_or_nanro   ry   r   rz   r{   r|   fdivr}   r   r'   r[   r0   rd   r   )r%   r   r]   r^   r~   r   r   r,   okr   r_   r   r   r   timedelta_over_number   s&   	

r   c                 C   s   |\}}|j \}}t|||g}| |j}	tj||	dd}
|t|	td|
 t	||) t
| |||||\}}|||	}|||	}|||||
 W d    n1 s[w   Y  ||
}t| ||j|S )Nr,   r-   nan)r^   r@   get_value_typer[   r   r/   r0   r   floatro   r+   r{   r   rd   r   )r%   r   r]   r^   rq   rr   rs   rt   not_nanll_ret_typer,   r_   r   r   r   timedelta_over_timedelta  s   

r   c                 C   sn  |\}}|j \}}| |j}t|||g}	tj||dd}
t|d}t|d}|||
 t||	 t	| |||||\}}|
|d||}t|| |d||}|||d||}||\}}|g ||R\}}| |||}|||}|||
 W d    n1 sw   Y  | |||}|||}|||
 W d    n1 sw   Y  W d    n1 sw   Y  W d    n1 sw   Y  | |||}|||
 W d    n1 sw   Y  W d    n	1 sw   Y  W d    n	1 sw   Y  W d    n	1 s%w   Y  ||
}t| ||j|S )Nr,   r-   r   r4   ri   <)r^   r   r[   r@   r   r/   r   r0   ro   r+   r   rk   or_rc   rw   r   r   rd   r   )r%   r   r]   r^   rq   rr   rs   rt   r   r   r,   rl   onedenom_okZvanegra   re   rf   ZnegthenZnegotherwisetopdivr_   r   r   r   timedelta_floor_div_timedelta+  sV   




r   c                 C   s  |\}}|j \}}t|||g}| |j}	t|}
|t|
 t|	d}t	|| t
| |||||\}}||d||}t	||v |d||}|d||}|||}|||||d||}||>\}}| |||
 W d    n1 sw   Y  | |||||
 W d    n1 sw   Y  W d    n1 sw   Y  W d    n1 sw   Y  W d    n1 sw   Y  ||
}t| ||j|S )Nr   ri   rh   )r^   r@   r   r[   r3   r0   r1   r   r   ro   r+   r   rk   sremr   r=   rc   r   rd   r   )r%   r   r]   r^   rq   rr   rs   rt   r   r   r,   rl   r   ZvaposZvbposremZcondre   rf   r_   r   r   r   timedelta_mod_timedeltaN  s@   


r   c                    s    fdd}|S )Nc              
      s*  |\}}|j \}}t|}|t|||gi\}	}
|	0 zt| |||||\}}W n ty9   | | Y nw ||||| W d    n1 sOw   Y  |
 dkrc|tj	| n|tj
| W d    n1 stw   Y  W d    n1 sw   Y  ||}t| ||j|S Nr9   )r^   r8   rc   r@   r+   r(   r0   r:   r   true_bit	false_bitrd   r   r[   r%   r   r]   r^   rq   rr   rs   rt   r,   re   rf   norm_anorm_br_   default_valuell_opr   r   implt  s2   
	
z/_create_timedelta_comparison_impl.<locals>.implr   )r   r   r   r   r   r   !_create_timedelta_comparison_impls  s   r   c                        fdd}|S )Nc              	      s   |\}}|j \}}t|}|t|||gK\}	}
|	 t| |||||\}}|| ||| W d    n1 s=w   Y  |
 |tj| W d    n1 sVw   Y  W d    n1 sew   Y  |	|}t
| ||j|S rS   )r^   r8   rc   r@   r+   r0   rk   r   r   rd   r   r[   r   r   r   r   r     s"   

z-_create_timedelta_ordering_impl.<locals>.implr   r   r   r   r   r   _create_timedelta_ordering_impl     r   ri   r9   r   <=rh   >=c              	   C   st   |  |ttd}t| | |ttd}t| | |ttd}t| | |ttd}| || ||S )z_
    Return a predicate indicating whether *year_val* (offset by 1970) is a
    leap year.
    i     d     )	r   r   rT   r   Zis_nullr=   Zis_not_nullr   r   )r   year_valZactual_yearZmultiple_of_4Znot_multiple_of_100Zmultiple_of_400r   r   r   is_leap_year  s   
r   c              	   C   sl  t | t}t| |d}| t | |\}}|> t| |d}| |t| |d}t| |d}| 	|t| |d}t| |d}	| |t| |	d}| 
|| W d   n1 s[w   Y  |8 t| |d	}
| |t| |
d}t| |
d
}| 	|t| |d}| |t| |d}| 
|| W d   n1 sw   Y  W d   n1 sw   Y  | |S )zg
    Given a year *year_val* (offset to 1970), return the number of days
    since the 1970 epoch.
    im  r4      D   r   i,  r   Ni)r   r/   r   r   rc   Z
is_neg_intr!   r   r   rw   r0   rd   )r   r   r,   daysZif_negZif_posZ	from_1968Zp_daysZ	from_1900Z	from_1600Z	from_1972Zn_daysZ	from_2000r   r   r   year_to_days  sH   






(r   c                 C   s  t j| }t j| }|dk s|dkr||fS |dkr"|}t| |}nt| dt}t| dt}	t| t}
t	| |d\}}| 
t| |T\}}| | tj| |d|dd}| ||
 W d    n1 sjw   Y  | | tj| |	d|dd}| ||
 W d    n1 sw   Y  W d    n1 sw   Y  t| |}| || |
}|dkrt	| |d\}}|d	fS |d
fS )Nr   r   leap_year_months_accnormal_year_months_acc   T)Zinbounds   WD)r
   ZDATETIME_UNITSr   r   Zglobal_constantr   r   r/   r   Zdivmod_by_constantrc   r   rd   Zgepr0   r   )r   dt_valsrc_unit	dest_unitZdest_unit_codeZsrc_unit_coder   Zdays_valZ
leap_arrayZnormal_arrayr   yearmonthre   rf   addendweeks_r   r   r   reduce_datetime_for_unit  sH   



r   c                 C   sB   t | |||\}}t||}|du rtd||f t| ||S )zC
    Convert datetime *dt_val* from *src_unit* to *dest_unit*.
    Nz'cannot convert datetime64 from %r to %r)r   r
   r#   r   r   )r   r   r   r   dt_unitZ	dt_factorr   r   r   convert_datetime_for_arith)  s   r   c                    r   )Nc           
         s   t |}t|t|||g) t||||}t||}t|||}t| ||}	|	|	| W d    n1 s;w   Y  |
|S rS   )r3   r   ro   r@   r   r
   r#   r   getattrr0   rd   )
r%   r   dt_argr   r~   Ztd_unitret_unitr,   Z	td_factorret_val
ll_op_namer   r   r   :  s   
z'_datetime_timedelta_arith.<locals>.implr   )r   r   r   r   r   _datetime_timedelta_arith9  s   r   r   rw   c           	      C   >   |\}}|j \}}t| |||j||j|jj}t| ||j|S rS   r^   _datetime_plus_timedeltar$   r[   r   	r%   r   r]   r^   r   r~   dt_typer   r_   r   r   r   datetime_plus_timedeltaO     
r   c           	      C   s>   |\}}|j \}}t| |||j||j|jj}t| ||j|S rS   r   )	r%   r   r]   r^   r~   r   r   r   r_   r   r   r   timedelta_plus_datetime[  r   r   c           	      C   r   rS   )r^   _datetime_minus_timedeltar$   r[   r   r   r   r   r   datetime_minus_timedeltai  r   r   c                 C   s   |\}}|j \}}|j}|j}	|jj}
t|}t|t|||g" t||||
}t|||	|
}|||}|	|| W d    n1 sGw   Y  |
|}t| ||j|S rS   )r^   r$   r[   r3   r   ro   r@   r   rw   r0   rd   r   )r%   r   r]   r^   rq   rr   rs   rt   unit_aunit_br   r,   r   r_   r   r   r   datetime_minus_datetimew  s   

r   c                    r   )Nc              	      s$  |\}}|j \}}|j}|j}	t||	}
t|}|t|||gZ\}}|# t||||
}t|||	|
}| ||}|	|| W d    n1 sNw   Y  |  dkr^t
j}nt
j}|	|| W d    n1 sqw   Y  W d    n1 sw   Y  ||}t| ||j|S r   )r^   r$   r
   Zget_best_unitr8   rc   r@   r   rk   r0   r   r   r   rd   r   r[   )r%   r   r]   r^   rq   rr   rs   rt   r   r   r   r,   re   rf   r   r   r   r_   r   r   r   r     s6   

z._create_datetime_comparison_impl.<locals>.implr   r   r   r   r    _create_datetime_comparison_impl  s   r   c                    r   )Nc           
         r   |\}}t ||}t ||}|d||}||||}	 r#||}}|||	|}	|||	|}	t| ||j|	S Nr   r;   rk   selectr   r[   
r%   r   r]   r^   in1in2in1_not_natin2_not_natZ
in1_ge_in2r_   NAT_DOMINATESr   r   datetime_max_impl     


z1_gen_datetime_max_impl.<locals>.datetime_max_implr   )r   r   r   r   r   _gen_datetime_max_impl  r   r   TFc                    r   )Nc           
         r   Nr   r   
r%   r   r]   r^   r   r   r   r   Z
in1_le_in2r_   r   r   r   datetime_min_impl  r   z1_gen_datetime_min_impl.<locals>.datetime_min_implr   )r   r   r   r   r   _gen_datetime_min_impl  r   r   c                    r   )Nc           
         r   r   r   r   r   r   r   timedelta_max_impl  r   z3_gen_timedelta_max_impl.<locals>.timedelta_max_implr   )r   r   r   r   r   _gen_timedelta_max_impl  r   r   c                    r   )Nc           
         r   r   r   r   r   r   r   timedelta_min_impl  r   z3_gen_timedelta_min_impl.<locals>.timedelta_min_implr   )r   r   r   r   r   _gen_timedelta_min_impl  r   r   c              	   C   s   | t}|d||}||>\}}| |t| W d    n1 s'w   Y  | |||t| W d    n1 sCw   Y  W d    n1 sRw   Y  ||S )NZuno)Zallocar   Zfcmp_unorderedrc   r0   r1   Zfptosird   )r%   r   r   tempZ
val_is_nanre   Zelsr   r   r   r}     s   

r}   c                 C   s   t | |||S rS   )r   Znp_datetime_isnat_impl)r%   r   r]   r^   r   r   r   _np_isnat_impl  rY   r   c                 C   s.   |j dkrd| d| d| d}t||S )Nr   zCannot cast r"   z as z is not 64 bits wide.)Zbitwidth
ValueError)r%   r   ZfromtyZtotyr   r&   r   r   r   _cast_npdatetime_int64!  s   
r   __hash__c                 C   s@   t jdkrt| tjr| jstdtrdd }|S dd }|S )N)r   r   zCan't hash generic timedelta64c                 S   sf   t | } | dk rt | }nt | d@ d? }t | d@ }t |d|  }|dkr1t d}|S )Nil            l    iCB rj   r   )rU   rV   Zint32)xyhilor   r   r   r   2  s   

z ol_hash_npdatetime.<locals>.implc                 S   s"   t | dkrt dS t | S )Nrj   r   )rU   rV   )r   r   r   r   r   >  s   

)r   Znumpy_versionry   r   NPTimedeltar$   r   r   )r   r   r   r   r   ol_hash_npdatetime*  s   

r   )r,   )__doc__numpyrU   operatorZllvmlite.irr5   r   Z
numba.corer   r   Znumba.core.cgutilsr   Znumba.core.imputilsr   r   r   r	   Znumba.npr
   r   r   Znumba.extendingr   Znumba.core.configr   Znumba.core.errorsr   r6   r7   rT   r   r1   r   ZTIMEDELTA_BINOP_SIGr   r   r!   r'   r+   r3   r8   r;   r@   Znormal_year_monthsZleap_year_monthsr   r   Z
NPDatetimerX   posr`   ra   rb   absrg   rm   r   iaddru   rw   isubrx   r   r   Integerimulrz   r   r   truedivitruedivfloordiv	ifloordivr   r   r   r   r   r   r   Ztimedelta_eq_timedelta_implr   Ztimedelta_ne_timedelta_implZtimedelta_lt_timedelta_implZtimedelta_le_timedelta_implZtimedelta_gt_timedelta_implZtimedelta_ge_timedelta_impleqneltlegtgeZop_funcr   r   r   r   r   r   r   r   r   r   r   r   Zdatetime_eq_datetime_implZdatetime_ne_datetime_implZdatetime_lt_datetime_implZdatetime_le_datetime_implZdatetime_gt_datetime_implZdatetime_ge_datetime_implopr   Zdatetime_maximum_implZdatetime_fmax_implr   Zdatetime_minimum_implZdatetime_fmin_implr   Ztimedelta_maximum_implZtimedelta_fmax_implr   Ztimedelta_minimum_implZtimedelta_fmin_implr}   Zisnatr   r   r   Zdatetime_minimumZdatetime_maximumr   r   r   r   <module>   sB   

	




"%6-

 

