
    Upf)              	          d dl mZmZmZmZm	Z
mZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZ g dZd Zd Zdd	Zd
eej        j        ej        j        ej        j        ej        j        f         dej        j        fdZ d
eej        j        ej        j        eeej        j        ej        j        ej        j        f                  f         deeej        j                 ej        j        f         fdZ!deej        j        ej        j        f         deej        j        ej        j"        eej        j"                 f         fdZ#ej        j        ej        j        ej        j        fZ$ee$         Z%ee%ee%         f         Z&ee'ef         Z(eeeef         Z)ee(e)f         Z*eeee'f                  Z+eeee+f                  Z,eeee-f                  Z.eeee.f                  Z/eeee(e)f                  ee)f         Z0eee*ee*         f                  Z1dee1ef         deee)         eee'         ef         ee-         f         fdZ2de0deee         eeeef         ef         fdZ3dee4eef         de4fdZ5deee4         ef         dee4         fdZ6deeee+f                  defdZ7deeeeeee+f                  f                  defdZ8dS )    )ListOptionalSequenceTupleTypeUnion   )_mlir)
	ArrayAttr	AttributeBoolAttrDenseI64ArrayAttrIntegerAttrIntegerTypeOpView	Operation
ShapedTypeValue)equally_sized_accessorget_default_loc_contextget_op_result_or_valueget_op_results_or_valuesget_op_result_or_op_resultssegmented_accessorc                     t           j                            |          t          fdt	          |          D                       }||         z   }| ||         S )a  
    Returns a slice of elements corresponding to the idx-th segment.

      elements: a sliceable container (operands or results).
      raw_segments: an mlir.ir.Attribute, of DenseI32Array subclass containing
          sizes of the segments.
      idx: index of the segment.
    c              3   (   K   | ]}|         V  d S N ).0isegmentss     `/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jaxlib/mlir/dialects/_ods_common.py	<genexpr>z%segmented_accessor.<locals>.<genexpr>0   s'      00000000    )_cextirDenseI32ArrayAttrsumrange)elementsraw_segmentsidxstartendr!   s        @r"   r   r   &   s_     x)),77H0000U3ZZ00000E
(3-
CE#Ir$   c                 d    t          |           |z
  dz   }||z  dk    sJ ||z  }|||z  z   }||fS )a  
    Returns a starting position and a number of elements per variadic group
    assuming equally-sized groups and the given numbers of preceding groups.

      elements: a sequential container.
      n_variadic: the number of variadic groups in the container.
      n_preceding_simple: the number of non-variadic groups preceding the current
          group.
      n_preceding_variadic: the number of variadic groups preceding the current
          group.
       r   )len)r*   
n_variadicn_preceding_simplen_preceding_variadictotal_variadic_lengthelements_per_groupr-   s          r"   r   r   5   sX      MMJ6: :-2222.*<!58J!JJE$$$r$   Nc                 J    | t           j        j        j        j        S | j        S )z
    Returns a context in which the defaulted location is created. If the location
    is None, takes the current location from the stack, raises ValueError if there
    is no location on the stack.
    )r%   r&   Locationcurrentcontext)locations    r"   r   r   M   s$     x (00r$   argreturnc                 8   t          | t          j        j                  r| j        j        S t          | t          j        j                  r| j        S t          | t          j        j                  r| d         S t          | t          j        j                  sJ | S )a5  Returns the given value or the single result of the given op.

    This is useful to implement op constructors so that they can take other ops as
    arguments instead of requiring the caller to extract results for every op.
    Raises ValueError if provided with an op that doesn't have a single result.
    r   )	
isinstancer%   r&   r   	operationresultr   OpResultListr   r<   s    r"   r   r   Y   s     #ux'' }##	C+	,	, z	C.	/	/ 1v#ux~.....
r$   c                     t          | t          j        j                  r| j        j        S t          | t          j        j                  r| j        S d | D             S )zReturns the given sequence of values or the results of the given op.

    This is useful to implement op constructors so that they can take other ops as
    lists of arguments instead of requiring the caller to extract results for
    every op.
    c                 ,    g | ]}t          |          S r   )r   )r   elements     r"   
<listcomp>z,get_op_results_or_values.<locals>.<listcomp>   s!    CCCG&w//CCCr$   )r?   r%   r&   r   r@   resultsr   rC   s    r"   r   r   o   sZ     #ux'' D}$$	C+	,	, D{CCsCCCCr$   opc                    t          | t          j        j                  r| j        } t          | j                  dk    rt          t          |                     n(t          | j                  dk    rt          |           n| S )Nr0   r   )
r?   r%   r&   r   r@   r1   rH   listr   r   )rI   s    r"   r   r      s|     "eho&& \ rz??Q 	%b))*** rz??Q $B'''r$   indicesc                 r   g t          j                    gt          |           z  dgt          |           z  }t          | t                    rd | D             } fd}t          |           D ]A\  }} |||          s0d||<   t          |          dk    sJ  |||d                   }|sJ B|fS )a  Dispatches a list of indices to the appropriate form.

    This is similar to the custom `DynamicIndexList` directive upstream:
    provided indices may be in the form of dynamic SSA values or static values,
    and they may be scalable (i.e., as a singleton list) or not. This function
    dispatches each index into its respective form. It also extracts the SSA
    values and static indices from various similar structures, respectively.
    Fc                     g | ]}|S r   r   )r   r,   s     r"   rG   z0_dispatch_dynamic_index_list.<locals>.<listcomp>   s    ***33***r$   c                     t          |t                    r|| <   nZt          |t                    r|j        | <   n:t          |t          t
          t          f          r                    |           ndS dS )zProcesses any form of non-scalable index.

        Returns False if the given index was scalable and thus remains
        unprocessed; True otherwise.
        FT)r?   intr   valuer   r   r   append)r    indexdynamic_indicesstatic_indicess     r"   process_nonscalable_indexz?_dispatch_dynamic_index_list.<locals>.process_nonscalable_index   s     eS!! 	 %N1{++ 	 %N1	5&9:: 	""5))))5tr$   Tr0   r   )r   get_dynamic_sizer1   r?   r   	enumerate)rL   scalable_indicesrV   r    rS   retrT   rU   s         @@r"   _dispatch_dynamic_index_listr[      s     O 1334s7||CNwW- '9%% +**'***     " g&&  5((E22 	 #'Qu::????++AuQx88CJJJN,<<<r$   valuesc                    g }d }d }t          | t                    r| }nt          | t          t          t          f          r| }ng }| pg D ]h}t          |t
                    r|                    |           -|                    t          j                               |                    |           it          j
        |          }|||fS r   )r?   r   r   r   r   rP   rR   r   rW   r   get)r\   dynamic_valuespacked_valuesstatic_valuessizes        r"   _dispatch_mixed_valuesrc      s     NMM&)$$ =	FYv6	7	7 
=Lb 	, 	,D$$$ ,$$T****$$Z%@%B%BCCC%%d++++)-m<<M=99r$   value_or_attrc                     t          | t                    rt          | d          r| j        S t          | t                    rt          |           S | S )NrQ   )r?   r   hasattrrQ   r   _get_value_list)rd   s    r"   _get_value_or_attribute_valuerh      sV     -++ #w0O0O #""-++ .}---r$   sequence_or_array_attrc                     d | D             S )Nc                 ,    g | ]}t          |          S r   )rh   r   vs     r"   rG   z#_get_value_list.<locals>.<listcomp>  s!    MMM)!,,MMMr$   r   )ri   s    r"   rg   rg      s     NM6LMMMMr$   c                 d    | d S t          |           } t          j        d | D                       S )Nc                 \    g | ])}t          j        t          j        d           |          *S )@   )r   r^   r   get_signlessrl   s     r"   rG   z'_get_int_array_attr.<locals>.<listcomp>  s/    JJJa1"55q	9	9JJJr$   rg   r   r^   r\   s    r"   _get_int_array_attrrt     sD     ~t V$$F =JJ6JJJ  r$   c                     | dS t          |           } d | D             } d | D             } t          j        |           S )a  Creates an ArrayAttr of ArrayAttrs of IntegerAttrs.

    The input has to be a collection of a collection of integers, where any
    Python _Sequence and ArrayAttr are admissible collections and Python ints and
    any IntegerAttr are admissible integers. Both levels of collections are
    turned into ArrayAttr; the inner level is turned into IntegerAttrs of i64s.
    If the input is None, an empty ArrayAttr is returned.
    Nc                 ,    g | ]}t          |          S r   )rg   r   nesteds     r"   rG   z-_get_int_array_array_attr.<locals>.<listcomp>'  s     ;;;&of%%;;;r$   c                 ,    g | ]}t          |          S r   )rt   rw   s     r"   rG   z-_get_int_array_array_attr.<locals>.<listcomp>*  s!    ???f!&))???r$   rr   rs   s    r"   _get_int_array_array_attrrz     sZ     ~t V$$F <;F;;;F @????F =   r$   r   )9typingr   _Listr   	_Optionalr   	_Sequencer   _Tupler   _Typer   _Union
_mlir_libsr
   r%   r&   r   r   r   r   r   r   r   r   r   r   __all__r   r   r   rB   r   r   OpResultr   ResultValueTypeTupleResultValueTVariadicResultValueTrP   StaticIntLike	ValueLikeMixedIntIntOrAttrListOptionalIntListboolBoolOrAttrListOptionalBoolListMixedValuesDynamicIndexListr[   rc   anyrh   rg   rt   rz   r   r$   r"   <module>r      s  
                ( ' ' ' ' '                           % % %0	 	 	 		+UX^UX=RR
 X^	   ,D	&%(*<ehnLMN	P
D Iehn%ux'<<=D D D D*ux 223EH 19UX=N3OOP    x)58?EHNJ *+lIl,CCD sK'(9fe+,	-*+&c!123F9m#;<=6(D.12VI~$=>? YvmY&>?@)YVWVHi.A$ABC -=$i/0-=E)fU3Z%:;U4[HI-= -= -= -=t::E%L&E6!9:<MMN: : : :.#y)34   N"9S>9#<=Ns^N N N NfY567   !fY	&M9Q2R(SSTU!! ! ! ! ! !r$   