o
    iH                     @   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   b/var/www/html/eduruby.in/lip-sync/lip-sync-env/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   r4   c                 C   s   t j| tjd|d}|S )z8
    Allocate an uninitialized boolean result slot.
       r.   )r   r0   llvmliteirIntTyper3   r   r   r   alloc_boolean_resultX   s   r9   c                 C   s   |  d|tS )z?
    Return a predicate which is true if *val* is not NaT.
    !=)icmp_unsignedr2   )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.
    r5   r   N)lenr<   and_)r   valspredr   r   r   r   are_not_natg   s
   rA   )      rB      rB   rD   rB   rB   rD   rB   rD   rB   )rB      rB   rD   rB   rD   rB   rB   rD   rB   rD   rB   )r   rB   ;   Z   x               i  i0  iN  )r   rB   <   [   y               i  i1  iO  c                 C   s   t |tjS N)
DATETIME64Zastypenpint64)r&   r   tyZpyvalr   r   r   datetime_constant      rY   c                 C   s   |d }t | ||j|S Nr   )r   return_typer&   r   sigargsresr   r   r   timedelta_pos_impl   s   ra   c                 C   s   | |d }t| ||j|S r[   )negr   r\   r]   r   r   r   timedelta_neg_impl   s   rc   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 rT   )	r4   if_elser   Zis_scalar_negr1   rb   loadr   r\   )	r&   r   r^   r_   r   r-   then	otherwiser`   r   r   r   timedelta_abs_impl   s   
rh   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   >r5   N==)
r4   r   r   rd   icmp_signedr1   r;   re   r   r\   )r&   r   r^   r_   r   r-   zeroZgt_zeroZle_zeroZeq_zeroZlt_zeror`   r   r   r   timedelta_sign_impl   s2   

rn   c           
      C      |\}}|j \}}t|}t|t|||g$ t| ||||j}t| ||||j}||||| W d    n1 s?w   Y  |	|}	t
| ||j|	S rT   )r_   r4   r   	if_likelyrA   r(   r\   r1   r    re   r   
r&   r   r^   r_   vavbtatbr-   r`   r   r   r   timedelta_add_impl      

rv   c           
      C   ro   rT   )r_   r4   r   rp   rA   r(   r\   r1   subre   r   rq   r   r   r   timedelta_sub_impl   rw   ry   c           	      C   s   t |}t|t||6 t|tjr(|||j}|	||}t
| ||}n|||}t| ||||}||| W d    n1 sFw   Y  ||S rT   )r4   r   rp   r<   
isinstancer   FloatsitofptypeZfmul_cast_to_timedeltar   r(   r1   re   )	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   r5   r   r_   r\   r   r]   r   r   r   timedelta_times_number   
   r   c                 C   r   Nr5   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_   r4   r>   r<   not_r   Zis_scalar_zero_or_nanrp   rz   r   r{   r|   r}   fdivr~   r   r(   r\   r1   re   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_   rA   get_value_typer\   r   r0   r1   r   floatrp   r,   r|   r   re   r   )r&   r   r^   r_   rr   rs   rt   ru   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   r5   rj   <)r_   r   r\   rA   r   r0   r   r1   rp   r,   r   rl   or_rd   rx   r   r    re   r   )r&   r   r^   r_   rr   rs   rt   ru   r   r   r-   rm   onedenom_okZvanegrb   rf   rg   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   rj   ri   )r_   rA   r   r\   r4   r1   r2   r   r   rp   r,   r   rl   sremr   r>   rd   r    re   r   )r&   r   r^   r_   rr   rs   rt   ru   r   r   r-   rm   r   ZvaposZvbposremZcondrf   rg   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 Nr:   )r_   r9   rd   rA   r,   r)   r1   r;   r   true_bit	false_bitre   r   r\   r&   r   r^   r_   rr   rs   rt   ru   r-   rf   rg   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 rT   )r_   r9   rd   rA   r,   r1   rl   r   r   re   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   rj   r:   r   <=ri   >=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   rU   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  r5      D   r   i,  r   Ni)r   r0   r   r   rd   Z
is_neg_intr"   r    r   rx   r1   re   )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   r0   r   Zdivmod_by_constantrd   r   re   Zgepr1   r    )r   dt_valsrc_unit	dest_unitZdest_unit_codeZsrc_unit_coder   Zdays_valZ
leap_arrayZnormal_arrayr   yearmonthrf   rg   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 rT   )r4   r   rp   rA   r   r
   r$   r   getattrr1   re   )
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    rx   c           	      C   >   |\}}|j \}}t| |||j||j|jj}t| ||j|S rT   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 rT   r   )	r&   r   r^   r_   r   r   r   r   r`   r   r   r   timedelta_plus_datetime[  r   r   c           	      C   r   rT   )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 rT   )r_   r%   r\   r4   r   rp   rA   r   rx   r1   re   r   )r&   r   r^   r_   rr   rs   rt   ru   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_unitr9   rd   rA   r   rl   r1   r   r   r   re   r   r\   )r&   r   r^   r_   rr   rs   rt   ru   r   r   r   r-   rf   rg   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<   rl   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_unorderedrd   r1   r2   Zfptosire   )r&   r   r   tempZ
val_is_nanrf   Zelsr   r   r   r~     s   

r~   c                 C   s   t | |||S rT   )r   Znp_datetime_isnat_impl)r&   r   r^   r_   r   r   r   _np_isnat_impl  rZ   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 rdd }|S dd }|S )Nc                 S   sf   t | } | dk rt | }nt | d@ d? }t | d@ }t |d|  }|dkr1t d}|S )Nil            l    iCB rk   r   )rV   rW   Zint32)xyhilor   r   r   r   .  s   

z ol_hash_npdatetime.<locals>.implc                 S   s"   t | dkrt dS t | S )Nrk   r   )rV   rW   )r   r   r   r   r   :  s   

r   )r   r   r   r   r   ol_hash_npdatetime*  s
   r   )r-   )__doc__numpyrV   operatorZllvmlite.irr6   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   r7   r8   rU   r   r2   ZNPTimedeltaZTIMEDELTA_BINOP_SIGr   r   r"   r(   r,   r4   r9   r<   rA   Znormal_year_monthsZleap_year_monthsr   r   Z
NPDatetimerY   posra   rb   rc   absrh   rn   r    iaddrv   rx   isubry   r   r   Integerimulr{   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-

 

