
    Vpf}                    ^   d Z ddlmZ dgZddlZddlmZmZ ddlZddl	m
Z
 ddlZddlZddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z,m-Z- e-e.cZ.Z/e,e0cZ0Z1ddd!Z2dd"dd&Z3dd(Z4dd+Z5dd,Z6	 ddd1Z7dd4Z8dd8Z9d9d:dd=Z:dddAZ;dB Z<e=e>e?ej@        ejA        e&fZBeCeDeEeFfZGddCZHdD ZIdddGZJddIZKddKZLejM        efZNeNejA        fz   ZOdL ZP	 dddddMddSZQ ejR                     eejS        dTU          dd[                        ZTejS        dd]            ZUd^ ZVd_ ZW G d` da          ZX G db dc          ZYi ddeWdeeIdeKdfeLdge!jZ        dhe!j[        di eHdje!j\                  dk eHdle!j]                  dm eHdne!j^                  do eHdpe!j_                  dq eHdre!j`                  ds eHdte!ja                  due!jb        dv eHdwe!jc                  dx eHdwe!jc        dyz          d{ eHd|e!jd                  d} eHd|e!jd        dyz          i d~ eHde!je                  d eHde!je        dyz          d eHde!jf                  d eHde!jf        dyz          d eHde!jg                  d eHde!jg        dyz          d eHde!jh                  d eHde!jh        dyz          d eHde!ji                  d eHde!ji        dyz          d eHde!jj                  d eHde!jj        dyz          d eHde!jk                  d eHde!jk        dyz          d eHdejl                  d eHdejl        dyz          d eHde!jm                   eHde!jm        dyz           eHde!jn                   eHde!jn        dyz           eHde!jo                   eHde!jo        dyz          e!jp         eHde!jq                   eHde!jr                   eHde!jq        dyz           eHde!jr        dyz          eJdZsi de jt        de ju        dejv        dejw        dejx        dejy        de2dejz        de7de!j{        de!j|        deQdej}        de j~        de j        dej        dej        i dej        de5d0e j        de j        d.e j        dej        de j        de j        dej        dej        de:dej        dej        dej        dej        de j        de j        ej        ej        e3ej        e8e j        e;ej        eTd	ZeVeUdZe<ej        ej        e!j        e!j        e4e6eXdZd Zd Zd Zd ZddZddÄZdĄ Zdń ZdƄ ZdǄ ZdS )zDefine methods which are dynamically added to JAX's Arrays and Tracers.

This is done dynamically in order to avoid circular imports.
    )annotationsregister_jax_array_methodsN)partialwraps)Any)lax)Sharding)api)core)dtypes)_ensure_index_tuple)	ArrayImpl)
xla_client)	lax_numpy)
reductions)ufuncs)util)scatter)Array	ArrayLikeDimSize	DTypeLikeShape)safe_zipsafe_mapFarrr   dtyper   copybooldevicexc.Device | Sharding | Nonereturnr   c                2    t          j        | |||          S )a3  Copy the array and cast to a specified dtype.

  This is implemented via :func:`jax.lax.convert_element_type`, which may
  have slightly different behavior than :meth:`numpy.ndarray.astype` in
  some cases. In particular, the details of float-to-int and int-to-float
  casts are implementation dependent.
  )r   r    )r   astype)r   r   r   r    s       \/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/numpy/array_methods.py_astyper&   =   s     
	#u4	?	?	??    )streamxc.Device | Shardingr(   int | Any | Nonec               N    |t          d          t          j        | |          S )Nz$stream argument of array.to_device())NotImplementedErrorr
   
device_put)r   r    r(   s      r%   
_to_devicer.   G   s)    
D
E
EE	V	$	$$r'   intc                b    t          j        |           t          j        | d          j        z  S )z2Total bytes consumed by the elements of the array.Tcanonicalize)npsizer   r   itemsizer   s    r%   _nbytesr7   N   s'    	St<<<E	EEr'   abool | int | float | complexc                    t          j        t          j        | d          }t	          j        | j        t          j                  rt          d| j                   |j	        | S )zFCopy an element of an array to a standard Python scalar and return it.z/This occurred in the item() method of jax.Array)contextz"No Python scalar type for a.dtype=)
r   concrete_or_errorr3   asarrayr   
issubdtyper   extended	TypeErroritem)r8   argsr   s      r%   _itemrC   S   s\    rz16ghhh#qw00 =
;;;
<
<<	4r'   c                8    t          j        | d          j        S )z%Length of one array element in bytes.Tr1   )r   r   r5   r6   s    r%   	_itemsizerE   Z   s    	c	-	-	-	66r'   numberminArrayLike | Nonemaxc                0    t          j        | ||          S )zyReturn an array whose values are limited to a specified range.

  Refer to :func:`jax.numpy.clip` for full documentation.)rG   rI   )r   clip)rF   rG   rI   s      r%   _cliprL   _   s    
 
