
    VpfO                   h   d dl mZ d dlZd dlmZmZ d dlmZ d dlZd dl	Z	d dl
mZmZmZmZmZ d dl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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* d dl+m,Z-m.Z.m/Z/ ej0        Z1e$j2        Z3ee4ee4         df         Z5ddZ6ddZ7ddZ8ddZ9eeegef         Z:dddd dddd dddd d!dd:Z;d; Z<dd<Z=dd>Z>dd@Z?ddAZ@ddCZA eejB        dDdE          	 	 	 	 dddG            ZC	 	 	 dddHZD eejB        dDdE          	 	 	 	 dddI            ZE	 	 	 	 dddJZF eejB        dKdE          	 	 	 dddL            ZG	 	 	 dddMZH eejB        dKdE          	 	 	 dddN            ZI	 	 	 dddOZJ eejB        dKdE          	 	 dddPddQ            ZK	 	 dddPddRZ0 eejB        dKdE          	 	 dddPddS            ZL	 	 dddPddTZM	 	 	 dddUZN	 	 	 dddVZOddXZP	 	 dddPddYZQ eejB        dZdE          	 	 dddd[dd\            ZRe	 	 ddd`            ZSedd daddc            ZSe	 	 ddde            ZS e"ejS                  	 	 dddf            ZS eejB        dgdE          	 	 dddh            ZT	 	 ddddiddmZU eejB        dZn          	 	 dddPddp            ZVddsZW	 	 ddddiddtZX eejB        dZn          	 	 dddPddu            ZY	 	 dddvZZ eejB        dKn          	 	 dddw            Z[ eejB        dKn          	 	 dddx            Z\	 ddd|Z] eejB        dKn          	 	 	 ddd}            Z^ eejB        dKn          	 	 	 ddd~            Z_ eejB        dZn          	 	 	 ddd            Z` eejB        dZn          	 	 	 ddd            Za eejB        dZn          	 	 ddd            Zb eejB        dZn          	 	 	 ddd            Zc eejB        dZn          	 	 	 ddd            Zd G d de          ZedZf	 	 dddZg egejh        ejh        d           Zh egeji        eji        d           Zi egejj        ejh        dd           Zj egejk        eji        dd          Zk egejh        ejh        d d          Zl e" emedd                    ddd ddd            Zn e"ejo        d1dg           eejB        dn          	 	 	 d e*            ddd                        Zo e"ejp        d1dg           eejB        dn          	 	 	 d e*            ddd                        ZpddZq e"ejr        d1dg           eejB        dn          	 	 	 d e*            ddd                        Zr e"ejs        d1dg           eejB        dn          	 	 	 d e*            ddd                        Zs eejB        dn          	 	 	 ddd            Zt eejB        dn          	 	 	 ddd            ZudS )    )annotationsN)CallableSequence)partial)overloadAnyLiteralProtocolUnion)lax)api)core)dtypes)ufuncs)_broadcast_tocheck_arraylike_complex_elem_typepromote_dtypes_inexactpromote_dtypes_numeric_where
implements)Array	ArrayLikeDType	DTypeLikeDeprecatedArg)canonicalize_axismaybe_named_axisNumpyComplexWarningelementr   returnboolc                    t          | d          r|                                 } t          j        |           pt	          j        |           S )N__jax_array__)hasattrr$   r   is_python_scalarnpisscalar)r    s    Y/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/numpy/reductions.py	_isscalarr*   1   sE    Wo&& &##%%G		 	)	)	AR[-A-AA    ar   sourceintdestinationr   c                   t          d|            t          j        |           } t          t	          j        |                     t          |t	          j        |                     }fdt          t	          j        |                     D             }|                    |           t          j	        | |          S )Nmoveaxisc                     g | ]
}|k    |S  r3   ).0ir-   s     r)   
<listcomp>z_moveaxis.<locals>.<listcomp><   s    	6	6	6!v++!+++r+   )
r   lax_internalasarray_canonicalize_axisr'   ndimrangeinsertr   	transpose)r,   r-   r/   perms    `  r)   	_moveaxisr?   6   s    *a   1!fbgajj11&";

