o
    8ήc                     @   s  d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
mZmZ ddlmZ eejG dd de	jZedZeejG d	d
 d
e	jZeejdd dd Zdd Zdd Zdd Zeeej eeej eeej edkr|edd ZdS edd ZdS )z9
Core Implementations for Generator/BitGenerator Models.
    )ir)cgutilstypes)	intrinsicmake_attribute_wrappermodelsoverloadregister_jitableregister_model)numpy_versionc                          e Zd Z fddZ  ZS )NumPyRngBitGeneratorModelc                    sT   dt jfdt jfdt jfdt jfdt jfdt jfdt jfg}tt| ||| d S )Nparentstate_addressstatefnptr_next_uint64fnptr_next_uint32fnptr_next_doublebit_generator)r   pyobjectuintpsuperr   __init__selfdmmfe_typemembers	__class__ E/tmp/pip-target-vg8gfxp4/lib/python/numba/np/random/generator_core.pyr      s   	z"NumPyRngBitGeneratorModel.__init____name__
__module____qualname__r   __classcell__r    r    r   r!   r          r   r   c                       r   )NumPyRandomGeneratorTypeModelc                    s8   dt fdttjfdtjfg}tt| ||| d S )Nr   meminfor   )_bit_gen_typer   MemInfoPointervoidptrr   r   r(   r   r   r   r    r!   r   !   s   z&NumPyRandomGeneratorTypeModel.__init__r"   r    r    r   r!   r(      r'   r(   c                    s*   t fdd t fdd}dS )zF
        Generate the overloads for "next_(some type)" functions.
    c                    s     } fdd}||fS )Nc                    s   j }t | ||d d}|j}t|d| }| tj}| }	| tj}
|	||}t
|	|
f}t|j||}|||j}|||f}|S )Nr   )valuefnptr_)r#   r   create_struct_proxyr   getattrget_value_typer   r,   r   inttoptrr   FunctionTypeget_or_insert_functionmodulebitcasttypecall)cgctxbuildersigllargsname
struct_ptrr   next_double_addrll_void_ptr_tll_return_t
ll_uintp_tnext_fn_fnptrfntynext_fnfnptr_as_fntyperet)instoverloadable_functionreturn_typer    r!   codegen>   s&   
z[_generate_next_binding.<locals>.intrin_NumPyRandomBitGeneratorType_next_ty.<locals>.codegenr    )tyctxrH   r;   rK   )rI   rJ   )rH   r!   *intrin_NumPyRandomBitGeneratorType_next_ty:   s   zJ_generate_next_binding.<locals>.intrin_NumPyRandomBitGeneratorType_next_tyc                    s    t | tjr fdd}|S d S )Nc                    s    | S Nr    bitgenrM   r    r!   impl]   s   z8_generate_next_binding.<locals>.ol_next_ty.<locals>.impl)
isinstancer   NumPyRandomBitGeneratorType)rP   rR   rQ   r    r!   
ol_next_tyZ   s   z*_generate_next_binding.<locals>.ol_next_tyN)r   r   )rI   rJ   rU   r    )rM   rI   rJ   r!   _generate_next_binding6   s   rV   c                 C      | j | j jS rN   )ctypesnext_doubler   rO   r    r    r!   rY   c      rY   c                 C   rW   rN   )rX   next_uint32r   rO   r    r    r!   r[   g   rZ   r[   c                 C   rW   rN   )rX   next_uint64r   rO   r    r    r!   r\   k   rZ   r\   )      c                 C      t | d? d S )N   g      p>r[   rO   r    r    r!   
next_floatv      rb   c                 C   r_   )N	   g      >ra   rO   r    r    r!   rb   z   rc   N)__doc__llvmliter   
numba.corer   r   numba.core.extendingr   r   r   r   r	   r
   numba.np.numpy_supportr   rT   StructModelr   r*   NumPyRandomGeneratorTyper(   rV   rY   r[   r\   doubleuint32uint64rb   r    r    r    r!   <module>   s6     
-