CS	1	1	11r'   rB   r   c                    |sd}nHt          |          dk    r&|d         |d         nt          |d                   }nt          |          }t          j        | |          S )ztReturns a view of the array with axes transposed.

  Refer to :func:`jax.numpy.transpose` for full documentation.
  N   r   )lenr   r   	transpose)r8   rB   axiss      r%   
_transposerR   g   sf    
 
 %DD
4yyA~~1go477+>tAw+G+GDDt$$D		Q	%	%%r'   newshapeDimSize | Shaper   c                    }	 t                     n
#  gY nxY wt          j                  d t                    D             }t	          |          dk    rt          d|           |r'|\  }g d|         |dz   d         R }t          d g t          j                   |R D                       rt          j	                   t          j        |          z  dk    rft          dt          j                    dt          j	                    d	| d
t          j        |           dt          j	                    
          t          j        t          j                   |          }|g d|         ||dz   d         R S nt          d g t          j                   R D                       r|t          j	                   t          j                  k    rRt          dt          j                    dt          j	                    d	| dt          j                   d	          t           fdD                       S )z)Fixes a -1 value in newshape, if present.c                P    g | ]#\  }}t          |          t          u |d k    !|$S ))typer/   ).0ids      r%   
<listcomp>z%_compute_newshape.<locals>.<listcomp>}   s/    
K
K
KAQ31771777r'   rN   z>can only specify one unknown axis size with a `-1` value, got Nc              3  @   K   | ]}t          |t                    V  d S N
isinstancer/   rY   r[   s     r%   	<genexpr>z$_compute_newshape.<locals>.<genexpr>   s,      EE1Jq#EEEEEEr'   r   zcannot reshape array of shape z (size z) into shape z. because the product of specified axis sizes (z) does not evenly divide c              3  @   K   | ]}t          |t                    V  d S r^   r_   ra   s     r%   rb   z$_compute_newshape.<locals>.<genexpr>   s,      BB1Jq#BBBBBBr'   )c              3     K   | ]C}t          j        |d           r(t          j        t          j                             n|V  DdS )rW   N)r   definitely_equaldivide_shape_sizesr3   shape)rY   r[   r8   rS   s     r%   rb   z$_compute_newshape.<locals>.<genexpr>   sn       I I:;$'2..6'X>>>>45I I I I I Ir'   )iterr   canonicalize_shape	enumeraterO   r@   allr3   rh   r4   mathprodcancel_divide_tracerstuple)r8   rS   orig_newshapeneg1srZ   other_sizesszs   ``     r%   _compute_newshaperu   u   s   -NNNNzHHH$X..(
K
K8,,
K
K
K%ZZ!^^
 +(+ + , , ,
 R	BA2HRaRL28AaCDD>22KEE(D"(1++(D(D(DEEEEE 9


TY{+++q00 8rx{{ 8 827ST:: 8 8$18 8/3y/E/E8 8 ,.71::8 8 9 9 9 
	#BHQKK	=	=B	~1x|1R1(1Q344.111  	BB(A"(1++(A(A(ABBBBB R


di)))) Qrx{{ Q Q27ST:: Q Q$1Q Q:>)H:M:MQ Q Q R R R	 I I I I I?GI I I 
I 
I Is    C)orderrw   strc                  d}t          | t          |          dk    r|d         n|          }|dk    rt          j        | |d          S |dk    rNt	          t          | j                  ddd                   }t          j        | |ddd         |          j        S |dk    rt          d	          t          d
| d          )z|Returns an array containing the same data with a new shape.

  Refer to :func:`jax.numpy.reshape` for full documentation.
  TrN   r   rv   NFrW   Az&np.reshape order=A is not implemented.z'Unexpected value for 'order' argument: .)
ru   rO   r   reshapelistrangendimTr,   
ValueError)r8   rw   rB   __tracebackhide__rS   dimss         r%   _reshaper      s    
 qSYY!^^$q''FF(
c\\;q(D)))||afddd#$$D;q(44R4.$//11||
F
G
GG
GuGGG
H
HHr'   DTypeLike | NonerX   Nonec                P   |t          d          t          j        d|            t          j        |           } t          j        |d           t          j        |          }| j        dk    rY| j	        j
        |j
        k    rt          d          t          t          j        | d          |                                          S | j        d         | j	        j
        z  |j
        z  dk    rt          d          | j	        |k    r| S | j	        t"          k    r#t          |                     d	          |          S t          j        | j	        t(          j                  rg | j        dd         | j        d         d