;;+	6	6	6	6U271::&&	6	6	6$++k6"""	q$		r+   dtyper   r   c                    t          j        |           t           j        t          j        fv rt          j        d          S t          j        |           S )Nfloat32)r'   r@   float16r   bfloat16r@   s    r)   _upcast_f16rF   @   s<    Xe__V_5558I	%r+   c                   t          j        | t          j                  rt           j        S t          j        | t          j                  rKt          j        |           j        t          j        t           j                  j        k     rt           j        S nit          j        | t          j	                  rJt          j        |           j        t          j        t           j                  j        k     rt           j        S | S N)
r   
issubdtyper'   bool_int_unsignedintegeriinfobitsuintintegerrE   s    r)   _promote_integer_dtyperQ   E   s     ubh'' ; 233 	xbhv{33888[ 9
++ 	xbhv{33888[	,r+   TF)has_identitypreprocbool_opupcast_f16_for_computationaxisr@   outkeepdimsinitialwhere_parallel_reducepromote_integersnamestrnp_funopReductionOpinit_valrR   rS   'Callable[[ArrayLike], ArrayLike] | NonerT   ReductionOp | NonerU   rV   AxisDTypeLike | NonerW   NonerX   rY   ArrayLike | NonerZ   r[   Callable[..., Array] | Noner\   c                  |p|}|t          d| d          t          ||            t          j        |
|           t	          j        d |	d| d          }	||s|t          d| d          t          | t                    r| nt          j
        |           } |r ||           n| } t          | |	          \  }}|D|sBt          j        |           t          fd|D                       st          d| d	          |
pt          j        |           }|
|rt!          |          }t          j        |          }|r/t          j        |t          j                  rt)          |          }n|}t+          j        | |          } |t          j        k    r|n|}t1          | |          }|t3          || |          } ||ur"|t          d
| d           || |          }nt+          j        | |||          }|Zt+          j        |t          j
        |           j                  }|j        dk    rt          d|j                    |||          }|rt+          j        ||          }t+          j        ||
p|          S )NThe 'out' argument to jnp. is not supported.zaxis argument to jnp.z().zreduction operation zO does not have an identity, so to use a where mask one has to specify 'initial'c              3  0   K   | ]}|         d k    V  dS )   Nr3   )r4   dshapes     r)   	<genexpr>z_reduction.<locals>.<genexpr>s   s+      00!aA000000r+   z'zero-size array to reduction operation z which has no identityz)Named reductions not implemented for jnp.z()r3   z3initial value must be a scalar. Got array of shape )NotImplementedErrorr   r   check_user_dtype_supportedr   concrete_or_error
ValueError
isinstancer   r7   r8   _reduction_dimsr'   rp   _allr@   rQ   canonicalize_dtyperI   inexactrF   r   convert_element_typerJ   _reduction_init_valr   reduceexpand_dims)r,   r]   r_   r`   rb   rR   rS   rT   rU   rV   r@   rW   rX   rY   rZ   r[   r\   pos_dimsdimsresult_dtypecomputation_dtyperesultinitial_arrrp   s                          @r)   
_reductionr   U   s    Mr' 	_
S4SSS
T
TT$#E4000		d,MD,M,M,M	N	N$_\_f.@
 @D @ @ @ A A A a<aa\%9!%<%<!"ggajjj!"1d++.(D_\_HQKKE0000x00000 _]]]]^^^)&,q//,
]']),77L*<88, %F$5lBJ$O$O %#L11$	q"344!"(**rr" !H--(vq(##AT TD T T TUUU_Q%%FFZ8R..F*7L4H4K4K4QRRKB A-8->A A B B BRV$$F /_VX..F		!&%*?<	@	@@r+   c                .    t          | fdd           S )Nc                $    t          |           S rH   r9   )r5   ranks    r)   <lambda>z0_canonicalize_axis_allow_named.<locals>.<lambda>   s    '9!T'B'B r+   c                    | S rH   r3   r]   s    r)   r   z0_canonicalize_axis_allow_named.<locals>.<lambda>   s    QU r+   )r   )xr   s    `r)   _canonicalize_axis_allow_namedr      s#    	!BBBBDUDU	V	VVr+   c                    |2t          t          t          j                                       fdz  S t	          |t          j        t           t          f          s|f}t           fd|D                       }t          |          t          t          |                    k    rt          d|           t          d |D                       }t          |          t          |          k    r||fS ||fS )N   c              3  \   K   | ]&}t          |t          j                            V  'd S rH   )r   r'   r:   )r4   r   r,   s     r)   rq   z"_reduction_dims.<locals>.<genexpr>   sI       $ $ 4ArwqzzBB $ $ $ $ $ $r+   zduplicate value in 'axis': c              3  D   K   | ]}t          |t                    |V  d S rH   )rv   r.   )r4   r   s     r)   rq   z"_reduction_dims.<locals>.<genexpr>   s1      EEq*Q2D2DEEEEEEEr+   )
tupler;   r'   r:   rv   ndarraylistlensetru   )r,   rV   
canon_axiscanon_pos_axiss   `   r)   rw   rw      s   	\%

##$$&**dRZ566 7D $ $ $ $"$ $ $ $ $*__C
OO,,,,
9499
:
::EEJEEEEE.C
OO++:%%z!!r+   
np.ndarrayc                    t          j        t          j        |                     }|dk    rt          j        |dk    |          S t          j        |          rt          j        |t          j                  rnt          j        |          sZt          j        t          j	        |          rt          j
        |          j        nt          j
        |          j        |          }	 t          j        ||          S # t          $ rt t          j        |t          j                  sJ t          j        |          t          j        |          }}t          j        |dk     r|j        n|j        |          cY S w xY w)Nr"   r   rE   )r   ry   r@   r'   arrayisinfrI   floatingsupports_infisneginffinfominmaxOverflowErrorrP   signrM   )r,   rb   a_dtyper   infos        r)   r|   r|      si    %fl1oo66'8HqL0000hx GV.wDD G!'**GxR[5J5J 7W--11#\'226gG G GHG8HG,,,,	 G G GWbj11111""FL$9$9$D8qDHHdhgFFFFFFGs   )C? ?A;E=<E=operandc                    t          j                    5  t          j        dt                     t	          j        | t          j                  cd d d            S # 1 swxY w Y   d S )Nignore)category)warningscatch_warningsfilterwarningsr   r   r{   r'   rJ   r   s    r)   _cast_to_boolr      s       7 7H/BCCCC#GRX667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s   :AA"Ac                ,    t          |           d         S )Nr   )r   r   s    r)   _cast_to_numericr      s    		(	(	++r+   r   c                4    d }t          j        || d          S )Nc                    | d S 	 t          j        |           S # t          $ r t          d | D                       cY S w xY w)Nc              3  l   K   | ]/}t          |t                    r|nt          j        |          V  0d S rH   )rv   r^   operatorindex)r4   r5   s     r)   rq   z7_ensure_optional_axes.<locals>.force.<locals>.<genexpr>   s?      MMa
1c**A11q0A0AMMMMMMr+   )r   r   	TypeErrorr   )r   s    r)   forcez$_ensure_optional_axes.<locals>.force   sd    yTN^A N N NMM1MMMMMMMMNs    #A A z+The axis argument must be known statically.)r   rt   )r   r   s     r)   _ensure_optional_axesr      s3    N N N 
		1;
= 
= =r+   )rV   r@   rX   r\   )static_argnamesinlinewherec                    t          | dt          j        t          j        dt
          t          j        d||||||t          j        |          S )Nsumr   T)rS   rT   rU   rV   r@   rW   rX   rY   rZ   r[   r\   )r   r'   r   r   addr   
bitwise_orpsumr,   rV   r@   rW   rX   rY   r   r\   s           r)   _reduce_sumr      sH    
 
Aubfcgq:JNtUh#E38%5	
7 
7 
7 7r+   c           
     J    t          | t          |          ||||||          S )a	  Sum of the elements of the array over a given axis.

  JAX implementation of :func:`numpy.sum`.

  Args:
    a: Input array.
    axis: int or array, default=None. Axis along which the sum to be computed.
      If None, the sum is computed along all the axes.
    dtype: The type of the output array. Default=None.
    out: Unused by JAX
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    initial: int or array, Default=None. Initial value for the sum.
    where: int or array, default=None. The elements to be used in the sum. Array
      should be broadcast compatible to the input.
    promote_integers : bool, default=True. If True, then integer inputs will be
      promoted to the widest available integer dtype, following numpy's behavior.
      If False, the result will have the same dtype as the input.
      ``promote_integers`` is ignored if ``dtype`` is specified.

  Returns:
    An array of the sum along the given axis.

  See also:
    - :func:`jax.numpy.prod`: Compute the product of array elements over a given
      axis.
    - :func:`jax.numpy.max`: Compute the maximum of array elements over given axis.
    - :func:`jax.numpy.min`: Compute the minimum of array elements over given axis.

  Examples:

    By default, the sum is computed along all the axes.

    >>> x = jnp.array([[1, 3, 4, 2],
    ...                [5, 2, 6, 3],
    ...                [8, 1, 3, 9]])
    >>> jnp.sum(x)
    Array(47, dtype=int32)

    If ``axis=1``, the sum is computed along axis 1.

    >>> jnp.sum(x, axis=1)
    Array([10, 16, 21], dtype=int32)

    If ``keepdims=True``, ``ndim`` of the output is equal to that of the input.

    >>> jnp.sum(x, axis=1, keepdims=True)
    Array([[10],
           [16],
           [21]], dtype=int32)

    To include only specific elements in the sum, you can use ``where``.

    >>> where=jnp.array([[0, 0, 1, 0],
    ...                  [0, 0, 1, 1],
    ...                  [1, 1, 1, 0]], dtype=bool)
    >>> jnp.sum(x, axis=1, keepdims=True, where=where)
    Array([[ 4],
           [ 9],
           [12]], dtype=int32)
    >>> where=jnp.array([[False],
    ...                  [False],
    ...                  [False]])
    >>> jnp.sum(x, axis=0, keepdims=True, where=where)
    Array([[0, 0, 0, 0]], dtype=int32)
  rV   r@   rW   rX   rY   r   r\   )r   r   r   s           r)   r   r      s7    J 
Q24883&u&6
8 
8 
8 8r+   c                    t          | dt          j        t          j        dt
          t          j        d|||||||          S )Nprodrn   T)
rS   rT   rU   rV   r@   rW   rX   rY   rZ   r\   )r   r'   r   r   mulr   bitwise_andr   s           r)   _reduce_prodr   &  sH    
 
Avrw<LOUh#EDT
V 
V 
V Vr+   c           
     J    t          | t          |          ||||||          S )aD	  Return product of the array elements over a given axis.

  JAX implementation of :func:`numpy.prod`.

  Args:
    a: Input array.
    axis: int or array, default=None. Axis along which the product to be computed.
      If None, the product is computed along all the axes.
    dtype: The type of the output array. Default=None.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    initial: int or array, Default=None. Initial value for the product.
    where: int or array, default=None. The elements to be used in the product.
      Array should be broadcast compatible to the input.
    promote_integers : bool, default=True. If True, then integer inputs will be
      promoted to the widest available integer dtype, following numpy's behavior.
      If False, the result will have the same dtype as the input.
      ``promote_integers`` is ignored if ``dtype`` is specified.
    out: Unused by JAX.

  Returns:
    An array of the product along the given axis.

  See also:
    - :func:`jax.numpy.sum`: Compute the sum of array elements over a given axis.
    - :func:`jax.numpy.max`: Compute the maximum of array elements over given axis.
    - :func:`jax.numpy.min`: Compute the minimum of array elements over given axis.

  Examples:
    By default, ``jnp.prod`` computes along all the axes.

    >>> x = jnp.array([[1, 3, 4, 2],
    ...                [5, 2, 1, 3],
    ...                [2, 1, 3, 1]])
    >>> jnp.prod(x)
    Array(4320, dtype=int32)

    If ``axis=1``, product is computed along axis 1.

    >>> jnp.prod(x, axis=1)
    Array([24, 30,  6], dtype=int32)

    If ``keepdims=True``, ``ndim`` of the output is equal to that of the input.

    >>> jnp.prod(x, axis=1, keepdims=True)
    Array([[24],
           [30],
           [ 6]], dtype=int32)

    To include only specific elements in the sum, you can use a``where``.

    >>> where=jnp.array([[1, 0, 1, 0],
    ...                  [0, 0, 1, 1],
    ...                  [1, 1, 1, 0]], dtype=bool)
    >>> jnp.prod(x, axis=1, keepdims=True, where=where)
    Array([[4],
           [3],
           [6]], dtype=int32)
    >>> where = jnp.array([[False],
    ...                    [False],
    ...                    [False]])
    >>> jnp.prod(x, axis=1, keepdims=True, where=where)
    Array([[1],
           [1],
           [1]], dtype=int32)
  r   )r   r   r   s           r)   r   r   1  s7    L 
a3D99''7
9 
9 
9 9r+   rV   rX   c                    t          | dt          j        t          j        t          j         d|||||t          j                  S )Nr   FrR   rV   rW   rX   rY   rZ   r[   )r   r'   r   r   infpmaxr,   rV   rW   rX   rY   r   s         r)   _reduce_maxr   |  sC     
AubfcgwU3#E38
M 
M 
M Mr+   c                F    t          | t          |          ||||          S )a  Return the maximum of the array elements along a given axis.

  JAX implementation of :func:`numpy.max`.

  Args:
    a: Input array.
    axis: int or array, default=None. Axis along which the maximum to be computed.
      If None, the maximum is computed along all the axes.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    initial: int or array, default=None. Initial value for the maximum.
    where: int or array of boolean dtype, default=None. The elements to be used
      in the maximum. Array should be broadcast compatible to the input.
      ``initial`` must be specified when ``where`` is used.
    out: Unused by JAX.

  Returns:
    An array of maximum values along the given axis.

  See also:
    - :func:`jax.numpy.min`: Compute the minimum of array elements along a given
      axis.
    - :func:`jax.numpy.sum`: Compute the sum of array elements along a given axis.
    - :func:`jax.numpy.prod`: Compute the product of array elements along a given
      axis.

  Examples:

    By default, ``jnp.max`` computes the maximum of elements along all the axes.

    >>> x = jnp.array([[9, 3, 4, 5],
    ...                [5, 2, 7, 4],
    ...                [8, 1, 3, 6]])
    >>> jnp.max(x)
    Array(9, dtype=int32)

    If ``axis=1``, the maximum will be computed along axis 1.

    >>> jnp.max(x, axis=1)
    Array([9, 7, 8], dtype=int32)

    If ``keepdims=True``, ``ndim`` of the output will be same of that of the input.

    >>> jnp.max(x, axis=1, keepdims=True)
    Array([[9],
           [7],
           [8]], dtype=int32)

    To include only specific elements in computing the maximum, you can use
    ``where``. It can either have same dimension as input

    >>> where=jnp.array([[0, 0, 1, 0],
    ...                  [0, 0, 1, 1],
    ...                  [1, 1, 1, 0]], dtype=bool)
    >>> jnp.max(x, axis=1, keepdims=True, initial=0, where=where)
    Array([[4],
           [7],
           [8]], dtype=int32)

    or must be broadcast compatible with input.

    >>> where = jnp.array([[False],
    ...                    [False],
    ...                    [False]])
    >>> jnp.max(x, axis=0, keepdims=True, initial=0, where=where)
    Array([[0, 0, 0, 0]], dtype=int32)
  rV   rW   rX   rY   r   )r   r   r   s         r)   r   r     s6    L 
Q2488c&u
F 
F 
F Fr+   c                    t          | dt          j        t          j        t          j        d|||||t          j                  S )Nr   Fr   )r   r'   r   r   r   pminr   s         r)   _reduce_minr     sA     
AubfcgrvE3#E38
M 
M 
M Mr+   c                F    t          | t          |          ||||          S )a  Return the minimum of array elements along a given axis.

  JAX implementation of :func:`numpy.min`.

  Args:
    a: Input array.
    axis: int or array, default=None. Axis along which the minimum to be computed.
      If None, the minimum is computed along all the axes.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    initial: int or array, Default=None. Initial value for the minimum.
    where: int or array, default=None. The elements to be used in the minimum.
      Array should be broadcast compatible to the input. ``initial`` must be
      specified when ``where`` is used.
    out: Unused by JAX.

  Returns:
    An array of minimum values along the given axis.

  See also:
    - :func:`jax.numpy.max`: Compute the maximum of array elements along a given
      axis.
    - :func:`jax.numpy.sum`: Compute the sum of array elements along a given axis.
    - :func:`jax.numpy.prod`: Compute the product of array elements along a given
      axis.

  Examples:
    By default, the minimum is computed along all the axes.

    >>> x = jnp.array([[2, 5, 1, 6],
    ...                [3, -7, -2, 4],
    ...                [8, -4, 1, -3]])
    >>> jnp.min(x)
    Array(-7, dtype=int32)

    If ``axis=1``, the minimum is computed along axis 1.

    >>> jnp.min(x, axis=1)
    Array([ 1, -7, -4], dtype=int32)

    If ``keepdims=True``, ``ndim`` of the output will be same of that of the input.

    >>> jnp.min(x, axis=1, keepdims=True)
    Array([[ 1],
           [-7],
           [-4]], dtype=int32)

    To include only specific elements in computing the minimum, you can use
    ``where``. ``where`` can either have same dimension as input.

    >>> where=jnp.array([[1, 0, 1, 0],
    ...                  [0, 0, 1, 1],
    ...                  [1, 1, 1, 0]], dtype=bool)
    >>> jnp.min(x, axis=1, keepdims=True, initial=0, where=where)
    Array([[ 0],
           [-2],
           [-4]], dtype=int32)

    or must be broadcast compatible with input.

    >>> where = jnp.array([[False],
    ...                    [False],
    ...                    [False]])
    >>> jnp.min(x, axis=0, keepdims=True, initial=0, where=where)
    Array([[0, 0, 0, 0]], dtype=int32)
  r   )r   r   r   s         r)   r   r     s6    J 
Q2488c&u
F 
F 
F Fr+   r   c               f    t          | dt          j        t          j        dt
          ||||
  
        S )NallTrS   rV   rW   rX   rZ   )r   r'   r   r   r   r   r,   rV   rW   rX   r   s        r)   _reduce_allr     s8     
Aubfcot]3%
I 
I 
I Ir+   c               D    t          | t          |          |||          S )a  Test whether all array elements along a given axis evaluate to True.

  JAX implementation of :func:`numpy.all`.

  Args:
    a: Input array.
    axis: int or array, default=None. Axis along which to be tested. If None,
      tests along all the axes.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    where: int or array of boolean dtype, default=None. The elements to be used
      in the test. Array should be broadcast compatible to the input.
    out: Unused by JAX.

  Returns:
    An array of boolean values.

  Examples:
    By default, ``jnp.all`` tests for True values along all the axes.

    >>> x = jnp.array([[True, True, True, False],
    ...                [True, False, True, False],
    ...                [True, True, False, False]])
    >>> jnp.all(x)
    Array(False, dtype=bool)

    If ``axis=0``, tests for True values along axis 0.

    >>> jnp.all(x, axis=0)
    Array([ True, False, False, False], dtype=bool)

    If ``keepdims=True``, ``ndim`` of the output will be same of that of the input.

    >>> jnp.all(x, axis=0, keepdims=True)
    Array([[ True, False, False, False]], dtype=bool)

    To include specific elements in testing for True values, you can use a``where``.

    >>> where=jnp.array([[1, 0, 1, 0],
    ...                  [0, 0, 1, 1],
    ...                  [1, 1, 1, 0]], dtype=bool)
    >>> jnp.all(x, axis=0, keepdims=True, where=where)
    Array([[ True,  True, False, False]], dtype=bool)
  rV   rW   rX   r   )r   r   r   s        r)   r   r   &  0    \ 
Q2488c&e
5 
5 
5 5r+   c               f    t          | dt          j        t          j        dt
          ||||
  
        S )NanyFr   )r   r'   r   r   r   r   r   s        r)   _reduce_anyr   W  s8     
Aubfcne]3%
I 
I 
I Ir+   c               D    t          | t          |          |||          S )a  Test whether any of the array elements along a given axis evaluate to True.

  JAX implementation of :func:`numpy.any`.

  Args:
    a: Input array.
    axis: int or array, default=None. Axis along which to be tested. If None,
      tests along all the axes.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    where: int or array of boolean dtype, default=None. The elements to be used
      in the test. Array should be broadcast compatible to the input.
    out: Unused by JAX.

  Returns:
    An array of boolean values.

  Examples:
    By default, ``jnp.any`` tests along all the axes.

    >>> x = jnp.array([[True, True, True, False],
    ...                [True, False, True, False],
    ...                [True, True, False, False]])
    >>> jnp.any(x)
    Array(True, dtype=bool)

    If ``axis=0``, tests along axis 0.

    >>> jnp.any(x, axis=0)
    Array([ True,  True,  True, False], dtype=bool)

    If ``keepdims=True``, ``ndim`` of the output will be same of that of the input.

    >>> jnp.any(x, axis=0, keepdims=True)
    Array([[ True,  True,  True, False]], dtype=bool)

    To include specific elements in testing for True values, you can use a``where``.

    >>> where=jnp.array([[1, 0, 1, 0],
    ...                  [0, 1, 0, 1],
    ...                  [1, 0, 1, 0]], dtype=bool)
    >>> jnp.any(x, axis=0, keepdims=True, where=where)
    Array([[ True, False,  True, False]], dtype=bool)
  r   )r   r   r   s        r)   r   r   ^  r   r+   c                ,    t          | |||||          S )zAlias of :func:`jax.numpy.min`.r   )r   r   s         r)   aminr     (     
QTsXE
+ 
+ 
+ +r+   c                ,    t          | |||||          S )zAlias of :func:`jax.numpy.max`.r   )r   r   s         r)   amaxr     r   r+   int | Sequence[int]c                    t          |t          t          f          s|f}n|}d}t          j        |           |D ]} |t          | fdd           z  }|S )Nrn   c                    |          S rH   r3   )r5   a_shapes    r)   r   z_axis_size.<locals>.<lambda>  s    '!* r+   c                ,    t          j        d|           S )Nrn   )r   r   r   s    r)   r   z_axis_size.<locals>.<lambda>  s    38AtCTCT r+   )rv   r   r   r'   rp   r   )r,   rV   axis_seqsizer   s       @r)   
_axis_sizer     sv    	D5$-	(	( #gHHH	
$HQKK' V VaQ 4 4 4 46T6TUUUDD	+r+   c               F    t          | t          |          ||||          S )a2  Return the mean of array elements along a given axis.

  JAX implementation of :func:`numpy.mean`.

  Args:
    a: input array.
    axis: optional, int or sequence of ints, default=None. Axis along which the
      mean to be computed. If None, mean is computed along all the axes.
    dtype: The type of the output array. Default=None.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    where: optional, boolean array, default=None. The elements to be used in the
      mean. Array should be broadcast compatible to the input.
    out: Unused by JAX.

  Returns:
    An array of the mean along the given axis.

  See also:
    - :func:`jax.numpy.sum`: Compute the sum of array elements over a given axis.
    - :func:`jax.numpy.max`: Compute the maximum of array elements over given axis.
    - :func:`jax.numpy.min`: Compute the minimum of array elements over given axis.

  Examples:
    By default, the mean is computed along all the axes.

    >>> x = jnp.array([[1, 3, 4, 2],
    ...                [5, 2, 6, 3],
    ...                [8, 1, 2, 9]])
    >>> jnp.mean(x)
    Array(3.8333335, dtype=float32)

    If ``axis=1``, the mean is computed along axis 1.

    >>> jnp.mean(x, axis=1)
    Array([2.5, 4. , 5. ], dtype=float32)

    If ``keepdims=True``, ``ndim`` of the output is equal to that of the input.

    >>> jnp.mean(x, axis=1, keepdims=True)
    Array([[2.5],
           [4. ],
           [5. ]], dtype=float32)

    To use only specific elements of ``x`` to compute the mean, you can use
    ``where``.

    >>> where = jnp.array([[1, 0, 1, 0],
    ...                    [0, 1, 0, 1],
    ...                    [1, 1, 0, 1]], dtype=bool)
    >>> jnp.mean(x, axis=1, keepdims=True, where=where)
    Array([[2.5],
           [2.5],
           [6. ]], dtype=float32)
  r   )_meanr   )r,   rV   r@   rW   rX   r   s         r)   meanr     s2    t 
q'--uc8
 
 
 r+   rV   r@   rX   )rU   r   c          	        t          d|            |t          d          |)t          j        t          j        | d                    }n)t          j        |d           t          j        |          }|r/t          j        |t          j	                  rt          |          }n|}|L|'t          j        t          j        |                     }	nVt          j        t          | |                    }	n3t          t!          |t          j        |                     |||          }	t%          j        t          | ||||          t%          j        |	|                                        |          S )Nr   z0The 'out' argument to jnp.mean is not supported.Tcanonicalizer@   rX   r@   rX   r   )r   rr   r   to_inexact_dtyper@   rs   ry   rI   r'   rz   rF   r   dimension_as_valuer   r   r   r   rp   r   divr{   astype)
r,   rV   r@   rW   rX   rU   r   r   r   
normalizers
             r)   r   r     sZ   
 &!_
P
Q
QQ
]*6<+M+M+MNNLL
%eV444,U33L %F$5lBJ$O$O %#L11$
]|*271::66jj*:a+>+>??jj]5"(1++66ET\]]]J		!T*XUKKK	z+<==
 
 F<r+   weightsreturnedLiteral[False]c                    d S rH   r3   r,   rV   r  r  rX   s        r)   averager    s    PSPSr+   )rX   Literal[True]c                   d S rH   r3   r  s        r)   r  r  
  s    GJsr+   Array | tuple[Array, Array]c                    d S rH   r3   r  s        r)   r  r    s    \_\_r+   c                B    t          | t          |          |||          S rH   )_averager   r  s        r)   r  r    s#     
!*400'8X	N	NNr+   )rV   r  rX   c                4   	 |t          d            t                     \   t           ||          }|5t          j        dt          j         j                  |j                  }nt          |t                    r5t          j        |t          j         fd|D                                 }nt          j        |t          j         j        |                             }nt          d |           t           |          \   }t          j                   }t!          |          	t          j        |          }|nAt          |t                    rt          	fd|D                       }nt#          |	          }||k    rt!          |          dk    rt%          d          |t%          d	          t          |t                    rt%          d
          t          j        |d         ||                   st%          d          t)          |	dz
  dz  |z             }t+          |d|          }t-          |||          }t-           |z  ||          |z  }|r)|j        |j        k    rt)          ||j                  }||fS |S )Nr  r   r3   rE   c              3  V   K   | ]#}t          j        j        |                   V  $d S rH   )r   r   rp   )r4   ro   r,   s     r)   rq   z_average.<locals>.<genexpr>  s6      0c0cYZ1HQR1T1T0c0c0c0c0c0cr+   c              3  8   K   | ]}t          |          V  d S rH   r   )r4   ro   a_ndims     r)   rq   z_average.<locals>.<genexpr>-  s.      ??Q%a00??????r+   rn   z81D weights expected when shapes of a and weights differ.z;Axis must be specified when shapes of a and weights differ.z8Single axis expected when shapes of a and weights differr   z5Length of weights not compatible with specified axis.)rn   )r   r   r   r   fullr   r   r   r@   rv   r   	full_likemathr   rp   r'   r   r9   ru   definitely_equalr   r?   r   )
r,   rV   r  r  rX   avgweights_sumr   weights_shaper  s
   `        @r)   r  r    s    _Iq!!!		"	"BA
qth
/
/
/C|HR!8!@!@	RRRkk	D%	 	  OM#ty0c0c0c0c^b0c0c0c'c'cddkkM#t'>qwt}'M'MNNkkIq'***'733JAwhqkkG\\FHW%%M|
	D%	 	  .????$?????ddf--d-	]		q	 	  + , , 	,	 + , , 	,dE"" <STTT$]1%5wt}EE < ; < < 	< g
d':]'JKKg'2t,,ggD8<<<K
a'kx
8
8
8;
FC 
yK%%%!+sy99k	*r+   )r   
correctionddofr  int | float | Nonec          	         ||}n*t          |t                    r|dk    rt          d          t          | t	          |          |||||          S )a
  Compute the variance along a given axis.

  JAX implementation of :func:`numpy.var`.

  Args:
    a: input array.
    axis: optional, int or sequence of ints, default=None. Axis along which the
      variance is computed. If None, variance is computed along all the axes.
    dtype: The type of the output array. Default=None.
    ddof: int, default=0. Degrees of freedom. The divisor in the variance computation
      is ``N-ddof``, ``N`` is number of elements along given axis.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    where: optional, boolean array, default=None. The elements to be used in the
      variance. Array should be broadcast compatible to the input.
    correction: int or float, default=None. Alternative name for ``ddof``.
      Both ddof and correction can't be provided simultaneously.
    out: Unused by JAX.

  Returns:
    An array of the variance along the given axis.

  See also:
    - :func:`jax.numpy.mean`: Compute the mean of array elements over a given axis.
    - :func:`jax.numpy.std`: Compute the standard deviation of array elements over
      given axis.
    - :func:`jax.numpy.nanvar`: Compute the variance along a given axis, ignoring
      NaNs values.
    - :func:`jax.numpy.nanstd`: Computed the standard deviation of a given axis,
      ignoring NaN values.

  Examples:
    By default, ``jnp.var`` computes the variance along all axes.

    >>> x = jnp.array([[1, 3, 4, 2],
    ...                [5, 2, 6, 3],
    ...                [8, 4, 2, 9]])
    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.var(x)
    Array(5.74, dtype=float32)

    If ``axis=1``, variance is computed along axis 1.

    >>> jnp.var(x, axis=1)
    Array([1.25  , 2.5   , 8.1875], dtype=float32)

    To preserve the dimensions of input, you can set ``keepdims=True``.

    >>> jnp.var(x, axis=1, keepdims=True)
    Array([[1.25  ],
           [2.5   ],
           [8.1875]], dtype=float32)

    If ``ddof=1``:

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.var(x, axis=1, keepdims=True, ddof=1))
    [[ 1.67]
     [ 3.33]
     [10.92]]

    To include specific elements of the array to compute variance, you can use
    ``where``.

    >>> where = jnp.array([[1, 0, 1, 0],
    ...                    [0, 1, 1, 0],
    ...                    [1, 1, 1, 0]], dtype=bool)
    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.var(x, axis=1, keepdims=True, where=where))
    [[2.25]
     [4.  ]
     [6.22]]
  Nr   5ddof and correction can't be provided simultaneously.r   )rv   r.   ru   _varr   r,   rV   r@   rW   r  rX   r   r  s           r)   varr!  L  sk    X JJdC   NDAII
L
M
MM	a&t,,eS*h
 
 
 r+   r   int | floatc                  t          d|            t          j        |d           |t          d          t	          t          j        |           |          \  }}t          j        |                               |          } t          | ||d|          }t          j        | |          }	t          j        |t          j                  rAt          j        t          j        |	t          j        |	                              }	|	j        }nt          j        |	          }	|a|'t'          j        t          j        |                     }
n"t'          j        t-          | |                    }
t          j        |
|          }
n3t1          t3          |t          j        |                     |||          }
t          j        |
t          j        ||                    }
t1          |	||||          }t          j        ||
                              |          }t9          j        d          5  t=          |
dk    |t          j                  }d d d            n# 1 swxY w Y   |S )Nr!  z/The 'out' argument to jnp.var is not supported.Tr   r   Fr   ) r   r   rs   rr   _var_promote_typesr@   r7   r8   r   r   r   subrI   r'   complexfloatingrealr   conjsquarer   r   r   r   r{   r   r   rp   r   jax
debug_nansr   nan)r,   rV   r@   rW   r  rX   r   r   a_meancenteredr  r   s               r)   r  r    sW    %#E5111_
O
P
PP/QGGU1$$%677!404uMMM&WQ(("*<== $x#(8*<*<==>>H z(##H
]|*271::66jj*:a+>+>??j)*6GHHJJ]5"(1++66,xA A AJwz3#;JHY#Z#Z[[*x%6QVWWW&76:&&--e44&
~e 4 4JNFBF33F4 4 4 4 4 4 4 4 4 4 4 4 4 4 4	-s   . II!Ir   tuple[DType, DType]c                ~   |rRt          j        |t          j                  s0t          j        | t          j                  rd}t	          |          |}nGt          j        | t          j                  st          j        |           }|}nt          |           }| }t          |          t          j	        |          fS )Na  jax.numpy.var does not yet support real dtype parameters when computing the variance of an array of complex values. The semantics of numpy.var seem unclear in this case. Please comment on https://github.com/google/jax/issues/2283 if this behavior is important to you.)
r   rI   r'   r'  ru   rz   r   r   rF   r@   )r   r@   msgr   s       r)   r%  r%    s    
 "eR%788 '2#566!c
 sOOWbj11 "%g..e ))e!	&	'	'%	88r+   c          	         ||}n*t          |t                    r|dk    rt          d          t          | t	          |          |||||          S )a:
  Compute the standard deviation along a given axis.

  JAX implementation of :func:`numpy.std`.

  Args:
    a: input array.
    axis: optional, int or sequence of ints, default=None. Axis along which the
      standard deviation is computed. If None, standard deviaiton is computed
      along all the axes.
    dtype: The type of the output array. Default=None.
    ddof: int, default=0. Degrees of freedom. The divisor in the standard deviation
      computation is ``N-ddof``, ``N`` is number of elements along given axis.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    where: optional, boolean array, default=None. The elements to be used in the
      standard deviation. Array should be broadcast compatible to the input.
    correction: int or float, default=None. Alternative name for ``ddof``.
      Both ddof and correction can't be provided simultaneously.
    out: Unused by JAX.

  Returns:
    An array of the standard deviation along the given axis.

  See also:
    - :func:`jax.numpy.var`: Compute the variance of array elements over given
      axis.
    - :func:`jax.numpy.mean`: Compute the mean of array elements over a given axis.
    - :func:`jax.numpy.nanvar`: Compute the variance along a given axis, ignoring
      NaNs values.
    - :func:`jax.numpy.nanstd`: Computed the standard deviation of a given axis,
      ignoring NaN values.

  Examples:
    By default, ``jnp.std`` computes the standard deviation along all axes.

    >>> x = jnp.array([[1, 3, 4, 2],
    ...                [4, 2, 5, 3],
    ...                [5, 4, 2, 3]])
    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.std(x)
    Array(1.21, dtype=float32)

    If ``axis=0``, computes along axis 0.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.std(x, axis=0))
    [1.7  0.82 1.25 0.47]

    To preserve the dimensions of input, you can set ``keepdims=True``.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.std(x, axis=0, keepdims=True))
    [[1.7  0.82 1.25 0.47]]

    If ``ddof=1``:

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.std(x, axis=0, keepdims=True, ddof=1))
    [[2.08 1.   1.53 0.58]]

    To include specific elements of the array to compute standard deviation, you
    can use ``where``.

    >>> where = jnp.array([[1, 0, 1, 0],
    ...                    [0, 1, 0, 1],
    ...                    [1, 1, 1, 0]], dtype=bool)
    >>> jnp.std(x, axis=0, keepdims=True, where=where)
    Array([[2., 1., 1., 0.]], dtype=float32)
  Nr   r  r   )rv   r.   ru   _stdr   r   s           r)   stdr5    sk    P JJdC   NDAII
L
M
MM	a&t,,eS*h
 
 
 r+   c          
     "   t          d|            t          j        |d           |1t          j        |t          j                  st          d|           |t          d          t          j	        t          | |||||                    S )Nr5  z/dtype argument to jnp.std must be inexact; got z/The 'out' argument to jnp.std is not supported.)rV   r@   r  rX   r   )r   r   rs   rI   r'   rz   ru   rr   r   sqrtr!  )r,   rV   r@   rW   r  rX   r   s          r)   r4  r4  '  s     %#E5111
v0
CC
NuNN
O
OO_
O
P
PP	#ad%JQYafggg	h	hhr+   c                @    t          | t          |          ||          S )a  Return the peak-to-peak range along a given axis.

  JAX implementation of :func:`numpy.ptp`.

  Args:
    a: input array.
    axis: optional, int or sequence of ints, default=None. Axis along which the
      range is computed. If None, the range is computed on the flattened array.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    out: Unused by JAX.

  Returns:
    An array with the range of elements along specified axis of input.

  Examples:
    By default, ``jnp.ptp`` computes the range along all axes.

    >>> x = jnp.array([[1, 3, 5, 2],
    ...                [4, 6, 8, 1],
    ...                [7, 9, 3, 4]])
    >>> jnp.ptp(x)
    Array(8, dtype=int32)

    If ``axis=1``, computes the range along axis 1.

    >>> jnp.ptp(x, axis=1)
    Array([4, 7, 6], dtype=int32)

    To preserve the dimensions of input, you can set ``keepdims=True``.

    >>> jnp.ptp(x, axis=1, keepdims=True)
    Array([[4],
           [7],
           [6]], dtype=int32)
  )_ptpr   )r,   rV   rW   rX   s       r)   ptpr:  4  s"    L 
a&t,,c8	<	<<r+   c                    t          d|            |t          d          t          | ||          }t          | ||          }t	          j        ||          S )Nr:  z/The 'out' argument to jnp.ptp is not supported.r   )r   rr   r   r   r   r&  )r,   rV   rW   rX   r   ys         r)   r9  r9  \  s`     %_
O
P
PP
14(+++!
14(+++!	Ar+   c           	         t          d|            t          t          j        | t	          | d                    |t          j        t                    |          S )a#  Return the number of nonzero elements along a given axis.

  JAX implementation of :func:`numpy.count_nonzero`.

  Args:
    a: input array.
    axis: optional, int or sequence of ints, default=None. Axis along which the
      number of nonzeros are counted. If None, counts within the flattened array.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.

  Returns:
    An array with number of nonzeros elements along specified axis of the input.

  Examples:
    By default, ``jnp.count_nonzero`` counts the nonzero values along all axes.

    >>> x = jnp.array([[1, 0, 0, 0],
    ...                [0, 0, 1, 0],
    ...                [1, 1, 1, 0]])
    >>> jnp.count_nonzero(x)
    Array(5, dtype=int32)

    If ``axis=1``, counts along axis 1.

    >>> jnp.count_nonzero(x, axis=1)
    Array([1, 1, 3], dtype=int32)

    To preserve the dimensions of input, you can set ``keepdims=True``.

    >>> jnp.count_nonzero(x, axis=1, keepdims=True)
    Array([[1],
           [1],
           [3]], dtype=int32)
  count_nonzeror   r   )r   r   r   ne
_lax_constr   ry   r.   )r,   rV   rX   s      r)   r>  r>  g  sZ    L /1%%%	SVAz!Q''((t,S11H
F 
F 
F Fr+   jnp_reductionCallable[..., Array]nan_if_all_nanc           	        t          ||            t          j        t          j        |           t          j                  s || f||d|S  |t          t          j        |           t          | |          |           f||d|}|rKt          t          t          j        |           ||          t          | t          j                  |          S |S )Nr   )r   r   rI   r@   r'   rz   r   r7   _isnanr|   r   r@  r-  )	r,   r]   rA  rb   rC  rV   rX   kwargsrW   s	            r)   _nan_reductionrG    s     $		6<??BJ	7	7 D=CCCFCCCf\0335HH5U5UWXYY 	>(	> 	>6<	> 	># #l)!,,4(KKKQ''. . . Jr+   c                V    t          | dt          t          j        |du |||||
  
        S )aJ
  Return the minimum of the array elements along a given axis, ignoring NaNs.

  JAX implementation of :func:`numpy.nanmin`.

  Args:
    a: Input array.
    axis: int or sequence of ints, default=None. Axis along which the minimum is
      computed. If None, the minimum is computed along the flattened array.
    keepdims: bool, default=False. If True, reduced axes are left in the result
      with size 1.
    initial: int or array, default=None. Initial value for the minimum.
    where: array of boolean dtype, default=None. The elements to be used in the
      minimum. Array should be broadcast compatible to the input. ``initial``
      must be specified when ``where`` is used.
    out: Unused by JAX.

  Returns:
    An array of minimum values along the given axis, ignoring NaNs. If all values
    are NaNs along the given axis, returns ``nan``.

  See also:
    - :func:`jax.numpy.nanmax`: Compute the maximum of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nansum`: Compute the sum of array elements along a given
      axis, ignoring NaNs.
    - :func:`jax.numpy.nanprod`: Compute the product of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nanmean`: Compute the mean of array elements along a given
      axis, ignoring NaNs.

  Examples:

    By default, ``jnp.nanmin`` computes the minimum of elements along the flattened
    array.

    >>> nan = jnp.nan
    >>> x = jnp.array([[1, nan, 4, 5],
    ...                [nan, -2, nan, -4],
    ...                [2, 1, 3, nan]])
    >>> jnp.nanmin(x)
    Array(-4., dtype=float32)

    If ``axis=1``, the maximum will be computed along axis 1.

    >>> jnp.nanmin(x, axis=1)
    Array([ 1., -4.,  1.], dtype=float32)

    If ``keepdims=True``, ``ndim`` of the output will be same of that of the input.

    >>> jnp.nanmin(x, axis=1, keepdims=True)
    Array([[ 1.],
           [-4.],
           [ 1.]], dtype=float32)

    To include only specific elements in computing the maximum, you can use
    ``where``. It can either have same dimension as input

    >>> where=jnp.array([[0, 0, 1, 0],
    ...                  [0, 0, 1, 1],
    ...                  [1, 1, 1, 0]], dtype=bool)
    >>> jnp.nanmin(x, axis=1, keepdims=True, initial=0, where=where)
    Array([[ 0.],
           [-4.],
           [ 0.]], dtype=float32)

    or must be broadcast compatible with input.

    >>> where = jnp.array([[False],
    ...                    [True],
    ...                    [False]])
    >>> jnp.nanmin(x, axis=0, keepdims=True, initial=0, where=where)
    Array([[ 0., -2.,  0., -4.]], dtype=float32)
  nanminNrC  rV   rW   rX   rY   r   )rG  r   r'   r   r   s         r)   rI  rI    s8    Z 
8S"&D!sX 'u
6 
6 
6 6r+   c                X    t          | dt          t          j         |du |||||
  
        S )aC
  Return the maximum of the array elements along a given axis, ignoring NaNs.

  JAX implementation of :func:`numpy.nanmax`.

  Args:
    a: Input array.
    axis: int or sequence of ints, default=None. Axis along which the maximum is
      computed. If None, the maximum is computed along the flattened array.
    keepdims: bool, default=False. If True, reduced axes are left in the result
      with size 1.
    initial: int or array, default=None. Initial value for the maximum.
    where: array of boolean dtype, default=None. The elements to be used in the
      maximum. Array should be broadcast compatible to the input. ``initial``
      must be specified when ``where`` is used.
    out: Unused by JAX.

  Returns:
    An array of maximum values along the given axis, ignoring NaNs. If all values
    are NaNs along the given axis, returns ``nan``.

  See also:
    - :func:`jax.numpy.nanmin`: Compute the minimum of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nansum`: Compute the sum of array elements along a given
      axis, ignoring NaNs.
    - :func:`jax.numpy.nanprod`: Compute the product of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nanmean`: Compute the mean of array elements along a given
      axis, ignoring NaNs.

  Examples:

    By default, ``jnp.nanmax`` computes the maximum of elements along the flattened
    array.

    >>> nan = jnp.nan
    >>> x = jnp.array([[8, nan, 4, 6],
    ...                [nan, -2, nan, -4],
    ...                [-2, 1, 7, nan]])
    >>> jnp.nanmax(x)
    Array(8., dtype=float32)

    If ``axis=1``, the maximum will be computed along axis 1.

    >>> jnp.nanmax(x, axis=1)
    Array([ 8., -2.,  7.], dtype=float32)

    If ``keepdims=True``, ``ndim`` of the output will be same of that of the input.

    >>> jnp.nanmax(x, axis=1, keepdims=True)
    Array([[ 8.],
           [-2.],
           [ 7.]], dtype=float32)

    To include only specific elements in computing the maximum, you can use
    ``where``. It can either have same dimension as input

    >>> where=jnp.array([[0, 0, 1, 0],
    ...                  [0, 0, 1, 1],
    ...                  [1, 1, 1, 0]], dtype=bool)
    >>> jnp.nanmax(x, axis=1, keepdims=True, initial=0, where=where)
    Array([[4.],
           [0.],
           [7.]], dtype=float32)

    or must be broadcast compatible with input.

    >>> where = jnp.array([[True],
    ...                    [False],
    ...                    [False]])
    >>> jnp.nanmax(x, axis=0, keepdims=True, initial=0, where=where)
    Array([[8., 0., 4., 6.]], dtype=float32)
  nanmaxNrJ  )rG  r   r'   r   r   s         r)   rL  rL    s:    Z 
8S26''T/!sX 'u
6 
6 
6 6r+   c                j    t          j        |d           t          | dt          dd||||||          S )a
  Return the sum of the array elements along a given axis, ignoring NaNs.

  JAX implementation of :func:`numpy.nansum`.

  Args:
    a: Input array.
    axis: int or sequence of ints, default=None. Axis along which the sum is
      computed. If None, the sum is computed along the flattened array.
    dtype: The type of the output array. Default=None.
    keepdims: bool, default=False. If True, reduced axes are left in the result
      with size 1.
    initial: int or array, default=None. Initial value for the sum.
    where: array of boolean dtype, default=None. The elements to be used in the
      sum. Array should be broadcast compatible to the input.
    out: Unused by JAX.

  Returns:
    An array containing the sum of array elements along the given axis, ignoring
    NaNs. If all elements along the given axis are NaNs, returns 0.

  See also:
    - :func:`jax.numpy.nanmin`: Compute the minimum of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nanmax`: Compute the maximum of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nanprod`: Compute the product of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nanmean`: Compute the mean of array elements along a given
      axis, ignoring NaNs.

  Examples:

    By default, ``jnp.nansum`` computes the sum of elements along the flattened
    array.

    >>> nan = jnp.nan
    >>> x = jnp.array([[3, nan, 4, 5],
    ...                [nan, -2, nan, 7],
    ...                [2, 1, 6, nan]])
    >>> jnp.nansum(x)
    Array(26., dtype=float32)

    If ``axis=1``, the sum will be computed along axis 1.

    >>> jnp.nansum(x, axis=1)
    Array([12.,  5.,  9.], dtype=float32)

    If ``keepdims=True``, ``ndim`` of the output will be same of that of the input.

    >>> jnp.nansum(x, axis=1, keepdims=True)
    Array([[12.],
           [ 5.],
           [ 9.]], dtype=float32)

    To include only specific elements in computing the sum, you can use ``where``.

    >>> where=jnp.array([[1, 0, 1, 0],
    ...                  [0, 0, 1, 1],
    ...                  [1, 1, 1, 0]], dtype=bool)
    >>> jnp.nansum(x, axis=1, keepdims=True, where=where)
    Array([[7.],
           [7.],
           [9.]], dtype=float32)

    If ``where`` is ``False`` at all elements, ``jnp.nansum`` returns 0 along
    the given axis.

    >>> where = jnp.array([[False],
    ...                    [False],
    ...                    [False]])
    >>> jnp.nansum(x, axis=0, keepdims=True, where=where)
    Array([[0., 0., 0., 0.]], dtype=float32)
  nanprodnansumr   FrC  rV   r@   rW   rX   rY   r   )r   rs   rG  r   r,   rV   r@   rW   rX   rY   r   s          r)   rO  rO  F  sG    Z 	#E9555	8S!E!C( 'u
6 
6 
6 6r+   c                j    t          j        |d           t          | dt          dd||||||          S )aE
  Return the product of the array elements along a given axis, ignoring NaNs.

  JAX implementation of :func:`numpy.nanprod`.

  Args:
    a: Input array.
    axis: int or sequence of ints, default=None. Axis along which the product is
      computed. If None, the product is computed along the flattened array.
    dtype: The type of the output array. Default=None.
    keepdims: bool, default=False. If True, reduced axes are left in the result
      with size 1.
    initial: int or array, default=None. Initial value for the product.
    where: array of boolean dtype, default=None. The elements to be used in the
      product. Array should be broadcast compatible to the input.
    out: Unused by JAX.

  Returns:
    An array containing the product of array elements along the given axis,
    ignoring NaNs. If all elements along the given axis are NaNs, returns 1.

  See also:
    - :func:`jax.numpy.nanmin`: Compute the minimum of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nanmax`: Compute the maximum of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nansum`: Compute the sum of array elements along a given
      axis, ignoring NaNs.
    - :func:`jax.numpy.nanmean`: Compute the mean of array elements along a given
      axis, ignoring NaNs.

  Examples:

    By default, ``jnp.nanprod`` computes the product of elements along the flattened
    array.

    >>> nan = jnp.nan
    >>> x = jnp.array([[nan, 3, 4, nan],
    ...                [5, nan, 1, 3],
    ...                [2, 1, nan, 1]])
    >>> jnp.nanprod(x)
    Array(360., dtype=float32)

    If ``axis=1``, the product will be computed along axis 1.

    >>> jnp.nanprod(x, axis=1)
    Array([12., 15.,  2.], dtype=float32)

    If ``keepdims=True``, ``ndim`` of the output will be same of that of the input.

    >>> jnp.nanprod(x, axis=1, keepdims=True)
    Array([[12.],
           [15.],
           [ 2.]], dtype=float32)

    To include only specific elements in computing the maximum, you can use ``where``.

    >>> where=jnp.array([[1, 0, 1, 0],
    ...                  [0, 0, 1, 1],
    ...                  [1, 1, 1, 0]], dtype=bool)
    >>> jnp.nanprod(x, axis=1, keepdims=True, where=where)
    Array([[4.],
           [3.],
           [2.]], dtype=float32)

    If ``where`` is ``False`` at all elements, ``jnp.nanprod`` returns 1 along
    the given axis.

    >>> where = jnp.array([[False],
    ...                    [False],
    ...                    [False]])
    >>> jnp.nanprod(x, axis=0, keepdims=True, where=where)
    Array([[1., 1., 1., 1.]], dtype=float32)
  rN  rn   FrP  )r   rs   rG  r   rQ  s          r)   rN  rN    sG    Z 	#E9555	9dAe!C( 'u
6 
6 
6 6r+   c           	        t          d|            |t          d          t          j        t          j        |           t
          j                  s1t          j        t          j        |           t
          j                  rt          | |||||          S |)t          j	        t          j        | d                    }n)t          j
        |d           t          j        |          }t          j        t          j        |                     }t          |||||          }t!          j        t%          | ||||	          |          }|S )
a
  Return the mean of the array elements along a given axis, ignoring NaNs.

  JAX implementation of :func:`numpy.nanmean`.

  Args:
    a: Input array.
    axis: int or sequence of ints, default=None. Axis along which the mean is
      computed. If None, the mean is computed along the flattened array.
    dtype: The type of the output array. Default=None.
    keepdims: bool, default=False. If True, reduced axes are left in the result
      with size 1.
    where: array of boolean dtype, default=None. The elements to be used in
      computing mean. Array should be broadcast compatible to the input.
    out: Unused by JAX.

  Returns:
    An array containing the mean of array elements along the given axis, ignoring
    NaNs. If all elements along the given axis are NaNs, returns ``nan``.

  See also:
    - :func:`jax.numpy.nanmin`: Compute the minimum of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nanmax`: Compute the maximum of array elements along a
      given axis, ignoring NaNs.
    - :func:`jax.numpy.nansum`: Compute the sum of array elements along a given
      axis, ignoring NaNs.
    - :func:`jax.numpy.nanprod`: Compute the product of array elements along a
      given axis, ignoring NaNs.

  Examples:

    By default, ``jnp.nanmean`` computes the mean of elements along the flattened
    array.

    >>> nan = jnp.nan
    >>> x = jnp.array([[2, nan, 4, 3],
    ...                [nan, -2, nan, 9],
    ...                [4, -7, 6, nan]])
    >>> jnp.nanmean(x)
    Array(2.375, dtype=float32)

    If ``axis=1``, mean will be computed along axis 1.

    >>> jnp.nanmean(x, axis=1)
    Array([3. , 3.5, 1. ], dtype=float32)

    If ``keepdims=True``, ``ndim`` of the output will be same of that of the input.

    >>> jnp.nanmean(x, axis=1, keepdims=True)
    Array([[3. ],
           [3.5],
           [1. ]], dtype=float32)

    ``where`` can be used to include only specific elements in computing the mean.

    >>> where = jnp.array([[1, 0, 1, 0],
    ...                    [0, 0, 1, 1],
    ...                    [1, 1, 0, 1]], dtype=bool)
    >>> jnp.nanmean(x, axis=1, keepdims=True, where=where)
    Array([[ 3. ],
           [ 9. ],
           [-1.5]], dtype=float32)

    If ``where`` is ``False`` at all elements, ``jnp.nanmean`` returns ``nan``
    along the given axis.

    >>> where = jnp.array([[False],
    ...                    [False],
    ...                    [False]])
    >>> jnp.nanmean(x, axis=0, keepdims=True, where=where)
    Array([[nan, nan, nan, nan]], dtype=float32)
  nanmeanNz3The 'out' argument to jnp.nanmean is not supported.r   Tr   r   )rV   r@   rX   r   r   )r   rr   r   rI   r@   r'   rJ   rP   r   r   rs   ry   r7   bitwise_notrE  r   r   r   rO  )	r,   rV   r@   rW   rX   r   nan_maskr  tds	            r)   rT  rT    s)   V )Q_
S
T
TTv|A11 <V5Fv|TUXZXb5c5c <4XU;;;;
]#FL$F$F$FGGEE
%eV444%e,,E%l&9!&<&<==(8$eheTTT*
wvaUXUKKKZXX"	)r+   c                F   t          d|            t          j        |d           |t          d          t	          t          j        |           |          \  }}t          j        |                               |          } t          | ||d|          }t          t          j        |           dt          j        | |                    }	t          j        |	j        t          j                  r:t          j        t          j        |	t          j        |	                              }	nt          j        |	          }	t+          t          j        t          j        |                     |||          }
|
|z
  }
t          j        |
t          j        |
                    }t+          |	|||          }t          |t          j        |          }t          |d	|
          }t          j        |t          j        ||j                            }t          j        ||          S )
a	  Compute the variance of array elements along a given axis, ignoring NaNs.

  JAX implementation of :func:`numpy.nanvar`.

  Args:
    a: input array.
    axis: optional, int or sequence of ints, default=None. Axis along which the
      variance is computed. If None, variance is computed along flattened array.
    dtype: The type of the output array. Default=None.
    ddof: int, default=0. Degrees of freedom. The divisor in the variance computation
      is ``N-ddof``, ``N`` is number of elements along given axis.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    where: optional, boolean array, default=None. The elements to be used in the
      variance. Array should be broadcast compatible to the input.
    out: Unused by JAX.

  Returns:
    An array containing the variance of array elements along specified axis. If
    all elements along the given axis are NaNs, returns ``nan``.

  See also:
    - :func:`jax.numpy.nanmean`: Compute the mean of array elements over a given
      axis, ignoring NaNs.
    - :func:`jax.numpy.nanstd`: Computed the standard deviation of a given axis,
      ignoring NaNs.
    - :func:`jax.numpy.var`: Compute the variance of array elements along a given
      axis.

  Examples:
    By default, ``jnp.nanvar`` computes the variance along all axes.

    >>> nan = jnp.nan
    >>> x = jnp.array([[1, nan, 4, 3],
    ...                [nan, 2, nan, 9],
    ...                [4, 8, 6, nan]])
    >>> jnp.nanvar(x)
    Array(6.984375, dtype=float32)

    If ``axis=1``, variance is computed along axis 1.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.nanvar(x, axis=1))
    [ 1.56 12.25  2.67]

    To preserve the dimensions of input, you can set ``keepdims=True``.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.nanvar(x, axis=1, keepdims=True))
    [[ 1.56]
     [12.25]
     [ 2.67]]

    If ``ddof=1``:

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.nanvar(x, axis=1, keepdims=True, ddof=1))
    [[ 2.33]
     [24.5 ]
     [ 4.  ]]

    To include specific elements of the array to compute variance, you can use
    ``where``.

    >>> where = jnp.array([[1, 0, 1, 0],
    ...                    [0, 1, 1, 0],
    ...                    [1, 1, 0, 1]], dtype=bool)
    >>> jnp.nanvar(x, axis=1, keepdims=True, where=where)
    Array([[2.25],
           [0.  ],
           [4.  ]], dtype=float32)
  nanvarNz2The 'out' argument to jnp.nanvar is not supported.Tr   r   )rV   rX   r   )rX   r   rn   )r   r   rs   rr   r%  r@   r7   r8   r   rT  r   rE  r   r&  rI   r'   r'  r(  r   r)  r*  r   rU  le_zeror-  r   r{   )r,   rV   r@   rW   r  rX   r   r   r.  r/  r  normalizer_maskr   divisors                 r)   rY  rY  G  s   X (A#E8444_
R
S
SS/QGGU1$$%677!1d"3d%PPP&L'**Aswq&/A/ABB(x~r'9:: $x#(8*<*<==>>HHz(##H<+L,?,B,BCCxu> > >*D *F:|'9*'E'EFF/x>>>&/26622&?Az22'7633GV\JJKK&		!&%	0	00r+   c           
         t          d|            t          j        |d           |t          d          t	          j        t          | |||||                    S )ay	  Compute the standard deviation along a given axis, ignoring NaNs.

  JAX implementation of :func:`numpy.nanstd`.

  Args:
    a: input array.
    axis: optional, int or sequence of ints, default=None. Axis along which the
      standard deviation is computed. If None, standard deviaiton is computed
      along flattened array.
    dtype: The type of the output array. Default=None.
    ddof: int, default=0. Degrees of freedom. The divisor in the standard deviation
      computation is ``N-ddof``, ``N`` is number of elements along given axis.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    where: optional, boolean array, default=None. The elements to be used in the
      standard deviation. Array should be broadcast compatible to the input.
    out: Unused by JAX.

  Returns:
    An array containing the standard deviation of array elements along the given
    axis. If all elements along the given axis are NaNs, returns ``nan``.

  See also:
    - :func:`jax.numpy.nanmean`: Compute the mean of array elements over a given
      axis, ignoring NaNs.
    - :func:`jax.numpy.nanvar`: Compute the variance along the given axis, ignoring
      NaNs values.
    - :func:`jax.numpy.std`: Computed the standard deviation along the given axis.

  Examples:
    By default, ``jnp.nanstd`` computes the standard deviation along flattened array.

    >>> nan = jnp.nan
    >>> x = jnp.array([[3, nan, 4, 5],
    ...                [nan, 2, nan, 7],
    ...                [2, 1, 6, nan]])
    >>> jnp.nanstd(x)
    Array(1.9843135, dtype=float32)

    If ``axis=0``, computes standard deviation along axis 0.

    >>> jnp.nanstd(x, axis=0)
    Array([0.5, 0.5, 1. , 1. ], dtype=float32)

    To preserve the dimensions of input, you can set ``keepdims=True``.

    >>> jnp.nanstd(x, axis=0, keepdims=True)
    Array([[0.5, 0.5, 1. , 1. ]], dtype=float32)

    If ``ddof=1``:

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.nanstd(x, axis=0, keepdims=True, ddof=1))
    [[0.71 0.71 1.41 1.41]]

    To include specific elements of the array to compute standard deviation, you
    can use ``where``.

    >>> where=jnp.array([[1, 0, 1, 0],
    ...                  [0, 1, 0, 1],
    ...                  [1, 1, 0, 1]], dtype=bool)
    >>> jnp.nanstd(x, axis=0, keepdims=True, where=where)
    Array([[0.5, 0.5, 0. , 0. ]], dtype=float32)
  nanstdNz2The 'out' argument to jnp.nanstd is not supported.)rV   r@   r  rX   r   )r   r   rs   rr   r   r7  rY  )r,   rV   r@   rW   r  rX   r   s          r)   r_  r_    sb    H (A#E8444_
R
S
SS	&UX]^^^	_	__r+   c                      e Zd Z	 	 dddZdS )CumulativeReductionNr,   r   rV   re   r@   rf   rW   rg   r!   r   c                    d S rH   r3   )selfr,   rV   r@   rW   s        r)   __call__zCumulativeReduction.__call__  s    KN3r+   NNN
r,   r   rV   re   r@   rf   rW   rg   r!   r   )__name__
__module____qualname__rd  r3   r+   r)   ra  ra    s:        04;?O O O O O O Or+   ra  zz
Unlike the numpy counterpart, when ``dtype`` is not specified the output dtype will always
match the dtype of the input.
np_reduction	reductionfill_nan
fill_valuec                     t           dgt                    	 	 ddfd            }t          t          j        d          	 	 dd fd            |S )NrW   )skip_paramslax_descriptionr,   r   rV   re   r@   rf   rg   r!   r   c                :     | t          |          ||          S rH   )r   )r,   rV   r@   rW   _cumulative_reductions       r)   cumulative_reductionz8_make_cumulative_reduction.<locals>.cumulative_reduction  s%     ! $9$$?$?LLLr+   rV   r@   r"  c                p   t          
j        |            |t          d
j         d          t          j        |
j                   |t          |           r(t          j        | t          j	        |           f          } |d}t          t          j        |                     }t          |          }t          ||          }r1t          t          j        |           t#          | 	          |           } t          j        |p|           }|st          j        |t          j                  rt+          |          }t          j        |          }t          j        | |          }  | |          }t          j        |t          j                  rt          j        |t          j                  }|S )Nrk   rl   r   )r   rg  rr   r   rs   r*   r   reshaper'   r   r   rp   r   r9   r   r7   rE  r@  r@   rI   rJ   rQ   ry   r{   )r,   rV   r@   rW   r   num_dimsresult_typer   rl  rm  rj  r\   rk  s           r)   rr  z9_make_cumulative_reduction.<locals>._cumulative_reduction  s    L)1---
 !5\=R !5 !5 !5 6 6 6
%e\-BCCC|y|||
+a"'!**
'
'a|d28A;;G7||HdH--D G
$Q''Az)B)BA
F
Fa#\%*155K})}V->{BH-U-U}*;77k+K88K K00AYq$F )) :'99fMr+   re  rf  )r   CUML_REDUCTION_LAX_DESCRIPTIONr   r   jit)rj  rk  rl  rm  r\   rs  rr  s   ````` @r)   _make_cumulative_reductionr{    s     l8: : :6:GKM M M M M M: :M 37$56667;HL          76B 
r+   )rl  )rl  rm  rn   )rl  r\   cumulative_sum)rV   r@   include_initial
int | Noner}  c                 t          d|            t          j        |           } | j        dk    rt	          d          |%d}| j        dk    rt	          d| j         d          t          || j                  }t          j        |           t          | ||          }|rKt          | j
                  }d||<   t          j        t          j        |d|j                  |g|	          }|S )
Nr|  r   zhThe input must be non-scalar to take a cumulative sum, however a scalar value or scalar array was given.rn   zThe input array has rank zo, however axis was not set to an explicit value. The axis argument is only optional for one-dimensional arrays.rt  rE   	dimension)r   r7   r8   r:   ru   r9   r   rs   _cumsum_with_promotionr   rp   concatenater  r@   )r   rV   r@   r}  rW   zeros_shapes         r)   r|  r|  ;  s   
 "A&&&1!Vq[[
0   
\Dvzz	AF 	 	 	  
 
D!&	)	)$#E***qt5999# qw--KK

"asy9993?  C 
*r+   overwrite_input)ro  )rV   r  interpolationrX   methodlinear)r  qint | tuple[int, ...] | Noner  r  DeprecatedArg | strc               $   t          d| |           |s|d}t          |          t          |t                    st	          j        dt          d           |}t          t          j	        |           t          j	        |          |||d          S )NquantilezGjax.numpy.quantile does not support overwrite_input=True or out != NonezOThe interpolation= argument to 'quantile' is deprecated. Use 'method=' instead.r   
stacklevelF
r   ru   rv   r   r   warnDeprecationWarning	_quantiler7   r8   	r,   r  rV   rW   r  r  rX   r  r2  s	            r)   r  r  ]  s    
 *a### C
S//	M=	1	1 M +,>1N N N NF	<'**L,@,C,CT6S[]b	c	ccr+   c               $   t          d| |           |s|d}t          |          t          |t                    st	          j        dt          d           |}t          t          j	        |           t          j	        |          |||d          S )NnanquantilezJjax.numpy.nanquantile does not support overwrite_input=True or out != NonezRThe interpolation= argument to 'nanquantile' is deprecated. Use 'method=' instead.r   r  Tr  r  s	            r)   r  r  n  s    
 -A&&& C
S//	M=	1	1 M +,>1N N N NF	<'**L,@,C,CT6S[]a	b	bbr+   squash_nansc                    |dvrt          d          t          |           \  } g }t          j        | j        t
          j                  rt          d          %|rdg| j        z  }|                                 } dnt          t                    rt          | j                  }| j        t          fdD                       t          t                              t                    k    rt          d          D ]}d||<   t          t                              t                    z
  }t          t                              }	t!          t#          |                    D ]\  }
}|	|         |	|
         c|	|
<   |	|<   t          fdt!          | j                  D                       }t          fd	t!          | j                  D                       }t%          j        | |t)          j        |          fz   |	          } t-          d
| j                  nt-          | j                  |j        }|j          dk    rt          d|j                   | j        }|rt/          t1          j        |           t
          j        |           } t%          j        |           } t9          t1          j        t1          j        |                     |j        |          }|j        }t%          j        |t          t           t          |           z                                 }t%          j        |t          t                                         }t%          j        |t%          j         |tC          |d                              }t%          j"        |          }t%          j#        |          }t%          j         ||          }t%          j         tC          |d          |          }t%          j$        tC          |d          t%          j%        ||dz
                      }t%          j$        tC          |d          t%          j%        ||dz
                      }t%          j&        |tN                    }t%          j&        |tN                    }||z    fdt          t          |                    D             }|r||<   n|(                    |           | t          |                   }||<   | t          |                   }ngt/          tS          t1          j        |           d          t
          j        |           } t%          j        |           } t%          j&        |         tU          j+        |                    }t%          j        ||dz
            }t%          j"        |          }t%          j#        |          }t%          j         ||          }t%          j         tC          |d          |          }t%          j,        tC          |d          ||dz
            }t%          j,        tC          |d          ||dz
            }t%          j&        |tN                    }t%          j&        |tN                    }t          |          }d|<   t%          j-        t          t           |rt          |           z   nt          |           z   dz
                      |rdnff          }t%          j.        | |d         ||          }t%          j.        | |d         ||          } dk    r8t%          j/        ||j        d          }t%          j/        ||j        d          }|dk    rlt%          j0        t%          j        |1                    |j                  |          t%          j        |1                    |j                  |                    }n|dk    r|}n|dk    r|}n|dk    r:t%          j2        |tC          |d                    }t%          j3        |||          }nP|dk    r7t%          j        t%          j0        ||          tC          |d                    }nt          d|d          |r:|r8 dk    rt          j        |          d         g|}|                    |          }t%          j&        || j                  S )N)r  lowerhighermidpointnearestzHmethod can only be 'linear', 'lower', 'higher', 'midpoint', or 'nearest'zLquantile does not support complex input, as the operation is poorly defined.rn   r   c              3  8   K   | ]}t          |          V  d S rH   r   )r4   axnds     r)   rq   z_quantile.<locals>.<genexpr>  s.      ;;#B++;;;;;;r+   zrepeated axisc              3  *   K   | ]\  }}|v	|V  d S rH   r3   r4   idxr   rV   s      r)   rq   z_quantile.<locals>.<genexpr>  s+      TTUSCtOOqOOOOTTr+   c              3  *   K   | ]\  }}|v 	|V  d S rH   r3   r  s      r)   rq   z_quantile.<locals>.<genexpr>  s+      IIec!SD[[[[[[IIr+   r  z$q must be have rank <= 1, got shape r  r   c                L    g | ] }t          j        t          |z             !S r3   )r   broadcasted_iotar.   )r4   dim	out_shapeq_ndims     r)   r6   z_quantile.<locals>.<listcomp>  s<     ; ; ; !#y#,?? ; ; ;r+   Tr   r3   )offset_dimscollapsed_slice_dimsstart_index_map).N)dimension_numbersslice_sizes)r   )broadcast_dimensionsr  r  r  r        ?r  zmethod=z not recognized)4ru   r   r   rI   r@   r'   r'  r:   ravelrv   r   r   rp   r   r   r;   	enumeratesortedr   rv  r  r   r9   r   r   isnanr-  sortr   logical_notr~   r   r&  r@  floorceilr   r   r{   r.   r<   r   r7   _dtypeclampGatherDimensionNumbersgatherbroadcast_in_dimr   r   rZ  select)!r,   r  rV   r  rX   r  keepdimr  keep
dimensionsr5   sdo_not_touch_shapetouch_shapeq_shaper   countsshape_after_reductionlowhighhigh_weight
low_weightr   	low_value
high_valuenr  dnumsr   predr  r  r  s!     `                           @@@r)   r  r  ~  sE   GGG
_
`
``a  "!'qw 233 e
c
d
dd	\ afg			ADD$ ,17mmG	
B;;;;d;;;;;D
3t99~~T""'''  gbkkuRyy>>CII%DeBiiJ&,,'' B B1%/]JqM"jmZ]]TTTTi.@.@TTTTTIIIIy'9'9IIIIIKA)TY{-C-C,EEzRRAb!&))DDdAF++DG'6&aZZ
EAGEE
F
FFG' ;Cv|A**Ad###A#FLOO444qwYabbbF"LuVS!677&@AA	B	B	D 	DA_VU5==%9%9::F376:a#3#34455A
)A,,C8A;;D'!S//KK33[AAJ
'*S!$$cgc6A:&>&>
?
?C7:dA&&fqj(A(ABBD

"3
,
,C#D#..D//I; ; ; ; ;c"78899; ; ;E eDkkll4%,,IE$K5<<JJs6<??===rvqIIAd###A 0CA0F0FGGA1q5A
)A,,C8A;;D'!S//KK33[AAJ
)JsA&&QU
3
3C9Za(($A66D

"3
,
,C#D#..Dw--KK&!)HGvs7||f/Dq/HJ J K K "*622wg  E 
1c)n'24 4 4IAtI%(35 5 5J{{'
IO=AC C Cj(j6F=AC C Ck xWSWY--ag66
CCWZ..qw77EEG GFFFFFF6+z+s;;<<DZi44FFWSWY
33Z	35O5OPPFF
2222
3
33 %' %zz!Q*'*g^^G$$F		!&!'	2	22r+   str | DeprecatedArgc          	         t          d| |           t          |          \  }t          |t                    st	          j        dt          d           |}t          | |dz  |||||          S )N
percentilezQThe interpolation= argument to 'percentile' is deprecated. Use 'method=' instead.r   r  d   rV   rW   r  r  rX   )r   r   rv   r   r   r  r  r  r,   r  rV   rW   r  r  rX   r  s           r)   r  r    s     ,1%%%a  "!	M=	1	1 M +,>1N N N NF	!QW4S/(
4 
4 
4 4r+   c          	         t          d| |           t          j        |d          }t          |t                    st          j        dt          d           |}t          | ||||||          S )Nnanpercentileg      Y@zTThe interpolation= argument to 'nanpercentile' is deprecated. Use 'method=' instead.r   r  r  )	r   r   true_dividerv   r   r   r  r  r  r  s           r)   r  r  	  s     /1a(((E""!	M=	1	1 M +,>1N N N NF	Q#"X
7 
7 
7 7r+   )rV   r  rX   c           	     N    t          d|            t          | d||||d          S )aF  Return the median of array elements along a given axis.

  JAX implementation of :func:`numpy.median`.

  Args:
    a: input array.
    axis: optional, int or sequence of ints, default=None. Axis along which the
      median to be computed. If None, median is computed for the flattened array.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    out: Unused by JAX.
    overwrite_input: Unused by JAX.

  Returns:
    An array of the median along the given axis.

  See also:
    - :func:`jax.numpy.mean`: Compute the mean of array elements over a given axis.
    - :func:`jax.numpy.max`: Compute the maximum of array elements over given axis.
    - :func:`jax.numpy.min`: Compute the minimum of array elements over given axis.

  Examples:
    By default, the median is computed for the flattened array.

    >>> x = jnp.array([[2, 4, 7, 1],
    ...                [3, 5, 9, 2],
    ...                [6, 1, 8, 3]])
    >>> jnp.median(x)
    Array(3.5, dtype=float32)

    If ``axis=1``, the median is computed along axis 1.

    >>> jnp.median(x, axis=1)
    Array([3. , 4. , 4.5], dtype=float32)

    If ``keepdims=True``, ``ndim`` of the output is equal to that of the input.

    >>> jnp.median(x, axis=1, keepdims=True)
    Array([[3. ],
           [4. ],
           [4.5]], dtype=float32)
  medianr  r  rV   rW   r  rX   r  )r   r  r,   rV   rW   r  rX   s        r)   r  r    s;    \ (A	!Sto#J
8 
8 
8 8r+   c           	     N    t          d|            t          | d||||d          S )a!  Return the median of array elements along a given axis, ignoring NaNs.

  JAX implementation of :func:`numpy.nanmedian`.

  Args:
    a: input array.
    axis: optional, int or sequence of ints, default=None. Axis along which the
      median to be computed. If None, median is computed for the flattened array.
    keepdims: bool, default=False. If true, reduced axes are left in the result
      with size 1.
    out: Unused by JAX.
    overwrite_input: Unused by JAX.

  Returns:
    An array containing the median along the given axis, ignoring NaNs. If all
    elements along the given axis are NaNs, returns ``nan``.

  See also:
    - :func:`jax.numpy.nanmean`: Compute the mean of array elements over a given
      axis, ignoring NaNs.
    - :func:`jax.numpy.nanmax`: Compute the maximum of array elements over given
      axis, ignoring NaNs.
    - :func:`jax.numpy.nanmin`: Compute the minimum of array elements over given
      axis, ignoring NaNs.

  Examples:
    By default, the median is computed for the flattened array.

    >>> nan = jnp.nan
    >>> x = jnp.array([[2, nan, 7, nan],
    ...                [nan, 5, 9, 2],
    ...                [6, 1, nan, 3]])
    >>> jnp.nanmedian(x)
    Array(4., dtype=float32)

    If ``axis=1``, the median is computed along axis 1.

    >>> jnp.nanmedian(x, axis=1)
    Array([4.5, 5. , 3. ], dtype=float32)

    If ``keepdims=True``, ``ndim`` of the output is equal to that of the input.

    >>> jnp.nanmedian(x, axis=1, keepdims=True)
    Array([[4.5],
           [5. ],
           [3. ]], dtype=float32)
  	nanmedianr  r  r  )r   r  r  s        r)   r  r  L  s<    f +q!!!	Q$C%4x&
( 
( 
( (r+   )r    r   r!   r"   )r,   r   r-   r.   r/   r.   r!   r   )r@   r   r!   r   )r@   r   r!   r   )$r,   r   r]   r^   r_   r   r`   ra   rb   r   rR   r"   rS   rc   rT   rd   rU   r"   rV   re   r@   rf   rW   rg   rX   r"   rY   rh   rZ   rh   r[   ri   r\   r"   r!   r   )r,   r   rV   re   )r,   r   rb   r   r!   r   )r   r   r!   r   )r   re   r!   re   )NNNFNNT)r,   r   rV   re   r@   rf   rW   rg   rX   r"   rY   rh   r   rh   r\   r"   r!   r   )NNFNN)r,   r   rV   re   rW   rg   rX   r"   rY   rh   r   rh   r!   r   )NNF)r,   r   rV   re   rW   rg   rX   r"   r   rh   r!   r   )r,   r   rV   r   )NNNF)r,   r   rV   re   r@   rf   rW   rg   rX   r"   r   rh   r!   r   )r,   r   rV   re   r@   rf   rW   rg   rX   r"   rU   r"   r   rh   r!   r   )NNFF)r,   r   rV   re   r  rh   r  r  rX   r"   r!   r   )NN)r,   r   rV   re   r  rh   r  r  rX   r"   r!   r   )r,   r   rV   re   r  rh   r  r"   rX   r"   r!   r
  )NNNr   F)r,   r   rV   re   r@   rf   rW   rg   r  r.   rX   r"   r   rh   r  r  r!   r   )r,   r   rV   re   r@   rf   rW   rg   r  r#  rX   r"   r   rh   r!   r   )r   r   r@   rf   r!   r0  )
r,   r   rV   re   rW   rg   rX   r"   r!   r   )NF)r,   r   rV   re   rX   r"   r!   r   )r,   r   r]   r^   rA  rB  rb   r   rC  r"   rV   re   rX   r"   r!   r   )NNNFNN)r,   r   rV   re   r@   rf   rW   rg   rX   r"   rY   rh   r   rh   r!   r   )NNNFN)NNNr   FN)r,   r   rV   re   r@   rf   rW   rg   r  r.   rX   r"   r   rh   r!   r   )Fr   F)rj  r   rk  rB  rl  r"   rm  r   r\   r"   r!   ra  )
r   r   rV   r~  r@   rf   r}  r"   r!   r   )NNFr  F)r,   r   r  r   rV   r  rW   rg   r  r"   r  r^   rX   r"   r  r  r!   r   )r,   r   r  r   rV   r  r  r^   rX   r"   r  r"   r!   r   )r,   r   r  r   rV   r  rW   rg   r  r"   r  r^   rX   r"   r  r  r!   r   )r,   r   rV   r  rW   rg   r  r"   rX   r"   r!   r   )v
__future__r   builtinscollections.abcr   r   	functoolsr   r  r   typingr   r   r	   r
   r   r   numpyr'   r+  r   jax._srcr   r   r   jax._src.numpyr   jax._src.numpy.utilr   r   r   r   r   r   r   jax._src.laxr7   jax._src.typingr   r   r   r   r   jax._src.utilr   r9   r   r   r   rx   _constr@  r.   re   r*   r?   rF   rQ   ra   r   r   rw   r|   r   r   r   rz  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r!  r  r%  r5  r4  r:  r9  r>  rG  rI  rL  rO  rN  rT  rY  r_  ra  ry  r{  cumsumcumprod	nancumsum
nancumprodr  getattrr|  r  r  r  r  r  r  r  r3   r+   r)   <module>r     s   # " " " " "  . . . . . . . .         : : : : : : : : : : : : : :      



                         ! ! ! ! ! !H H H H H H H H H H H H H H H H H H - , , , , , M M M M M M M M M M M M M M         
 | 
 S(3-%&B B B B
          
    Sz3' (,BF-127 Dd %4*.>B(-AA AA AA AA AA AAFW W W" " " "G G G G"7 7 7 7
, , , ,	= 	= 	= 	= 	"S\`aaaKO38LP)-7 7 7 7 ba7 DHNRAEG8 G8 G8 G8 G8T 	"S\`aaaLP49MQ*.V V V V baV EI,1EI"&H9 H9 H9 H9 H9V 	"6tDDD=ADH*.M M M M EDM 6:<@"&GF GF GF GF GFR 	"6tDDD=ADH*.M M M M EDM 6:<@"&FF FF FF FF FFP 	"6tDDD=A!&IEII I I I I EDI 6:/5=A/5 /5 /5 /5 /5 /5b 	"6tDDD=A!&IEII I I I I EDI 6:/5=A/5 /5 /5 /5 /5 /5b 7;<@"&+ + + + + 7;<@"&+ + + + +	 	 	 	 EI,1;#'; ; ; ; ; ;z 	"?MMMEI-2-1$(     NM@ 
IM?DT T T T 
T	K6;K K K K K 
K	IM5:` ` ` ` 
`BJIM5:O O O O O 	"B4PPPJN6;3 3 3 3 QP3l DH:?Q"&Q Q Q Q Q Qf 	"?@@@DHIN #'          A@ F9 9 9 9* DH:?M"&M M M M M M^ 	"?@@@DHIN	i#'	i 	i 	i 	i 	i A@	i 6:&= &= &= &= &=P 	"67776:    87 	"6777-1#('F 'F 'F 'F 87'FX 8=      	"67778<?C%)N6 N6 N6 N6 87N6b 	"67778<?C%)N6 N6 N6 N6 87N6b 	"?@@@X\?C%)O6 O6 O6 O6 A@O6d 	"?@@@Y]@D&*O6 O6 O6 O6 A@O6d 	"?@@@Y]>BW W W W A@Wt 	"?@@@X\+0%)b1 b1 b1 b1 A@b1J 	"?@@@X\+0%)G` G` G` G` A@G`TO O O O O( O O O"  PQ8=+ + + + +\ 
$	#BIszE	J	J	J
$
$RZu
M
M
M&&r|SZ04D D D	''s{15!E E E
33)SZ%$    GGB($//00+/"!     10B BKe->%?@@@"deeeNRLT#dMZ]__d d d d d fe A@d BN0A(BCCC"deeeQUOW!&cP]P]P_P_c c c c c fe DCcx3 x3 x3 x3v BM/@'ABBB"deee48NV %4 P]}4 4 4 4 4 fe CB4 B52C*DEEE"deee7;QY#(7 S`R_RaRa7 7 7 7 7 fe FE7 	"IJJJ>B5:!/8 /8 /8 /8 KJ/8d 	"IJJJAE8=$5( 5( 5( 5( KJ5( 5( 5(r+   