
    0;ji                         d dl mZ d dlmZmZ  G d de          Z G d de          Zd ZdZ	d	Z
d
ZdZ G d de          ZdS )    )deque)typescgutilsc                   2    e Zd ZdZd Zd ZddZd Zd ZdS )	
DataPackerz
    A helper to pack a number of typed arguments into a data structure.
    Omitted arguments (i.e. values with the type `Omitted`) are automatically
    skipped.
    c                 f   | _         || _        fd|D             | _        g | _        g | _        t          |          D ]p\  }}t          |t          j                  sQ| j        	                    |           | j        	                    | j        |         
                                           qd S )Nc                 :    g | ]}                     |          S  )lookup).0tydmms     U/root/voice-cloning/.venv/lib/python3.11/site-packages/numba/core/datamodel/packer.py
<listcomp>z'DataPacker.__init__.<locals>.<listcomp>   s#    :::2

2:::    )_dmm	_fe_types_models	_pack_map	_be_types	enumerate
isinstancer   Omittedappendget_data_type)selfr   fe_typesir   s    `   r   __init__zDataPacker.__init__   s    	!:::::::x(( 	G 	GEArb%-00 G%%a(((%%dl1o&C&C&E&EFFF	G 	Gr   c                 \      fd j         D             }t          j        |          S )zE
        Return the given values packed as a data structure.
        c                 ^    g | ])}j         |                             |                   *S r
   )r   as_data)r   r   builderr   valuess     r   r   z&DataPacker.as_data.<locals>.<listcomp>   sC     * * * a((&)<< * * *r   )r   r   make_anonymous_struct)r   r#   r$   elemss   ``` r   r"   zDataPacker.as_data   sL    * * * * * *.* * *,We<<<r   Nc                    g }t          | j                  D ]g\  }}t          j        ||d|          }| j        |                             ||          }|#|                    | j        |         |f           b|||<   h|S Nr   )r   r   r   gep_inboundsr   load_from_data_pointerr   r   )	r   r#   ptrformal_listresr   i_formalelem_ptrvals	            r   _do_loadzDataPacker._do_load#   s    $T^44 	, 	,KAx+GS!Q??H,x(??RRC"

DN84c:;;;;(+H%%
r   c                 .    |                      ||          S )zK
        Load the packed values and return a (type, value) tuples.
        r1   )r   r#   r+   s      r   loadzDataPacker.load.   s     }}Wc***r   c                 4    |                      |||           dS )z
        Load the packed values into a sequence indexed by formal
        argument number (skipping any Omitted position).
        Nr3   )r   r#   r+   r,   s       r   	load_intozDataPacker.load_into4   s     
 	gsK00000r   N)	__name__
__module____qualname____doc__r   r"   r1   r4   r6   r
   r   r   r   r      sq         