z  R }t          j        | j	                  j	        }t          j        ||          j        dddd
f                             | j                  j        dddd
f                             | j                  } t          | |          S |t"          k    r2t          | t(          j                                      t"                    S t          j        |t(          j                  rXt          | t          j        |          j	                                      |          }|dddd
f         d|dddd
f         z  z   S | j	        j
        |j
        k     rU|j
        | j	        j
        z  } | j        g | j        dd         | j        d         |z  |R  } t          j        | |          S | j	        j
        |j
        k    rJt          j        | |          } |j        g |j        dd         |j        d         |j        d         z  R  S t          j        | |          S )a  Return a bitwise copy of the array, viewed as a new dtype.

  This is fuller-featured wrapper around :func:`jax.lax.bitcast_convert_type`.

  If the source and target dtype have the same bitwidth, the result has the same
  shape as the input array. If the bitwidth of the target dtype is different
  from the source, the size of the last axis of the result is adjusted
  accordingly.

  >>> jnp.zeros([1,2,3], dtype=jnp.int16).view(jnp.int8).shape
  (1, 2, 6)
  >>> jnp.zeros([1,2,4], dtype=jnp.int8).view(jnp.int16).shape
  (1, 2, 2)

  Conversions involving booleans are not well-defined in all situations. With
  regards to the shape of result as explained above, booleans are treated as
  having a bitwidth of 8. However, when converting to a boolean array, the input
  should only contain 0 or 1 bytes. Otherwise, results may be unpredictable or
  may change depending on how the result is used.

  This conversion is guaranteed and safe:
  >>> jnp.array([1, 0, 1], dtype=jnp.int8).view(jnp.bool_)
  Array([ True, False,  True], dtype=bool)

  However, there are no guarantees about the results of any expression involving
  a view such as this: `jnp.array([1, 2, 3], dtype=jnp.int8).view(jnp.bool_)`.
  In particular, the results may change between JAX releases and depending on
  the platform. To safely convert such an array to a boolean array, compare it
  with `0`:

  >>> jnp.array([1, 2, 0], dtype=jnp.int8) != 0
  Array([ True,  True, False], dtype=bool)
  Nz1`type` argument of array.view() is not supported.viewr   zDview() of a 0d array is only supported if the itemsize is unchanged.)r   rW   zuWhen changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array.uint8   .rN   y              ?)r,   r   check_arrayliker   r=   r   check_user_dtype_supportedcanonicalize_dtyper   r   r5   r   _viewr   expand_dimssqueezerh   r   r$   r>   r3   complexfloatingfinfozerosatsetrealimagr   r}   bitcast_convert_type)r   r   rX   	new_shape	new_dtypeoutfactors          r%   r   r      sa   D 

Q
R
RRvs######E6222

#E
*
*%X]]
yU^++]^^^d++U33;;===	imci((EN:a??
 Q R R R 	Y%J 	Y$G$$e,,,#)R%788 4#)CRC.4#)B-!"344I	**0I?9i00addCMMaddCMM  e
d]]bh&&t,,,%!344 0
Y_U++1
2
2
9
9%
@
@CsADqDy>BS!$Q$Y/// 	Y%.((^sy11F
#+
Gsy"~
Gsy}'>
G
G
G
GC#C///Y%.((

"3
.
.C3;F	#2#F	"	"(EFFFF		!#u	-	--r'   c                     t          d          )z8Not implemented: Use :meth:`~jax.Array.flatten` instead.zRJAX Arrays do not implement the arr.flat property: consider arr.flatten() instead.r,   selfs    r%   _notimplemented_flatr     s     > 	? 	? ?r'   c                      fd}|S )Nc                ^   t          |d          r|                                }r|| fn| |f}t          |t                    r | S t	          |          t
          v rHt          d dt	          |d                   j        dt	          |d                   j                  t          S )N__jax_array__z unsupported operand type(s) for z: r   z and rN   )	hasattrr   r`   _accepted_binop_typesrX   _rejected_binop_typesr@   __name__NotImplemented)r   otherrB   	binary_opopcharswaps      r%   deferring_binary_opz7_defer_to_unrecognized_arg.<locals>.deferring_binary_op  s    uo&& $!!##e 3E4==tUmD%.// Y E{{+++ S S Sd1g/S S8<T!W8NS S T T Tr'    )r   r   r   r   s   ``` r%   _defer_to_unrecognized_argr   	  s0           
r'   c                d    d}t          |                    t          |                               )Nz'{}' object does not support item assignment. JAX arrays are immutable. Instead of ``x[idx] = y``, use ``x = x.at[idx].set(y)`` or another .at[] method: https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.ndarray.at.html)r@   formatrX   )r   rZ   xmsgs       r%   _unimplemented_setitemr     s,    
W# 	#**T$ZZ(()))r'   ndigits
int | Nonec                n    t          j        | |pd          }||                    t                    n|S )Nr   )decimals)r   roundr$   r/   )rF   r   r   s      r%   _operator_roundr      s2    A666##OC4r'   r   c                *    |                                  S r^   r   r   s    r%   _copyr   %  s    	r'   memoc                ,    ~|                                  S r^   r   )r   r   s     r%   	_deepcopyr   (  s    
	r'   c                Z    t          d |D                       rt          j        S t          S )Nc              3  @   K   | ]}t          |t                    V  d S r^   )
