o
    r::j                     @  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                	   @  sB   e Zd Zdd ZdddZdd Zd	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 jdkr&td j d fddt jD  _ jrCt	 j}|dkrCtd fd	dt jD  _
 j
r`t	 j
}|dkr`td
 jj _ jj _d S )Nrunz0Parameter 'body' must have a method 'run', type .r   z'Scan requires num_scan_inputs > 0, got c                   2   g | ]} j d u s|t j krdn j | qS Nr   )scan_input_directionslen.0iself a/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/onnx/reference/ops/op_scan.py
<listcomp>       
z!Scan.__init__.<locals>.<listcomp>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num_scan_inputsrange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__returnboolc                 C  s   dS )zScan body subgraphs may reference names from the enclosing graph
        (lexical capture, per the ONNX spec). Request the outer-scope
        context so those names resolve at body-evaluation time.
        Tr   r   r   r   r   need_context6   s   zScan.need_contextc                   s   t | j }t  j| } fddt|D }|rt|nd}|dkr)td fddt|D }|r:t|nd}|dkrDtd jd | } jd t | }	 j|d  }
 j|d  }||d  }t|d | }||||||||	|
|||fS )Nc                   r   r   )scan_output_directionsr
   r   r   r   r   r   A   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   O   r   z5Scan is not implemented for other output axes than 0.)r
   r   r!   r   r   r   r    list)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)contextr   r   r   r	   r*   r)   
attributesc                  sv  | j |	 \}
}}}}}}}}}}}|	|
 j| jd  }dd |D }t|D ]t i }|d ur3|| |tt||dd | fddt||ddD  z| |}W n tyo } ztdt	| j
 d	|d }~ww tt| j|ddfd
d|D }t|D ]\}}|| tj| dd qq&|dkr|rtd|D ]}|tj|dd q| t|S )Nr   c                 S  s   g | ]}g qS r   r   )r   _r   r   r   r      s    zScan._run.<locals>.<listcomp>F)strictc                   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   r>   )outputsr   r   r      s    )axiszCScan with zero scan-input length and scan outputs is not supported.)r9   shaper   r   updatedictzip	_run_body	TypeErrorr   r   r!   	enumerateappendnpexpand_dimsr   concatenate_check_and_fix_outputstuple)r   r:   r   r   r   r	   r*   r)   r;   r,   r-   _num_scan_outputs_output_directions_max_dir_out_output_axes_max_axe_outr3   r4   r5   r6   r7   r8   max_iterresultsinputsoutputs_lister   r>   resr   )r@   rB   r   _runr   s`   

z	Scan._run)r&   r'   )__name__
__module____qualname__r   r(   r9   r\   r   r   r   r   r      s    
*8r   )
__future__r   numpyrL   onnx.reference.op_runr   r   r   r   r   r   <module>   s   