G 
G 
G= = =	 	 	 	+ + +1 1 1 1 1r   r   c                   H    e Zd ZdZd Zd Zd Zd Zd
dZe	d             Z
d	S )	ArgPackera  
    Compute the position for each high-level typed argument.
    It flattens every composite argument into primitive types.
    It maintains a position map for unflattening the arguments.

    Since struct (esp. nested struct) have specific ABI requirements (e.g.
    alignment, pointer address-space, ...) in different architecture (e.g.
    OpenCL, CUDA), flattening composite argument types simplifes the call
    setup from the Python side.  Functions are receiving simple primitive
    types and there are only a handful of these.
    c                    || _         || _        t          |          | _        g | _        g }|D ]]}| j                             |          }| j                            |           |                    |                                           ^t          |          | _	        t          t          |                    | _        d S r7   )r   _fe_argslen_nargs_dm_argsr   r   get_argument_type_Unflattener_unflattenerlist_flatten_be_args)r   r   fe_argsargtysr   dms         r   r   zArgPacker.__init__I   s    	'll 	2 	2B!!"%%BM  $$$MM"..001111(00Xf--..r   c                    t          |          | j        k    r&t          d| j        t          |          fz            |sdS fdt          | j        |          D             }t          t          |                    }|S )z$Flatten all argument values
        z+invalid number of args: expected %d, got %dr
   c                 B    g | ]\  }}|                     |          S r
   )as_argumentr   rK   r0   r#   s      r   r   z*ArgPacker.as_arguments.<locals>.<listcomp>a   s;       B w,,   r   )r@   rA   	TypeErrorziprB   tuplerG   )r   r#   r$   argss    `  r   as_argumentszArgPacker.as_argumentsW   s     v;;$+%%I#{CKK89 : : :  	2   "4=&99   Xd^^$$r   c                 ~    | j                             |          }fdt          | j        |          D             }|S )z&Unflatten all argument values
        c                 B    g | ]\  }}|                     |          S r
   )from_argumentrO   s      r   r   z,ArgPacker.from_arguments.<locals>.<listcomp>m   s=       b# ""7C00   r   )rE   	unflattenrQ   rB   )r   r#   rS   valtreer$   s    `   r   from_argumentszArgPacker.from_argumentsh   sV     #--d33   !$T]G!<!<   r   c                     | j                             |          }t          ||          D ]\  }}|                     ||           dS )z9Assign names for each flattened argument values.
        N)rE   rX   rQ   _assign_names)r   rS   namesrY   avalanames         r   assign_nameszArgPacker.assign_namess   sZ     #--d33w.. 	, 	,KD%tU++++	, 	,r   r
   c                 V   t          |t          t          f          r3t          |          D ]!\  }}|                     ||||fz              "d S d                    t          t          |                    }||g}d                    t          t          |                    |_
        d S )N)depth.)r   rR   rF   r   r\   joinmapstrfilterboolname)r   val_or_nestedri   rb   posr^   postfixpartss           r   r\   zArgPacker._assign_names{   s    meT]33 	?&}55 E E	T""4UcV^"DDDDE E hhs3//G7OE!$&u*=*=!>!>Mr   c                 >    t          d | j        D                       S )z\Return a list of LLVM types that are results of flattening
        composite types.
        c              3   &   K   | ]}|d k    |V  dS )r
   Nr
   )r   r   s     r   	<genexpr>z+ArgPacker.argument_types.<locals>.<genexpr>   s&      <<B288R8888<<r   )rR   rH   )r   s    r   argument_typeszArgPacker.argument_types   s#    
 <<$-<<<<<<r   N)r
   )r8   r9   r:   r;   r   rT   rZ   r`   r\   propertyrq   r
   r   r   r=   r=   <   s        
 
/ / /  "	 	 	, , ,? ? ? ? = = X= = =r   r=   c                 $    fd |           S )z3
    Flatten nested iterable of (tuple, list).
    c              3   |   K   | D ]5}t          |t          t          f          r |          D ]}|V  1|V  6d S r7   )r   rR   rF   )iterabler   jrecs      r   rw   z_flatten.<locals>.rec   sj       	 	A!eT]++ Q  AGGGG 	 	r   r
   )ru   rw   s    @r   rG   rG      s,         3x==r               c                   $    e Zd ZdZd Zd Zd ZdS )rD   z
    An object used to unflatten nested sequences after a given pattern
    (an arbitrarily nested sequence).
    The pattern shows the nested sequence shape desired when unflattening;
    the values it contains are irrelevant.
    c                 :    |                      |          | _        d S r7   )_build_unflatten_code_code)r   patterns     r   r   z_Unflattener.__init__   s    //88


r   c                 0    g fd |           S )zzBuild the unflatten opcode sequence for the given *iterable* structure
        (an iterable of nested sequences).
        c                 Z   | D ]}t          |t          t          f          rnt          |          dk    r@                    t
                      |                               t                     q                    t                                         t                     d S r(   )	r   rR   rF   r@   r   
_PUSH_LIST_POP_APPEND_EMPTY_TUPLE_APPEND_NEXT_VALUE)ru   r   coderw   s     r   rw   z/_Unflattener._build_unflatten_code.<locals>.rec   s     	4 	4a%// 41vvzzJ///AD))))$78888KK 23333	4 	4r   r
   )r   ru   r   rw   s     @@r   r~   z"_Unflattener._build_unflatten_code   s=     
	4 
	4 
	4 
	4 
	4 
	4 	Hr   c                    t          |          }g }|}g }| j        D ]}|t          u r3|                    |           |                    g            |d         }>|t          u r(|                    |                                           o|t          u r|                    d           |t          u r|                                }|r
J |            |r
J |            |S )z*Rebuild a nested tuple structure.
        r
   )	r   r   r   r   r   popleftr   r   pop)r   flatitervalsr-   curstackops          r   rX   z_Unflattener.unflatten   s     X* 
	" 
	"BZS!!!

2"g)))

4<<>>*******

2tiikk%yx
r   N)r8   r9   r:   r;   r   r~   rX   r
   r   r   rD   rD      sK         9 9 9  (    r   rD   N)collectionsr   
numba.corer   r   objectr   r=   rG   r   r   r   r   rD   r
   r   r   <module>r      s          % % % % % % % %21 21 21 21 21 21 21 21jM= M= M= M= M= M= M= M=`   
  6 6 6 6 66 6 6 6 6 6r   