issubclass_HANDLED_ARRAY_TYPES)rY   ts     r%   rb   z#__array_module__.<locals>.<genexpr>3  s-      <<A+	,	,<<<<<<r'   )rl   jaxnumpyr   )r   typess     r%   __array_module__r   2  s/    <<e<<<<< 9r'   )r   r4   
fill_value	conditionrQ   r   r4   r   c               6    t          j        || ||||          S )zuReturn selected slices of this array along given axis.

  Refer to :func:`jax.numpy.compress` for full documentation.)rQ   r   r4   r   )r   compress)r8   r   rQ   r   r4   r   s         r%   _compress_methodr   9  s+     
	Iqt!%*
> 
> 
> >r'   )rN   r      )static_argnumsstart_indicestuple[tuple[int, ...]]limit_indicesremoved_dimslist[Array]c                    g }t          |||          D ]H\  }}}t          j        | ||          }|rt          j        ||          }|                    |           I|S )zExtracts multiple slices from `arr`.

  This is used to shard Array arguments to pmap. It's implemented as a
  Array method here to avoid circular imports.
  )zipr   slicer   append)	r   r   r   r   resultsstartslimitsremovedsliceds	            r%   _multi_slicer   C  sq     '!$]M<!P!P  ffgYsFF++F ,{67++fNN6	.r'   r   c                P      fdt           j        d                   D             S )Nc                >    g | ]}t          j        |d           S )F)keepdims)r   index_in_dim)rY   rZ   r   s     r%   r\   z_unstack.<locals>.<listcomp>Z  s+    	L	L	LQ#
