o
    wiG                     @  s4   d dl mZ d dlZd dlmZ G dd deZdS )    )annotationsN)OpRunc                   @  s6   e Zd Zdd Zdd ZddddddddddZdS )	Scanc                   s   t  || t jdstdt j d fddt jD  _t	 j}|dkr2td fddt jD  _
t	 j
}|dkrLtd	 jj _ jj _d S )
Nrunz0Parameter 'body' must have a method 'run', type .c                   2   g | ]} j d u s|t j krdn j | qS Nr   )scan_input_directionslen.0iself W/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/onnx/reference/ops/op_scan.py
<listcomp>       
z!Scan.__init__.<locals>.<listcomp>r   z@Scan is not implemented for other output input_direction than 0.c                   r   r   )scan_input_axesr
   r   r   r   r   r           z4Scan is not implemented for other input axes than 0.)r   __init__hasattrbodyRuntimeErrortyperangenum_scan_inputsinput_directions_maxinput_axes_input_namesoutput_names)r   	onnx_node
run_params
max_dir_in
max_axe_inr   r   r   r      s*   

	


zScan.__init__c                   s   t | j }t || } fddt|D }t|}|dkr$td fddt|D }t|}|dkr;td jd  j } jd t | }	 j|d  }
 j|d  }||d  }|d | }||||||||	|
|||fS )Nc                   r   r   )scan_output_directionsr
   r   r   r   r   r   2   r   z*Scan._common_run_shape.<locals>.<listcomp>r   zAScan is not implemented for other output output_direction than 0.c                   r   r   )scan_output_axesr
   r   r   r   r   r   @   r   z5Scan is not implemented for other output axes than 0.)r
   r   r   r   r   r    r!   )r   argsnum_loop_state_varsnum_scan_outputsoutput_directionsmax_dir_outoutput_axesmax_axe_outstate_names_instate_names_outscan_names_inscan_names_outscan_valuesstatesr   r   r   _common_run_shape.   sF   
	
zScan._common_run_shapeN)r   r   r   r	   r'   r&   
attributesc                  s:  | j | \}	}
}}}}}}}}}}||	 j| jd  }dd |D }t|D ]` tt||}| fddt||D  z| |}W n ty] } ztdt	| j
 d|d }~ww tt| j|fdd|D }t|D ]\}}|| tj| dd	 qsq&|D ]}t|}|| q| t|S )
Nr   c                 S  s   g | ]}g qS r   r   )r   _r   r   r   r      s    zScan._run.<locals>.<listcomp>c                   s   i | ]	\}}||  qS r   r   )r   namevalue)itr   r   
<dictcomp>   s    zScan._run.<locals>.<dictcomp>zUnable to call 'run' for type 'z'.c                   s   g | ]} | qS r   r   )r   r8   )outputsr   r   r      s    )axis)r5   shaper   r   dictzipupdate	_run_body	TypeErrorr   r   r!   	enumerateappendnpexpand_dimsvstack_check_and_fix_outputstuple)r   r   r   r   r	   r'   r&   r6   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   max_iterresultsinputsoutputs_lister   r8   resconcr   )r:   r<   r   _runc   sP   
z	Scan._run)__name__
__module____qualname__r   r5   rR   r   r   r   r   r      s    "8r   )
__future__r   numpyrF   onnx.reference.op_runr   r   r   r   r   r   <module>   s   