o
    ۾i!(                     @   s   d dl Zd dlmZ d dlmZmZmZmZ d dl	m
Z
m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dS )#    N)register_jitable)
UINT32_MAX
UINT64_MAX
UINT16_MAX	UINT8_MAX)next_uint32next_uint64c                 C   sV   t | }||d? O }||d? O }||d? O }||d? O }||d? O }||d? O }|S )N                   )npuint64)maxmask r   V/home/ubuntu/.local/lib/python3.10/site-packages/numba/np/random/new_random_methods.pygen_mask   s   
r   c                 C   sF   |dkr	|||fS |st | }d}n|dL }|d8 }|d@ dk||fS )Nr      r	   )r   )bitgenoffrngbcntbufr   r   r   buffered_bounded_bool   s   
r   c                 C   s2   |s	t | }d}n|dL }|d8 }t|||fS )N   r   r	   )r   r   uint8r   r   r   r   r   r   buffered_uint8'      r    c                 C   s2   |s	t | }d}n|dL }|d8 }t|||fS )Nr	   r   )r   r   uint16r   r   r   r   buffered_uint163   r!   r#   c           	      C      t |t d }|dksJ t| ||\}}}t || }|d@ }||k rMt t| | }||k rMt| ||\}}}t || }|d@ }||k s5|d? ||fS )a?  
    Generates a random unsigned 8 bit integer bounded
    within a given interval using Lemire's rejection.

    The buffer acts as storage for a 32 bit integer
    drawn from the associated BitGenerator so that
    multiple integers of smaller bitsize can be generated
    from a single draw of the BitGenerator.
    r	      r   )r   r   r    r"   r   	r   r   r   r   rng_exclnmleftover	thresholdr   r   r   buffered_bounded_lemire_uint8A      r,   c           	      C   r$   )a@  
    Generates a random unsigned 16 bit integer bounded
    within a given interval using Lemire's rejection.

    The buffer acts as storage for a 32 bit integer
    drawn from the associated BitGenerator so that
    multiple integers of smaller bitsize can be generated
    from a single draw of the BitGenerator.
    r	     r   )r   r"   r#   uint32r   r&   r   r   r   buffered_bounded_lemire_uint16e   r-   r0   c                 C   s   t |t d }|dksJ t t| t | }|d@ }||k rBt| | }||k rBt t| t | }|d@ }||k s.|d? S )zr
    Generates a random unsigned 32 bit integer bounded
    within a given interval using Lemire's rejection.
    r	       r   )r   r/   r   r   r   )r   r   r'   r)   r*   r+   r   r   r   buffered_bounded_lemire_uint32   s   r2   c                 C   s   t |t d }|dksJ t| }t |t | }||k r>t| | }||k r>t| }t |t | }||k s,|t d@ }|d? }|t d@ }|d? }	|| }
|| |
d?  }|t d@ }|d? }|||	 7 }||	 | |d?  }|S )zr
    Generates a random unsigned 64 bit integer bounded
    within a given interval using Lemire's rejection.
    r	       r1   r   )r   r   r   r   )r   r   r'   xr*   r+   x0x1	rng_excl0	rng_excl1w0tw1w2m1r   r   r   bounded_lemire_uint64   s*   r>   c                 C   s   t j||d}|dkrt |D ]}|||< q|S |dkrF|dkr3t |D ]
}|t|  ||< q&|S t |D ]}|t| | ||< q8|S |dkr\t |D ]
}|t|  ||< qO|S t |D ]}|t| | ||< qa|S )z_
    Returns a new array of given size with 64 bit integers
    bounded by given interval.
    dtyper   r1   r3   )r   emptyndindexr   r2   r   r>   r   lowr   sizer@   outir   r   r   random_bounded_uint64_fill   s(   
	rH   c                 C   s   t j||d}|dkrt |D ]}|||< q|S |dkr/t |D ]
}|t|  ||< q"|S t |D ]}|t| | ||< q4|S )z_
    Returns a new array of given size with 32 bit integers
    bounded by given interval.
    r?   r   r1   )r   rA   rB   r   r2   rC   r   r   r   random_bounded_uint32_fill   s   
rI   c           
      C      d}d}t j||d}|dkrt |D ]}|||< q|S |dkr:t |D ]}t| ||\}	}}||	 ||< q&|S t |D ]}t| |||\}	}}||	 ||< q?|S )z_
    Returns a new array of given size with 16 bit integers
    bounded by given interval.
    r   r?   r.   )r   rA   rB   r#   r0   
r   rD   r   rE   r@   r   r   rF   rG   valr   r   r   random_bounded_uint16_fill   s&   
rM   c           
      C   rJ   )z^
    Returns a new array of given size with 8 bit integers
    bounded by given interval.
    r   r?   r%   )r   rA   rB   r    r,   rK   r   r   r   random_bounded_uint8_fill  s&   
rN   c           
      C   sL   d}d}t j||d}t |D ]}t| ||||\}	}}||	 ||< q|S )z@
    Returns a new array of given size with boolean values.
    r   r?   )r   rA   rB   r   rK   r   r   r   random_bounded_bool_fill.  s   rO   c                 C   s   | |k rt d|dkr:t|}|s|td8 }t|}| dkr(t| } ||kr0t d| |kr8t ddS ||krBt d| |krJt ddS )zS
    Check that low and high are within the bounds
    for the given datatype.
    zlow is out of boundsr   r	   zhigh is out of boundsz*low is greater than high in given intervalN)
ValueErrorr   r   )rD   highendpointlower_boundupper_boundr   r   r   _randint_arg_check<  s&   


rU   c                 C   s   |dkrdS t |}t t|}|dkr1t t| |@ }||kr0t t| |@ }||ks#nt| |@ }||krEt| |@ }||ks;t |S )Nr   r1   )r   r   r   r   r   )r   max_valr   valuer   r   r   random_interval[  s   

rX   )numpyr   numba.core.extendingr   numba.np.random._constantsr   r   r   r   numba.np.random.generator_corer   r   r   r   r    r#   r,   r0   r2   r>   rH   rI   rM   rN   rO   rU   rX   r   r   r   r   <module>   sD    




#
#

"