1a%
0
0
0	L	L	Lr'   r   )r   rh   )r   s   `r%   _unstackr   X  s+    	L	L	L	L%
:K:K	L	L	LLr'   c              #    K   || j         d         k    r| V  d S t          j        | j         d         |          \  }}t          |          D ]}t	          j        | ||z  |          V  |rt	          j        | ||z  |          V  d S d S )Nr   )rh   r   divmodr   r   dynamic_slice_in_dim)r   r4   
num_chunkstailrZ   s        r%   _chunk_iterr   \  s      	AGAJ
GGGGG}QWQZ66J: 8 8$QD$777777 A$Q
T(94@@@@@@@A Ar'   c                ,    t          j        | |          S r^   )r   _rewriting_take)r   rA   s     r%   _getitemr   f  s    		"4	.	..r'   c                  (    e Zd ZdZdZd Zd Zd ZdS )_IndexUpdateHelpera!  Helper property for index update functionality.

  The ``at`` property provides a functionally pure equivalent of in-place
  array modifications.

  In particular:

  ==============================  ================================
  Alternate syntax                Equivalent In-place expression
  ==============================  ================================
  ``x = x.at[idx].set(y)``        ``x[idx] = y``
  ``x = x.at[idx].add(y)``        ``x[idx] += y``
  ``x = x.at[idx].multiply(y)``   ``x[idx] *= y``
  ``x = x.at[idx].divide(y)``     ``x[idx] /= y``
  ``x = x.at[idx].power(y)``      ``x[idx] **= y``
  ``x = x.at[idx].min(y)``        ``x[idx] = minimum(x[idx], y)``
  ``x = x.at[idx].max(y)``        ``x[idx] = maximum(x[idx], y)``
  ``x = x.at[idx].apply(ufunc)``  ``ufunc.at(x, idx)``
  ``x = x.at[idx].get()``         ``x = x[idx]``
  ==============================  ================================

  None of the ``x.at`` expressions modify the original ``x``; instead they return
  a modified copy of ``x``. However, inside a :py:func:`~jax.jit` compiled function,
  expressions like :code:`x = x.at[idx].set(y)` are guaranteed to be applied in-place.

  Unlike NumPy in-place operations such as :code:`x[idx] += y`, if multiple
  indices refer to the same location, all updates will be applied (NumPy would
  only apply the last update, rather than applying all updates.) The order
  in which conflicting updates are applied is implementation-defined and may be
  nondeterministic (e.g., due to concurrency on some hardware platforms).

  By default, JAX assumes that all indices are in-bounds. Alternative out-of-bound
  index semantics can be specified via the ``mode`` parameter (see below).

  Arguments
  ---------
  mode : str
      Specify out-of-bound indexing mode. Options are:

      - ``"promise_in_bounds"``: (default) The user promises that indices are in bounds.
        No additional checking will be performed. In practice, this means that
        out-of-bounds indices in ``get()`` will be clipped, and out-of-bounds indices
        in ``set()``, ``add()``, etc. will be dropped.
      - ``"clip"``: clamp out of bounds indices into valid range.
      - ``"drop"``: ignore out-of-bound indices.
      - ``"fill"``: alias for ``"drop"``.  For `get()`, the optional ``fill_value``
        argument specifies the value that will be returned.

        See :class:`jax.lax.GatherScatterMode` for more details.

  indices_are_sorted : bool
      If True, the implementation will assume that the indices passed to ``at[]``
      are sorted in ascending order, which can lead to more efficient execution
      on some backends.
  unique_indices : bool
      If True, the implementation will assume that the indices passed to ``at[]``
      are unique, which can result in more efficient execution on some backends.
  fill_value : Any
      Only applies to the ``get()`` method: the fill value to return for out-of-bounds
      slices when `mode` is ``'fill'``. Ignored otherwise. Defaults to ``NaN`` for
      inexact types, the largest negative value for signed types, the largest positive
      value for unsigned types, and ``True`` for booleans.

  Examples
  --------
  >>> x = jnp.arange(5.0)
  >>> x
  Array([0., 1., 2., 3., 4.], dtype=float32)
  >>> x.at[2].add(10)
  Array([ 0.,  1., 12.,  3.,  4.], dtype=float32)
  >>> x.at[10].add(10)  # out-of-bounds indices are ignored
  Array([0., 1., 2., 3., 4.], dtype=float32)
  >>> x.at[20].add(10, mode='clip')
  Array([ 0.,  1.,  2.,  3., 14.], dtype=float32)
  >>> x.at[2].get()
  Array(2., dtype=float32)
  >>> x.at[20].get()  # out-of-bounds indices clipped
  Array(4., dtype=float32)
  >>> x.at[20].get(mode='fill')  # out-of-bounds indices filled with NaN
  Array(nan, dtype=float32)
  >>> x.at[20].get(mode='fill', fill_value=-1)  # custom fill value
  Array(-1., dtype=float32)
  arrayc                    || _         d S r^   r   )r   r   s     r%   __init__z_IndexUpdateHelper.__init__  s    DJJJr'   c                ,    t          | j        |          S r^   )_IndexUpdateRefr   )r   indexs     r%   __getitem__z_IndexUpdateHelper.__getitem__  s    4:u---r'   c                    d| j         dS )Nz_IndexUpdateHelper(rd   r   r   s    r%   __repr__z_IndexUpdateHelper.__repr__  s    00000r'   N)r   
__module____qualname____doc__	__slots__r   r   r   r   r'   r%   r   r   j  sU        R Rf )  . . .1 1 1 1 1r'   r   c                      e Zd ZdZdZd Zd ZddddddZdddd	d
Zdddd	dZ	dddd	dZ
dddd	dZeZdddd	dZdddd	dZdddd	dZdddd	dZdS )r   a  Helper object to call indexed update functions for an (advanced) index.

  This object references a source array and a specific indexer into that array.
  Methods on this object return copies of the source array that have been
  modified at the positions specified by the indexer.
  r   r   c                "    || _         || _        d S r^   r  )r   r   r   s      r%   r   z_IndexUpdateRef.__init__  s    DJDJJJr'   c                (    d| j         d| j        dS )Nz_IndexUpdateRef(z, rd   r  r   s    r%   r   z_IndexUpdateRef.__repr__  s    =dj==dj====r'   FNindices_are_sortedunique_indicesmoder   c               J    t          j        | j        | j        ||||          S )al  Equivalent to ``x[idx]``.

    Returns the value of ``x`` that would result from the NumPy-style
    :mod:indexing <numpy.doc.indexing>` ``x[idx]``. This function differs from
    the usual array indexing syntax in that it allows additional keyword
    arguments ``indices_are_sorted`` and ``unique_indices`` to be passed.

    See :mod:`jax.ops` for details.
    r  )r   r   r   r   )r   r  r  r  r   s        r%   getz_IndexUpdateRef.get  s1     $TZ8J4B0:< < < <r'   r  r  r  c          	     `    t          j        | j        | j        |t          j         |||          S )zPure equivalent of ``x[idx] = y``.

    Returns the value of ``x`` that would result from the NumPy-style
    :mod:`indexed assignment <numpy.doc.indexing>` ``x[idx] = y``.

    See :mod:`jax.ops` for details.
    r  )r   _scatter_updater   r   r   r   valuesr  r  r  s        r%   r   z_IndexUpdateRef.set  s8     "4:tz63;6H2@tM M M Mr'   c          	         fd}t          j        | j        | j        t	          j        | j        j                  ||||          S )a2  Pure equivalent of ``func.at(x, idx)`` for a unary ufunc ``func``.

    Returns the value of ``x`` that would result from applying the unary
    function ``func`` to ``x`` at the given indices. This is similar to
    ``x.at[idx].set(func(x[idx]))``, but differs in the case of repeated indices:
    in ``x.at[idx].apply(func)``, repeated indices result in the function being
    applied multiple times.

    Note that in the current implementation, ``scatter_apply`` is not compatible
    with automatic differentiation.

    See :mod:`jax.ops` for details.
    c                <    t          j        | ||fd|j        i|S )Nupdate_shape)r   scatter_applyrh   )r   indicesyr   kwargsfuncs        r%   _scatter_applyz-_IndexUpdateRef.apply.<locals>._scatter_apply  s)    q'4VVAGVvVVVr'   r  )r   r  r   r   lax_internal_zeror   )r   r  r  r  r  r  s    `    r%   applyz_IndexUpdateRef.apply  se    W W W W W"4:tz#/#5dj6F#G#G#16H2@t	M M M Mr'   c          	     `    t          j        | j        | j        |t          j        |||          S )zPure equivalent of ``x[idx] += y``.

    Returns the value of ``x`` that would result from the NumPy-style
    :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] += y``.

    See :mod:`jax.ops` for details.
    r  )r   r  r   r   r   scatter_addr  s        r%   addz_IndexUpdateRef.add  s9     "4:tz6#&?6H2@tM M M Mr'   c          	     `    t          j        | j        | j        |t          j        |||          S )zPure equivalent of ``x[idx] *= y``.

    Returns the value of ``x`` that would result from the NumPy-style
    :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] *= y``.

    See :mod:`jax.ops` for details.
    r  )r   r  r   r   r   scatter_mulr  s        r%   multiplyz_IndexUpdateRef.multiply  s6     "4:tz6#&?6H2@(,	. . . .r'   c                   t          j        | j        t          j        t          j        | j                  | j        |t          j	        |||                    S )zPure equivalent of ``x[idx] /= y``.

    Returns the value of ``x`` that would result from the NumPy-style
    :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] /= y``.

    See :mod:`jax.ops` for details.
    r  )
