o
    toi                     @  s@   d dl mZ d dlZd dlmZ d dlmZ G dd deZdS )    )annotationsNtensor_dtype_to_np_dtype)OpRunc                   @  s@   e Zd Zdd Zedd Zeddddd	Zed
d ZdS )_CommonRandomc                 C  sB   t | || t| drt| jdkrtd| jj dd S d S )Nshaper   z#shape cannot be empty for operator .)r   __init__hasattrlenr   
ValueError	__class____name__)self	onnx_node
run_params r   X/home/ubuntu/.local/lib/python3.10/site-packages/onnx/reference/ops/_op_common_random.pyr	      s   z_CommonRandom.__init__c                 C  s   t | S )Nr   )dtyper   r   r   
numpy_type   s   z_CommonRandom.numpy_typeNF)r   dtype_firstc                 G  s   t | }|r)|d ur)| dkr|S |r|d jS tdt jd| dt| dd }|s0|}n|d ur7|}nt|d drC|d j}|d u rVtd| dt|d  d|S )	Nr   z+dtype cannot be None for a random operator z, numpy_type=z, len(data)=r   r   z!dtype cannot be None, numpy_type=z, type(data[0])=)r   r   r   RuntimeErrorr   r   r
   type)r   r   datar   resr   r   r   _dtype   s2   



z_CommonRandom._dtypec                 C  s6   | d u s	t | rt j }|S t jjt| d}|S )N)seed)npisnanrandomRandomStateint)r   stater   r   r   
_get_state1   s
   
z_CommonRandom._get_state)r   
__module____qualname__r	   staticmethodr   r   r#   r   r   r   r   r      s    
r   )	
__future__r   numpyr   onnx.helperr   onnx.reference.op_runr   r   r   r   r   r   <module>   s
   