r   divider   r   r  r   	ones_liker   r   r   r  s        r%   r#  z_IndexUpdateRef.divide-  sZ     =
ji1$*==tz6!o1C-;$H H HI I Ir'   c                   t          j        | j        t          j        t          j        | j                  | j        |t          j	        |||                    S )zPure equivalent of ``x[idx] **= y``.

    Returns the value of ``x`` that would result from the NumPy-style
    :mod:indexed assignment <numpy.doc.indexing>` ``x[idx] **= y``.

    See :mod:`jax.ops` for details.
    r  )
r   powerr   r   r  r   r$  r   r   r   r  s        r%   r&  z_IndexUpdateRef.power=  sZ     <
ji1$*==tz6!o1C-;$H H HI I Ir'   c          	     `    t          j        | j        | j        |t          j        |||          S )zPure equivalent of ``x[idx] = minimum(x[idx], y)``.

    Returns the value of ``x`` that would result from the NumPy-style
    :mod:indexed assignment <numpy.doc.indexing>`
    ``x[idx] = minimum(x[idx], y)``.

    See :mod:`jax.ops` for details.
    r  )r   r  r   r   r   scatter_minr  s        r%   rG   z_IndexUpdateRef.minM  9     "4:tz6#&?6H2@tM M M Mr'   c          	     `    t          j        | j        | j        |t          j        |||          S )zPure equivalent of ``x[idx] = maximum(x[idx], y)``.

    Returns the value of ``x`` that would result from the NumPy-style
    :mod:indexed assignment <numpy.doc.indexing>`
    ``x[idx] = maximum(x[idx], y)``.

    See :mod:`jax.ops` for details.
    r  )r   r  r   r   r   scatter_maxr  s        r%   rI   z_IndexUpdateRef.max\  r)  r'   )r   r   r   r   r   r   r   r
  r   r  r  r!  mulr#  r&  rG   rI   r   r'   r%   r   r     s         !)  > > > ',E< < < < <  /4EM M M M M /4EM M M M M. /4EM M M M M 49. . . . . 	#16uI I I I I  16eI I I I I  /4EM M M M M /4EM M M M M M Mr'   r   getitemsetitemdeepcopynegposeqz==nez!=lt<lez<=gt>gez>=absr  +raddT)r   sub-rsubr,  *rmuldiv/rdivtruedivrtruedivfloordivz//	rfloordivr   rdivmodmod%rmodpowz**rpowmatmul@rmatmuland&|^z<<z>>)randorrorxorrxorinvertlshiftrshiftrlshiftrrshiftr   rl   anyargmaxargminargpartitionargsortr$   chooserK   conj	conjugater   cumprodcumsumdiagonaldotflattenrA   meannonzerorn   ptpravelrepeatr}   r   searchsortedsortr   stdsum)	swapaxestake	to_devicetracerP   varr   _splitr   )r   r   )flatr   mTr   r   nbytesr5   r   c                   t                                           D ]&\  }}t          | d| t          |                     't                                          D ](\  }}t          | |t          j        |                     )t                                          D ](\  }}t          | |t          j        |                     )t          | dt          t                               d S )N__array_module)
_array_operatorsitemssetattrstaticmethod_array_methodsr   aval_method_array_propertiesaval_propertyr   )shaped_arrayoperator_namefunctionmethod_namemethod	prop_nameprops          r%   _set_shaped_array_attributesr    s    
 "2!7!7!9!9 G GmXL-m--|H/E/EFFFF+1133 A Ak6L+t'7'?'?@@@@*0022 ? ?oiL)T%7%=%=>>>>	,6F)G)GHHHHHr'   c                      fd}|S )Nc                B     t          | j        d           | g|R  S )Nr  )getattraval)r   rB   names     r%   opz%_forward_operator_to_aval.<locals>.op  s-    )749j$jj))$66666r'   r   )r  r  s   ` r%   _forward_operator_to_avalr    s!    7 7 7 7 7	)r'   c                      fd}|S )Nc                P    d} t          | j                  j        | g|R i |S )NT)r  r  fun)r   rB   r  r   r  s       r%   methz%_forward_method_to_aval.<locals>.meth  s8    '749d##'>t>>>v>>>r'   r   )r  r  s   ` r%   _forward_method_to_avalr    s#    ? ? ? ? ? 
+r'   c                ,     t            fd            }|S )Nc                T    t          | j                                      |           S r^   )r  r  fget)r   r  s    r%   r  z'_forward_property_to_aval.<locals>.prop  s#    49d##((...r'   )property)r  r  s   ` r%   _forward_property_to_avalr    s+    / / / / 8/	+r'   r   c                   t           D ](}||vr"t          | d| dt          |                     )t          D ]$}||vrt          | |t	          |                     %t
          D ]$}||vrt          | |t          |                     %d S N__)r  r  r  r  r  r  r  )tracerexcluder  r  r  s        r%   _set_tracer_aval_forwardingr    s    ' X XmG##f,=,,,.G.V.VWWW# I Ik'!!fk#:;#G#GHHH$ G Gifi!:9!E!EFFFG Gr'   c                     fd}t                                           D ]\  }} |d| d|           t                                          D ]\  }} |||           t                                          D ]\  }}	 ||t	          |	                     t
                                          D ]\  }
}t           |
|           d S )Nc                J    | v rd S r| v rt          | |           d S d S r^   )r  )	attr_nametargetdevice_arrayr  includes     r%   maybe_setattrz1_set_array_base_attributes.<locals>.maybe_setattr  sJ    yG33f /i7**lIv..... +*r'   r  )r  r  r  r  r  _impl_only_array_methodsr  )r  r  r  r  r  r  r  r  r  r  r  r  s   ```         r%   _set_array_base_attributesr    s   / / / / / / / "2!7!7!9!9 4 4mXM(}((((3333+1133 ' 'k6M+v&&&&*0022 - -oiM)Xd^^,,,,,2244 & &jdDL$%%%%& &r'   c                2    t          | dt                     d S )Nr   )r  r   )r  s    r%   _set_array_attributesr    s    	,*,<=====r'   c                `     t           j        t          |           fd                        }|S )Nc                 (    t          d           )NzCannot call abstract method r   )rB   r  r  s     r%   r  z%_make_abstract_method.<locals>.method  s     CTCC
D
DDr'   )abcabstractmethodr   )r  r  r  s   `  r%   _make_abstract_methodr    sD    ;;E E E E ; E	-r'   c                   t                                           D ],\  }}t          | d| dt          d| d|                     -t                                          D ]$\  }}t          | |t          ||                     %t
                                          D ]1\  }}t          | |t          t          ||                               2d S r  )r  r  r  r  r  r  r  )	basearrayr  r  r  r  r  r  s          r%   _set_array_abstract_methodsr  "  s
   !1!7!7!9!9 E EmXI-M---!"8}"8"8"8(CCE E E E+1133 8 8k6I{!+v668 8 8 8*0022 > >oiIy*9d;;<<> > > >> >r'   c                 0   t          t          j                   t          t          j                   t	          t
          dh           t          t          j        h t          d           t          t
                     t          t                     dS )z9Call this function once to register methods of JAX arraysr   )r  r   N)r  r   ShapedArrayDShapedArrayr  r   r  Tracerr  r  r  r   r   r'   r%   r   r   -  s|    t/000t0111Y@@@@dk3T5M3Tt3TUUUU	"""e$$$$$r'   )FN)
r   r   r   r   r   r   r    r!   r"   r   )r   r   r    r)   r(   r*   )r   r   r"   r/   )r8   r   r"   r9   )NN)rF   r   rG   rH   rI   rH   r"   r   )r8   r   rB   r   r"   r   )r8   r   rS   rT   r"   r   )r8   r   rB   r   rw   rx   r"   r   )r   r   r   r   rX   r   r"   r   )Fr^   )rF   r   r   r   r"   r   )r   r   r"   r   )r   r   r   r   r"   r   )r8   r   r   r   rQ   r   r   r   r4   r   r   r   r"   r   )
r   r   r   r   r   r   r   r   r"   r   )r   r   r"   r   )r   )r   
__future__r   __all__r  	functoolsr   r   rm   typingr   r   r3   r   r   jax.shardingr	   jax._srcr
   r   r   jax._src.api_utilr   jax._src.arrayr   jax._src.laxr  jax._src.libr   xcjax._src.numpyr   r   r   r   jax._src.opsr   jax._src.typingr   r   r   r   r   jax._src.utilr   r   map
unsafe_mapr   
unsafe_zipr&   r.   r7   rC   rE   rL   rR   ru   r   r   r   r/   floatcomplexgenericndarrayr   r~   rp   r   dictr   r   r   r   r   r   r  _JAX_ARRAY_TYPESr   r   r   stash_axis_envjitr   r   r   r   r   r   negativepositiveequal	not_equalless
less_equalgreatergreater_equalr:  r  subtractr!  r#  true_dividefloor_divider   rJ  r&  rO  bitwise_and
bitwise_orbitwise_xorbitwise_not
left_shiftright_shiftr  rl   r`  ra  rb  rc  rd  re  rf  rg  r   rh  ri  rj  rk  rp  rI   rm  rG   rn  rn   ro  rq  r   rr  rs  r   rt  ru  rv  rw  ry  rz  splitr  r  rP   matrix_transposer   r   r  r  r  r  r  r  r  r  r  r  r   r   r'   r%   <module>r     s}  " 
 # " " " " "'
( 



 $ $ $ $ $ $ $ $            



       ! ! ! ! ! !                   1 1 1 1 1 1 $ $ $ $ $ $ , , , , , , ) ) ) ) ) ) $ $ $ $ $ $ % % % % % % ! ! ! ! ! !                   G G G G G G G G G G G G G G , , , , , , , ,CZCZ@ @ @ @ @ +/% % % % % %F F F F
   7 7 7 7 AE2 2 2 2 2& & & &I I I IB 14 I I I I I I$V. V. V. V. V.r? ? ?
 eWbj"*eL uc40     * * *5 5 5 5 5
       K+ '2:-7    )->=A(,a> > > > > > )))   *) & M M M 	MA A A/ / /^1 ^1 ^1 ^1 ^1 ^1 ^1 ^1B^M ^M ^M ^M ^M ^M ^M ^M@.X.#. 	%. i	.
 . . ""466. ""4)9::. ""344. ""4):;;. ""377. ""4)=>>. . 	#	#C	4	4. 	
$
$S&*4
@
@
@.  	#	#C	9	9!." 	
$
$S&/
E
E
E#. .$ 	#	#C	9	9%.& 	
$
$S&/
E
E
E'.( 	#	#C	7	7).* 	
$
$S&-d
C
C
C+., ''V-?@@-.. ((f.@tLLL/.0 ((v/BCC1.2 ))$0C$OOO3.4 &&x??5.6 ''&-dKKK7.8 	#	#C	4	49.: 	
$
$S&*4
@
@
@;.< 	#	#D&,	7	7=.> 	
$
$T6<d
C
C
C?.@ &&sI,<==A.B ''Y-=DIIIC.D 	#	#C);	<	<E. .F %
$S&*<4
H
H
H""3(9::	#	#C):	F	F	F	#	#C);	<	<
$
$S&*<4
H
H
H&&tV->??&&tV-?@@''f.?dKKK''f.@tLLL[. . . `... I. I	.
 )(. Y. G. I. 	%. 	&+. v. . 	).. Z. J.  i !." #. .$ Y_%.& 	%'.( ).* 	*/+., -.. Y/.0 	*/1.2 3.4 
9?5.6 I7.8 X9.: 
9?;.< )(=.> 	).?.@ YA.B C.D E. .F  
.?	
 O[. . .b    "
+
+	 	 I I I  
    	G 	G 	G 	G& & & &&> > >  	> 	> 	>	% 	% 	% 	% 	%r'   