
    Vpf%             	      p   d dl mZ d dlmZmZ d dlmZ d dlZd dlm	Z	 d dl
Z
d dl
mZ d dlZd dlZd dlmZ d dlmZ d dlmZmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZm Z  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, d dl-m.Z.m/Z/m0Z0 d dl1m2Z2 e/Z3e/Z4e0Z5e0Z6e0Z7ee8         Z9ej:        Z:e.Z;e/Z<ej=        Z=e&j>        Z?ddZ@dddd%ZAd& ZBdd,ZCd- ZD G d. d/          ZEeeFeEe:f         ZGdd3ZHdd7ZIdd8dd:ZJdd8dd;ZKdd>ZLdcddBZMdcddCZNddEZOddGZPddHZQddIZRdd8ddKZSddMZT	 	 dddQZUdNeVdRdSfddXZW eedYZ          dd[            ZXe8fdd]ZY eed^Z          dd_            ZZ	 	 dddbZ[ eedcZ          ddd            Z\	 	 	 	 dddjZ]dNeVfddkZ^ eedYZ          ddl            Z_ eedYZ          ddm            Z`	 	 	 dddtZa eeduZ          ddv            ZbdeVfddyZc eedzZ          dd{            Zd eje        d|          dfdd}Zf eedcZ          dd~            ZgdeVfddZhddZidNeVfddZj eedYZ          dd            ZkdeVfddZl eedZ          dd            ZmddZndNeVfddZo eedYZ          dd            ZpddZqd ZrdddZsd Zt eju        d          Zvevw                    es           evx                    d             e"jy        evdd             e$jz        ev e$j{         eesde          d                      e$jz        ev e$j{         eesde          d          d           ete#j|        ev<   deVfd dZ}deVfd dZ~ eed          ddd            Z eedZ          dd            Z eedZ          dd            Z eedZ          dd            Zde8fddZdNeVfddZ eedYZ          dd            Z	 	 dddZdNeVfddZ eedYZ          dd            ZdNeVfddZ eedYZ          d             ZdeVfddZ eedZ          dd            ZdNeVfddZ eedZ          dd            ZdeVfddZ eedZ          dd            ZdeVfddZ eedzZ          dd            ZdNe8fd	dZ eedYZ          dd            ZdNeVfddZ eedYZ          dd            ZdNeVfd
dZ eedzZ          dd            ZdNeVfddZ eedzZ          dd            ZdNeVfddZdNeVfddÄZd?dNeVfddńZdeVfddƄZ eedZ          ddǄ            ZdeVfddȄZ eedZ          ddɄ            Zde8fddʄZ eedZ          dd˄            ZdeVfddτZ eeddeѦ          dd҄            Z eje        dӦ          deVfddՄZ eeddeѦ          ddք            Zdׄ Z eedudeѦ          d؄             Z eedudeѦ          dل             Z eedzdeѦ          ddڄ            ZdeVfddۄZ eju        dܦ          Z ej        e           ex                    d݄             e#j        e            e$jz        edބ            d߄ ZdS (      )annotations)HashableSequence)partialN)index)Union)lax)choleskysvdeigh)config)core)dispatch)dtypes)prng)
xla_bridge)jitvmap)ad)batching)mlir)_convert_and_clip_integer)
_arraylikecheck_arraylikepromote_dtypes_inexact)Array	ArrayLike	DTypeLike)canonicalize_axisxr   returnr   c                ,    t          j        | |           S N)r	   ner    s    O/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/random.py_isnanr'   D   s    	1    Fallow_batchednamestrkeyKeyArrayLiker*   booltuple[KeyArray, bool]c                  t          |t                    r)t          j        |j        t          j                  r|}d}nt          |          rt          j        |t                                }d}t          j        j        dk    rt          d          t          j        j        dk    rt          j        dd           nKt          j        j        rt          j        d	t"                     nt%          d
t'          |                     |s.|j        r't          |  dt+          j        |           d          ||fS )NFimplTerrorzLegacy uint32 key array passed as key to jax.random function. Please create keys using jax.random.key(). If use of a raw key array was intended, set jax_legacy_prng_key="allow".warn   )
stacklevelzjRaw arrays as random keys to jax.random functions are deprecated. Assuming valid threefry2x32 key for now.zunexpected PRNG key type z: accepts a single key, but was given a key array of shape " != (). Use jax.vmap for batching.)
isinstancer   r   
issubdtypedtypeprng_keyr   r   random_wrapdefault_prng_implr   legacy_prng_keyvalue
ValueErrorwarningsr5   enable_custom_prngFutureWarning	TypeErrortypendimnpshape)r+   r-   r*   wrapped_keywrappeds        r&   _check_prng_keyrL   H   sz   U = 1#)V_ M M =KGG# ="3->-@-@AAAKG#w..	9: : : 
		%	/	/m	9EFH H H H H 
	"	( m5
  
 ;S		;;
<
<<
 R[- R
 Q Q!x}}Q Q Q R R R 
g	r(   c                    t          j        |j        t          j                  sJ t
          j        j        r|S | rt          j	        |          n|S r#   )
jnpr:   r;   r   r<   r   rC   r@   r   random_unwrap)was_wrappedr-   s     r&   _return_prng_keysrQ   k   sL    		6?	3	3333$ ;J&1:4c"""s:r(   KeyArray	bit_widthintrI   Shapec                |    t          j        | j        t          j                  sJ t          j        | ||          S )N)rS   rI   )rN   r:   r;   r   r<   r   random_bits)r-   rS   rI   s      r&   _random_bitsrX   t   s6    		6?	3	3333		#%	@	@	@@r(   c                 x    t           j        j        } | t          j        v s
J |             t          j        |          S )zGet the default PRNG implementation.

  The default implementation is determined by ``config.jax_default_prng_impl``,
  which specifies it by name.
  )r   r>   r@   r   prngs)	impl_names    r&   r>   r>   {   s7     &,)	dj	 	 	 )	 	 	 	I	r(   c                  B    e Zd ZU dZdgZded<   d ZddZdd	ZddZ	dS )PRNGSpecz$Specifies a PRNG key implementation._implPRNGImplc                    || _         d S r#   r^   )selfr3   s     r&   __init__zPRNGSpec.__init__   s    DJJJr(   r!   r,   c                *    t          | j                  S r#   )r,   r^   rb   s    r&   __str__zPRNGSpec.__str__   s    C
OO3r(   rT   c                *    t          | j                  S r#   )hashr^   re   s    r&   __hash__zPRNGSpec.__hash__   s    D$4$44r(   r/   c                "    | j         |j         k    S r#   ra   )rb   others     r&   __eq__zPRNGSpec.__eq__   s    :$$r(   N)r!   r,   )r!   rT   )r!   r/   )
__name__
__module____qualname____doc__	__slots____annotations__rc   rf   ri   rl    r(   r&   r]   r]      si         ,,i)///   43334444% % % % % %r(   r]   	impl_specPRNGSpecDesc | Noner_   c                   | t                      S t          |           t          u r| S t          |           t          u r| j        S t          |           t
          u rq| t          j        v rt          j        |          S d                    d t          j        	                                D                       }t          d|  d| d          t          |           }t          d| d          )Nz, c              3  "   K   | ]
}d | d V  dS )"Nrs   ).0ss     r&   	<genexpr>z$resolve_prng_impl.<locals>.<genexpr>   s*      ==aQ======r(   z"unrecognized PRNG implementation "z". Did you mean one of: ?zunrecognized type z$ for specifying PRNG implementation.)r>   rF   r_   r]   r^   r,   r   rZ   joinkeysrA   rE   )rt   keys_fmtts      r&   resolve_prng_implr      s    	)__  
 	)__  ?	)__DJZ	""yy==4:??+<+<=====H
 9) 9 9-59 9 9 : : : 9oo!NqNNNOOOr(   	ctor_nameseedint | ArrayLikec                N   t          |          }t          |d          r6t          j        |j        t
          j                  rt          |  d          t          j	        |          r't          |  dt          j
        |           d          t          j        ||          S )Nr;   z1 accepts a scalar seed, but was given a PRNG key.z8 accepts a scalar seed, but was given an array of shape z! != (). Use jax.vmap for batchingr2   )r   hasattrrN   r:   r;   r   r<   rE   rH   rG   rI   r   random_seed)r   r   rt   r3   s       r&   _keyr      s    	9	%	%$T7 Itz6? K K I
GGGI I IWT]] D
 	C 	C$	C 	C 	CD D D 
	$T	*	*	**r(   r2   r3   c               $    t          d| |          S )a0  Create a pseudo-random number generator (PRNG) key given an integer seed.

  The result is a scalar array with a key that indicates the default PRNG
  implementation, as determined by the optional ``impl`` argument or,
  otherwise, by the ``jax_default_prng_impl`` config flag.

  Args:
    seed: a 64- or 32-bit integer used as the value of the key.
    impl: optional string specifying the PRNG implementation (e.g.
      ``'threefry2x32'``)

  Returns:
    A scalar PRNG key array, consumable by random functions as well as ``split``
    and ``fold_in``.
  r-   )r   r   r3   s     r&   r-   r-      s    " 
eT4	 	  r(   c               @    t          dt          d| |                    S )a  Create a pseudo-random number generator (PRNG) key given an integer seed.

  The resulting key carries the default PRNG implementation, as
  determined by the optional ``impl`` argument or, otherwise, by the
  ``jax_default_prng_impl`` config flag.

  Args:
    seed: a 64- or 32-bit integer used as the value of the key.
    impl: optional string specifying the PRNG implementation (e.g.
      ``'threefry2x32'``)

  Returns:
    A PRNG key, consumable by random functions as well as ``split``
    and ``fold_in``.
  TPRNGKey)rQ   r   r   s     r&   r   r      s     " 
4it!<!<	=	==r(   dataIntegerArrayc                   t          d|           \  } }t          j        |          r%t          dt          j        |           d          t          j        | t          j        |                    }t          ||          S )ac  Folds in data to a PRNG key to form a new PRNG key.

  Args:
    key: a PRNG key (from ``key``, ``split``, ``fold_in``).
    data: a 32-bit integer representing data to be folded into the key.

  Returns:
    A new PRNG key that is a deterministic function of the inputs and is
    statistically safe for producing a stream of new pseudo-random values.
  fold_inz9fold_in accepts a scalar, but was given an array ofshape r8   )
rL   rH   rG   rE   rI   r   random_fold_inrN   uint32rQ   )r-   r   rK   key_outs       r&   r   r      s     !C00,#wWT]] Q
 PXd^^P P P Q Q QSZ%5%566'	7G	,	,,r(   r6   numint | tuple[int, ...]c                   t          j        | j        t          j                  sJ | j        rt          d| j         d          t          |t                    rt          |          n|f}t          j        | |          S )Nz?split accepts a single key, but was given a key array of shape r8   rI   )rN   r:   r;   r   r<   rG   rE   rI   r9   r   tupler   random_split)r-   r   rI   s      r&   _splitr      s     
	6?	3	3333X L
 K YK K K L L L"311
=%***v%		3e	,	,	,,r(   c                d    t          d|           \  }}t          |t          ||                    S )aK  Splits a PRNG key into `num` new keys by adding a leading axis.

  Args:
    key: a PRNG key (from ``key``, ``split``, ``fold_in``).
    num: optional, a positive integer (or tuple of integers) indicating
      the number (or shape) of keys to produce. Defaults to 2.

  Returns:
    An array-like object of `num` new PRNG keys.
  split)rL   rQ   r   )r-   r   	typed_keyrK   s       r&   r   r   	  s2     'w44)W	7F9c$:$:	;	;;r(   r~   c                    t          j        | j        t          j                  sJ t          j        t          j        | j                  }|j	        S r#   )
rN   r:   r;   r   r<   typingcastr   KeyTyr^   )r~   
keys_dtypes     r&   	_key_implr     s<    	
FO	4	4444{4:tz22*		r(   r   c                d    t          d| d          \  }}t          t          |                    S )Nkey_implTr)   )rL   r]   r   )r~   
typed_keys_s      r&   r   r     s0    !*d$GGG-*a	)J''	(	((r(   c                v    t          j        | j        t          j                  sJ t          j        |           S r#   )rN   r:   r;   r   r<   r   rO   )r~   s    r&   	_key_datar   "  s/    	
FO	4	4444		D	!	!!r(   c                J    t          d| d          \  } }t          |           S )z9Recover the bits of key data underlying a PRNG key array.key_dataTr)   )rL   r   )r~   r   s     r&   r   r   &  s&    JDAAA'$	4r(   key_bits_arrayc               L    t          |          }t          j        | |          S )a  Wrap an array of key data bits into a PRNG key array.

  Args:
    key_bits_array: a ``uint32`` array with trailing shape corresponding to
      the key shape of the PRNG implementation specified by ``impl``.
    impl: optional, specifies a PRNG implementation, as in ``random.key``.

  Returns:
    A PRNG key array, whose dtype is a subdtype of ``jax.dtypes.prng_key``
      corresponding to ``impl``, and whose shape equals the leading shape
      of ``key_bits_array.shape`` up to the key bit dimensions.
  r2   )r   r   r=   )r   r3   impl_objs      r&   wrap_key_datar   ,  s'     t$$(		.x	8	8	88r(   Nonec                    |r>t          j        |g|R  }||k    r(d}t          |                    | ||                    d S d S )Nz{} parameter shapes must be broadcast-compatible with shape argument, and the result of broadcasting the shapes must equal the shape argument, but got result {} for shape argument {}.)r	   broadcast_shapesrA   format)r+   rI   param_shapesshape_msgs        r&   _check_shaper   A  sb     8!%7,777FLc szz$667778 8r(   rs   r;   DTypeLikeUInt | Nonec                z   t          d|           \  } }|t          j        t          j                  }nt          j        |           t          j        |t          j                  st          d|           t          j        |          }t          j        |          }|j        dz  }t          | ||          S )a  Sample uniform bits in the form of unsigned integers.

  Args:
    key: a PRNG key used as the random key.
    shape: optional, a tuple of nonnegative integers representing the result
      shape. Default ``()``.
    dtype: optional, an unsigned integer dtype for the returned values (default
      ``uint64`` if ``jax_enable_x64`` is true, otherwise ``uint32``).

  Returns:
    A random array with the specified shape and dtype.
  bitsNz<dtype argument to `bits` must be an unsigned int dtype, got    )rL   r   canonicalize_dtyperN   uintcheck_user_dtype_supportedr:   rH   unsignedintegerrA   r   canonicalize_shapeitemsizerX   )r-   rI   r;   r   rS   s        r&   r   r   K  s     63''&#q
]%ch//EE
%e,,,		5""4	5	5 %
 $!$ $ % % %

#E
*
*%

!%
(
(%nq )	c9e	,	,,r(                 ?DTypeLikeFloatminval	RealArraymaxvalc                (   t          d|           \  } }t          j        |           t          j        |          }t          j        |t          j                  st          d|           t          j	        |          }t          | ||||          S )a  Sample uniform random values in [minval, maxval) with given shape/dtype.

  Args:
    key: a PRNG key used as the random key.
    shape: optional, a tuple of nonnegative integers representing the result
      shape. Default ().
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).
    minval: optional, a minimum (inclusive) value broadcast-compatible with shape for the range (default 0).
    maxval: optional, a maximum (exclusive) value broadcast-compatible with shape for the range (default 1).

  Returns:
    A random array with the specified shape and dtype.
  uniformz7dtype argument to `uniform` must be a float dtype, got )rL   r   r   r   r   r:   rH   floatingrA   r   _uniform)r-   rI   r;   r   r   r   s         r&   r   r   h  s    & 9c**&#q#E***

!%
(
(%		5"+	.	. %
 $!$ $ % % %

#E
*
*%	#ueVV	4	44r(   )   r6   )static_argnumsc           	        t          d|           t          j        |t          j                  st          d          t          j        ||          }t          j        ||          }t          j        |t          |                    }t          j        |t          |                    }t          j
        |          }|j        |j        }}|dvrt          d| d          |}|dk     rd}t          | ||          }	t          |         }
||k    rt          j        |	|
          }	t          j        t          j        |	t          j        ||z
  |
                    t          j        d|                              |
                    }t          j        ||          t          j        d|          z
  }t          j        |t          j        |||z
  z  |z   |                    S )Nr   z+uniform only accepts floating point dtypes.r          @   z7uniform only accepts 8-, 16-, 32-, or 64-bit dtypesgot .r   r   )r   rN   r:   rH   r   rE   r	   convert_element_typebroadcast_to_ranklenfinfor   nmantrX   UINT_DTYPES
bitwise_orshift_right_logicalarrayviewbitcast_convert_typemaxreshape)r-   rI   r;   r   r   r   nbitsr   rng_bitsr   
uint_dtype
float_bitsfloatss                r&   r   r     s   y%   	r{	+	+ C
A
B
BB#FE22&#FE22& U44& U44&
)E

%U[%
/!!
J%JJJ   (
QYYH	c8U	+	+$5!*#D*55D ~	dBHX-=z$J$JKKhsE
++ * #J66"e9L9LL&		k&FVO,v5u==
? 
? ?r(   DTypeLikeIntc                    t          d|           \  } }t          j        |           t          j        |          }t	          j        |          }t          | ||||          S )ap  Sample uniform random values in [minval, maxval) with given shape/dtype.

  Args:
    key: a PRNG key used as the random key.
    shape: a tuple of nonnegative integers representing the shape.
    minval: int or array of ints broadcast-compatible with ``shape``, a minimum
      (inclusive) value for the range.
    maxval: int or array of ints broadcast-compatible with ``shape``, a maximum
      (exclusive) value for the range.
    dtype: optional, an int dtype for the returned values (default int64 if
      jax_enable_x64 is true, otherwise int32).

  Returns:
    A random array with the specified shape and dtype.
  randint)rL   r   r   r   r   r   _randint)r-   rI   r   r   r;   r   s         r&   r   r     s^    ( 9c**&#q#E***

#E
*
*%

!%
(
(%	#uffe	4	44r(   )r      c           
     <   t          dt          j        |          t          j        |                     t          j        |t          j                  st          d|           t          d||           t          j        |          }t          j        |          }t          j        |j	        t          j                  s|
                    t                    }t          j        |j	        t          j                  s|
                    t                    }t          j        |t          t          j        t          j        |          j        |          |j	                            }t          ||          }t          ||          }t          j        |t'                              }t          j        |t'                              }t          j        |          j        dvrt          d|           t+          |           \  }}fd} ||           ||          }
}	t,                   }t          j        ||z
  |          }t          j        ||k    t          j        |d          |          }t          j        |||k    z  t          j        |t7          |d                    |          }t          j        t7          |ddz  z            |          }t          j        t          j        ||          |          }t          j        t          j        t          j        |	|          |          t          j        |
|                    }t          j        ||          }t          j        |t          j        ||                    S )Nr   z)randint only accepts integer dtypes, got r   z9randint only accepts 8-, 16-, 32-, or 64-bit dtypes, got c                &    t          |           S r#   )rX   )r-   r   rI   s    r&   <lambda>z_randint.<locals>.<lambda>  s    l3u55 r(   r   r6   )r   rH   rI   rN   r:   integerrE   r   asarrayr;   astyperT   r	   gtr   r   iinfor   r   r   r   r   r   r   select	full_likeadd
_lax_constremmul)r-   rI   r   r   r;   maxval_out_of_rangek1k2rbitshigher_bits
lower_bitsunsigned_dtypespan
multiplierrandom_offsetr   s    `             @r&   r   r     s   y%&!1!128F3C3CDDD	rz	*	* I
GGG
H
HH)VV,,,;v&;v&	bj	1	1  ]]3F	bj	1	1  ]]3F 
%ci	%0@0@0De&L&Lfl[[] ] %VU33&$VU33& U44& U44&
)E


%
/!!
WPUWW
X
XX
 #;;&"b
5
5
5
5
5%!E"IIuuRyyz+u%.		!&6/>	B	B$ 
Ff$cmD!&<&<d	C	C$
 
6F?+GD*T1%%&&

 

$ wz$eqj(9::DAA*wswz:66==*'#'#'+t"<"<jII'*d335 5-'-..-	1-GG	H	HHr(   axisindependentc                   t          d|           \  } }t          d|           t          |t          j        |          pd          }t          j        |          s~t          j        t          j        |          t          j                  st          d          t          j        t          |d          }t          | t          j        |          |          S |st          j        |          dk    rt          | ||          S t          | t          j        |j        |                   d          }t          j        |||d          S )a  Returns a randomly permuted array or range.

  Args:
    key: a PRNG key used as the random key.
    x: int or array. If x is an integer, randomly shuffle np.arange(x).
      If x is an array, randomly shuffle its elements.
    axis: int, optional. The axis which x is shuffled along. Default is 0.
    independent: bool, optional. If set to True, each individual vector along
      the given axis is shuffled independently. Default is False.

  Returns:
    A shuffled version of x or array range
  permutationr   z.x must be an integer or at least 1-dimensionalz&argument x of jax.random.permutation()r   T)unique_indices)rL   r   r   rH   rG   r:   r	   r;   r   rE   r   concrete_or_errorrT   _shufflerN   arangerI   take)r-   r    r  r  r   rinds          r&   r  r    s   " =#..&#q-###	4q	1	1$	 .=1rz22 HFGGGsA'OPPACA--- "BGAJJ!OOCD!!!cj//33#	!S$t	4	4	44r(   )r6   c                   d}t          j        t          j                  j        }t          t          j        |t          j        t	          d|j                            z  t          j        |          z                      }t          |          D ]C}t          |           \  } }t          |d|j                  }t          j        |||          \  }}D|S )N   r   r   )rN   r   rH   r   r   rT   ceillogsizeranger   rX   rI   r	   sort_key_val)	r-   r    r  exponent	uint32max
num_roundsr   subkey	sort_keyss	            r&   r	  r	  &  s      (i	""&)278bfSAF^^&<&<<rvi?P?PPQQRR* 0 0a++KCVR11IIq$//DAqq	
(r(   TareplacepRealArray | Nonec                   t          d|           \  } }t          |t                    st          d|           t	          d|           t          j        |          }|j        dk    rt          j	        t          |d          }n"t          ||j                  }|j        |         }t          j        |          }	|	dk    rt          j        ||j                  S |dk    rt#          d          |s|	|k    rt#          d          ||r7t%          | |d|          }
|j        dk    r|
nt          j        ||
|          }nZt)          d          f|z  t)          |	          fz   }t+          | |j        dk    r|n||          |         }nt	          d|           t-          |          \  }|j        |fk    rt#          d	          |ret          j        |          }|d
         dt1          | ||j                  z
  z  }t          j        ||                              t                    }
nJt7          | |f|j                   t          j        |          z
  }t          j        |          d|	         }
|j        dk    r|
nt          j        ||
|          }|                    |j        dk    r|n-t?          j         t?          j!        |j        |          ||                    S )a|  Generates a random sample from a given array.

  .. warning::
    If ``p`` has fewer non-zero elements than the requested number of samples,
    as specified in ``shape``, and ``replace=False``, the output of this
    function is ill-defined. Please make sure to use appropriate inputs.

  Args:
    key: a PRNG key used as the random key.
    a : array or int. If an ndarray, a random sample is generated from
      its elements. If an int, the random sample is generated as if a were
      arange(a).
    shape : tuple of ints, optional. Output shape.  If the given shape is,
      e.g., ``(m, n)``, then ``m * n`` samples are drawn.  Default is (),
      in which case a single value is returned.
    replace : boolean.  Whether the sample is with or without replacement.
      Default is True.
    p : 1-D array-like, The probabilities associated with each entry in a.
      If not given the sample assumes a uniform distribution over all
      entries in a.
    axis: int, optional. The axis along which the selection is performed.
      The default, 0, selects by row.

  Returns:
    An array of shape `shape` containing samples from `a`.
  choicez<shape argument of jax.random.choice must be a sequence, got r   z)The error occurred in jax.random.choice()r;   z4a must be greater than 0 unless no samples are takenz@Cannot take a larger sample than population when 'replace=False'Nz&p must be None or match the shape of ar   )"rL   r9   r   rE   r   rN   r   rG   r   r  rT   r   rI   mathprodzerosr;   rA   r   r  slicer  r   cumsumr   searchsortedr   gumbelr  argsortr   rH   insertdelete)r-   r  rI   r  r  r  r   arrn_inputsn_drawsr  resultslicesp_arrp_cumlr  gs                    r&   r  r  B  s   @ 8S))&#q	E8	$	$ $
 # # # $ $ $(AA#X]]%c1.YZZHHT38,,DyHIe'\\9U#),,,,]]
K
L
LL	 YWx''
W
X
XXY RC8,,ch!mmss#sD)A)Affd~$g'88f3CHMMsDII&QffHa   #A&&FE{xk!!?@@@ %z%  f
*GCflCCCC
DaVQ''..s33cc #{%+666
6
GaKNN8G8$cHMMSSsxS$'?'?F	Q	")CIt"<"<dEJJ
L 
L Lr(   c                $   t          d|           \  } }t          j        |          }t          j        |           t          j        |t          j                  st          d|           t          j	        |          }t          | ||          S )aY  Sample standard normal random values with given shape and float dtype.

  The values are returned according to the probability density function:

  .. math::
     f(x) = \frac{1}{\sqrt{2\pi}}e^{-x^2/2}

  on the domain :math:`-\infty < x < \infty`

  Args:
    key: a PRNG key used as the random key.
    shape: optional, a tuple of nonnegative integers representing the result
      shape. Default ().
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified shape and dtype.
  normalzAdtype argument to `normal` must be a float or complex dtype, got )rL   r   r   r   r   r:   rH   inexactrA   r   _normalr-   rI   r;   r   s       r&   r5  r5    s    , 8S))&#q

!%
(
(%#E***		5"*	-	- %
 $!$ $ % % %

#E
*
*%	eU	#	##r(   c                   t          j        |t          j                  rt          j        t          j        d          |          }t          |           \  }}t          j        d|          j        j        }t          |||          
                    |          }t          |||          
                    |          }|d|z  z   |z  S t          | ||          S )Nr6   r   y              ?)r   r:   rH   complexfloatingr   sqrtr   realr;   _normal_realr   )	r-   rI   r;   sqrt2key_rekey_im
real_dtype_re_ims	            r&   r7  r7    s    ub011 	+HRWQZZ''EC[[NFF!U##(.J
vuj
1
1
8
8
?
?C
vuj
1
1
8
8
?
?C"s(Ne##UE***r(   c                   t          d|           t          j        t          j        d|          t          j        d|          |          }t          j        d|          }t	          | ||||          }t          j        t          j        t          j        d          |          t          j        |                    S )Nr5        r   r   r   r6   )	r   rH   	nextafterr   r   r	   r   r;  erf_inv)r-   rI   r;   lohius         r&   r=  r=    s    x	|BHS%(("(2u*=*=UKKK"	xE"c5%R((!	"'!**e,,ck!nn	=	==r(   r
   meancovShape | NoneDTypeLikeFloat | Nonemethodc                d   t          d|           \  } }t          j        |           t          ||          \  }}|dvrt	          d          ||j        }t          j        |t          j                  st	          d|           |t          j
        |          }t          | |||||          S )a0  Sample multivariate normal random values with given mean and covariance.

  The values are returned according to the probability density function:

  .. math::
     f(x;\mu, \Sigma) = (2\pi)^{-k/2} \det(\Sigma)^{-1}e^{-\frac{1}{2}(x - \mu)^T \Sigma^{-1} (x - \mu)}

  where :math:`k` is the dimension, :math:`\mu` is the mean (given by ``mean``) and
  :math:`\Sigma` is the covariance matrix (given by ``cov``).

  Args:
    key: a PRNG key used as the random key.
    mean: a mean vector of shape ``(..., n)``.
    cov: a positive definite covariance matrix of shape ``(..., n, n)``. The
      batch shape ``...`` must be broadcast-compatible with that of ``mean``.
    shape: optional, a tuple of nonnegative integers specifying the result
      batch shape; that is, the prefix of the result shape excluding the last
      axis. Must be broadcast-compatible with ``mean.shape[:-1]`` and
      ``cov.shape[:-2]``. The default (None) produces a result batch shape by
      broadcasting together the batch shapes of ``mean`` and ``cov``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).
    method: optional, a method to compute the factor of ``cov``.
      Must be one of 'svd', 'eigh', and 'cholesky'. Default 'cholesky'. For
      singular covariance matrices, use 'svd' or 'eigh'.
  Returns:
    A random array with the specified dtype and shape given by
    ``shape + mean.shape[-1:]`` if ``shape`` is not None, or else
    ``broadcast_shapes(mean.shape[:-1], cov.shape[:-2]) + mean.shape[-1:]``.
  multivariate_normal>   r   r   r
   z1method must be one of {'svd', 'eigh', 'cholesky'}NzCdtype argument to `multivariate_normal` must be a float dtype, got )rL   r   r   r   rA   r;   r:   rH   r   r   r   _multivariate_normal)r-   rK  rL  rI   r;   rO  r   s          r&   rQ  rQ    s    H 0#66&#q#E***$T3//)$...
H
I
II
]JE		5"+	.	. ,
 +#(+ + , , ,
#E**E	c4eUF	C	CCr(   )r  r      c                   t          j        |          dk    s6d}t          |                    t          j        |                              t          j        |          dk    s6d}t          |                    t          j        |                              |j        d         }t          j        |          dd          ||fk    r8d}t          |                    |t          j        |                              |0t          j        |j        d d         |j        d d                   }n,t          d	||j        d d         |j        d d                    |d
k    r6t          |          \  }}	}
|t          j
        |	dd d d f                   z  }nJ|dk    r5t          |          \  }}|t          j
        |dd d d f                   z  }nt          |          }t          | ||j        dd          z   |          }t          j        d          5  |t          j        d||          z   }d d d            n# 1 swxY w Y   |S )Nr   z@multivariate_normal requires mean.ndim >= 1, got mean.ndim == {}r6   z>multivariate_normal requires cov.ndim >= 2, got cov.ndim == {}r!  z^multivariate_normal requires cov.shape == (..., n, n) for n={n}, but got cov.shape == {shape}.)nrI   r5  r   .r   allowz...ij,...j->...i)rH   rG   rA   r   rI   r	   r   r   r   rN   r;  r   r
   r5  r   numpy_rank_promotioneinsum)r-   rK  rL  rI   r;   rO  r   rV  rJ  rz   r   factorwvnormal_samplesr/  s                   r&   rR  rR    s_   	!		
LC
SZZ..
/
//			
JC
SZZ--
.
..
jn!Xc]]233Aq6!!+C
SZZ!28C==Z99
:
::
] CRC#)CRC.AAEE5$*SbS/39SbS>BBBu__CIQ1!CqqqL/***FF#YYFQ!CqqqL/***FFc]]F#utz"##6>>."7++ K KCJ16>JJJFK K K K K K K K K K K K K K K	-s   II
Ilowerupperc                ,   |t          j        |          }t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j	        |          }t          | ||||          S )a  Sample truncated standard normal random values with given shape and dtype.

  The values are returned according to the probability density function:

  .. math::
     f(x) \propto e^{-x^2/2}

  on the domain :math:`\rm{lower} < x < \rm{upper}`.

  Args:
    key: a PRNG key used as the random key.
    lower: a float or array of floats representing the lower bound for
      truncation. Must be broadcast-compatible with ``upper``.
    upper: a float or array of floats representing the  upper bound for
      truncation. Must be broadcast-compatible with ``lower``.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``lower`` and ``upper``. The
      default (None) produces a result shape by broadcasting ``lower`` and
      ``upper``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and shape given by ``shape`` if
    ``shape`` is not None, or else by broadcasting ``lower`` and ``upper``.
    Returns values in the open interval ``(lower, upper)``.
  Ntruncated_normalz@dtype argument to `truncated_normal` must be a float dtype, got )r   r   rL   r   r   r:   rH   r   rA   r   _truncated_normal)r-   r^  r_  rI   r;   r   s         r&   ra  ra    s    @ #E**E-s33&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%	3ueU	;	;;r(   )r  r   c                   |:t          j        t          j        |          t          j        |                    }n6t	          d|t          j        |          t          j        |                     t          j        t          j        d          |          }t          j        ||          }t          j        ||          }t          j        ||z            }t          j        ||z            }t          j
        |t          j                  st          d          t          | ||||          }|t          j        |          z  }	t          j        |	t          j        t          j        |          t          j        t          j        |                    t          j        t          j        |          t          j        t          j         |                              S )Nra  r6   z4truncated_normal only accepts floating point dtypes.r   r   r   )r	   r   rH   rI   r   r   r;  r   erfrN   r:   r   rE   r   rG  cliprF  stop_gradientinf)
r-   r^  r_  rI   r;   r>  r  brJ  outs
             r&   rb  rb  A  sw   
] %"(5//BBEE#UBHUOORXe__MMM
(271::u
%
%%

"5%
0
0%

"5%
0
0%	geem!	geem!	r{	+	+ L
J
K
KKc5%!444!A# 
		mC%e,,bhrvU.K.K.KLL	mC%e,,bhwe.L.L.LMM
O 
O Or(         ?c                r   |t          j        |          }t          d|           \  } }t          j        t          j        |                    }t          j        |t          j
                  s$d}t          |                    |                    t          j        ||          }t          | ||          S )a	  Sample Bernoulli random values with given shape and mean.

  The values are distributed according to the probability mass function:

  .. math::
     f(k; p) = p^k(1 - p)^{1 - k}

  where :math:`k \in \{0, 1\}` and :math:`0 \le p \le 1`.

  Args:
    key: a PRNG key used as the random key.
    p: optional, a float or array of floats for the mean of the random
      variables. Must be broadcast-compatible with ``shape``. Default 0.5.
    shape: optional, a tuple of nonnegative integers representing the result
      shape. Must be broadcast-compatible with ``p.shape``. The default (None)
      produces a result shape equal to ``p.shape``.

  Returns:
    A random array with boolean dtype and shape given by ``shape`` if ``shape``
    is not None, or else ``p.shape``.
  N	bernoulliz=bernoulli probability `p` must have a floating dtype, got {}.)r   r   rL   r   r   r	   r;   rN   r:   rH   r   rE   r   r   
_bernoulli)r-   r  rI   r   r;   r   s         r&   rm  rm  Y  s    0 #E**E;,,&#q

#CIaLL
1
1%	r{	+	+ '
IC
CJJu%%
&
&&	q%((!	CE	"	""r(   c                    |t          j        |          }n#t          d|t          j        |                     t          | |t	          j        |                    |k     S )Nrm  )rH   rI   r   r   r	   r;   r-   r  rI   s      r&   rn  rn  {  sO    
]HQKKEEeRXa[[111	eSYq\\	*	*Q	..r(   ri  c                ,   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | ||||          S )a
  Sample Beta random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(x;a,b) \propto x^{a - 1}(1 - x)^{b - 1}

  on the domain :math:`0 \le x \le 1`.

  Args:
    key: a PRNG key used as the random key.
    a: a float or array of floats broadcast-compatible with ``shape``
      representing the first parameter "alpha".
    b: a float or array of floats broadcast-compatible with ``shape``
      representing the second parameter "beta".
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``a`` and ``b``. The default
      (None) produces a result shape by broadcasting ``a`` and ``b``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and shape given by ``shape`` if
    ``shape`` is not None, or else by broadcasting ``a`` and ``b``.
  betaz4dtype argument to `beta` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _beta)r-   r  ri  rI   r;   r   s         r&   rr  rr    s    < 63''&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	sAq%	'	''r(   c                   |:t          j        t          j        |          t          j        |                    }n6t	          d|t          j        |          t          j        |                     t          j        ||          }t          j        ||          }t          |           \  }}t          j        ||          }t          j        ||          }t          ||||          }t          ||||          }t          j
        ||          }	t          j        ||	z
            }
t          j        ||	z
            }|
|
|z   z  S )Nrr  )r	   r   rH   rI   r   r   r   rN   broadcast_tologgammar   exp)r-   r  ri  rI   r;   key_akey_blog_gamma_alog_gamma_blog_maxgamma_a_scaledgamma_b_scaleds               r&   rs  rs    s   
] !bhqkk::EERXa[[999	q%((!	q%((!,%	q%  !	q%  !5%00+5%00+GK--'7;011.7;011.	>N:	;;r(   c                $   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }t          j	        |          }t          | ||          S )aK  Sample Cauchy random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(x) \propto \frac{1}{x^2 + 1}

  on the domain :math:`-\infty < x < \infty`

  Args:
    key: a PRNG key used as the random key.
    shape: optional, a tuple of nonnegative integers representing the result
      shape. Default ().
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified shape and dtype.
  cauchyz6dtype argument to `cauchy` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _cauchyr8  s       r&   r  r    s    , 8S))&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%

!%
(
(%	eU	#	##r(   c                <   t          d|           t          | ||t          j        |          j        d          }t          |t          j                  }t          j	        t          j
        |t          j        |t          |d                                        S )Nr  r   rd  rk  )r   r   rN   r   epsr   rH   pir	   tanr   sub)r-   rI   r;   rJ  r  s        r&   r  r    sz    xc5%	%(8(8(<RHHH!!RU"	SWQ
1c(:(:;;<<	=	==r(   alphac                *   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | |||          S )a  Sample Dirichlet random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(\{x_i\}; \{\alpha_i\}) \propto \prod_{i=1}^k x_i^{\alpha_i - 1}

  Where :math:`k` is the dimension, and :math:`\{x_i\}` satisfies

  .. math::
     \sum_{i=1}^k x_i = 1

  and :math:`0 \le x_i \le 1` for all :math:`x_i`.

  Args:
    key: a PRNG key used as the random key.
    alpha: an array of shape ``(..., n)`` used as the concentration
      parameter of the random variables.
    shape: optional, a tuple of nonnegative integers specifying the result
      batch shape; that is, the prefix of the result shape excluding the last
      element of value ``n``. Must be broadcast-compatible with
      ``alpha.shape[:-1]``. The default (None) produces a result shape equal to
      ``alpha.shape``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and shape given by
    ``shape + (alpha.shape[-1],)`` if ``shape`` is not None, or else
    ``alpha.shape``.
  	dirichletz9dtype argument to `dirichlet` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   
_dirichlet)r-   r  rI   r;   r   s        r&   r  r    s    F ;,,&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	Cu	-	--r(   )r6   r  c                   t          j        |          dk    s6d}t          |                    t          j        |                              |t          j        |          d d         }n+t          d|t          j        |          d d                    t          j        ||          }t          | ||t          j        |          dd          z   |          }t          |d          S )Nr   z8dirichlet requires alpha.ndim >= 1, got alpha.ndim == {}r!  r  )
rH   rG   rA   r   rI   r   r	   r   rv  _softmax)r-   r  rI   r;   r   log_gamma_sampless         r&   r  r    s    	1		
DC
SZZ//
0
00
]HUOOCRC EEeRXe__SbS%9:::

"5%
0
0% sE528E??2333G+GOO	#R	(	((r(   c                ,   t          j        | j        t          j                  st          d| j                   t          j        | |d          }t          j        | t          j
        |          z
            }||                    |d          z  S )z7Utility to compute the softmax of x along a given axis.z+_softmax only accepts floating dtypes, got T)keepdims)r   r:   r;   rH   r   rE   rN   r   rw  r	   rg  sum)r    r  x_maxunnormalizeds       r&   r  r  )  s    		17BK	0	0 M
K!'KK
L
LL
'!TD
)
)
)%S.u55566,	(((==	==r(   c                $   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }t          j	        |          }t          | ||          S )a<  Sample Exponential random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(x) = e^{-x}

  on the domain :math:`0 \le x < \infty`.

  Args:
    key: a PRNG key used as the random key.
    shape: optional, a tuple of nonnegative integers representing the result
      shape. Default ().
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified shape and dtype.
  exponentialz;dtype argument to `exponential` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _exponentialr8  s       r&   r  r  2  s    , =#..&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%

!%
(
(%	c5%	(	((r(   c                    t          d|           t          | ||          }t          j        t          j        t          j        |                              S )Nr  )r   r   r	   neglog1pr-   rI   r;   rJ  s       r&   r  r  Q  sE    }e$$$c5%  !	371::&&	'	''r(   c                   t          |d          t          |d          t          |d          t          |d          t          |d          }t          |d          t          j        |          t          j        |          }|}t          j        ||t          j        |                    }t          j        ||          t          j        |t          j                            fd}fd}t          |           \  } }t          j
        ||| t          |d	          f          \  }	}	}
}	|rt          j        t          |d
                    }t          j        ||dk    z  t          j        |t          j        |                              }t          j        t          j        t          j                  t          j        |
                    |          S dt          |d
          z
  }t          j        |t          j        |t          j        |                              }t          j        t          j        |
          |          S )Nr   r   r!  rk  gUUUUUU?gm{?c                   | \  }}}}t          j        t          j        |t          j        t          j        	t          j        ||                                        t          j        t          j        |          t          j        t          j        |          t          j        t          j        t          j        |          t          j        |                                                            }|S r#   )r	   bitwise_andger  r   r  r   )
kXVUr   XVUconddoneone_over_twosqueeze_consts
         r&   _cond_fnz_gamma_one.<locals>._cond_fnu  s    JAq!Q ?36!SWS#'-QRTU2W2W%X%XYY6#'!**cgcga6N6N69gaQTVWILQRBU BU 7V 7V/W /W X XY YD Kr(   c                4   fd}| d         }t          |d          \  }}}t          j        fd||f          \  }}}t          j        ||          }t          j        t          j        ||          |          }	t	          |d          }
|||	|
fS )Nc                    | d         }t          |          \  }}t          |d          }t          j        t          j        |                    }|||fS )Nr   rs   r   )r   r5  r	   r   r   )kxvr-   r  r    r\  cr;   r  s        r&   	_next_kxvz/_gamma_one.<locals>._body_fn.<locals>._next_kxv  sV    Fc3KKkc6
5
)
)
)a
'#swq!}}
%
%a!QYr(   r   r  c                :    t          j        | d                   S )Nr6   )r	   le)r  zeros    r&   r   z._gamma_one.<locals>._body_fn.<locals>.<lambda>  s    A)=)= r(   rs   r   )r   r	   
while_loopr   r   )r  r  r-   x_keyU_keyr   r    r\  r  r  r  r  r;   	minus_oner  r  s              r&   _body_fnz_gamma_one.<locals>._body_fn  s           q'CsACn====y5RVXaJbccGAq!1A1q!!Ar'''A1a<r(   r6   rs   r   )r   r	   r;   r  r   r   r  divr;  r   r  r  r  r   r  r   pow)r-   r  	log_spaceone_over_three
boost_mask
alpha_origr  r  r  r   r  log_samples	log_boostsamplesboostr  r  r;   r  r  r  r  r  s                  @@@@@@@@r&   
_gamma_oner  Y  sX    
E1		$5!###)E3'',eW--.UF++-
)E

% veS!!**
*Zs(;(;
<
<%	ge^$$!	gnchqkk**!	 	 	 	 	 	 	 	        " s+#v~h3c:eUVCWCW2XYY*!Q1 )'+fb>>>??K
:)9:D#'+WZW^_bdnWoWoBpBpqqI737371::swqzz22I>>>'&"E2222GJz3j9Q9Q(R(RSSE7371a==%(((r(   c               p   t          j        | d          }t          j        |d          }|rt          j        |          }t	          j        | d          }t          j        |t          j        |j                  j	                  }t          j
        t          j        ||          ||          }d nt          j        t          j                    j        dk    rt          j        fd||f          }n t#                    ||          }|                    t%          j        |                    S )Nr!  r   c                2    t          j        | |          |z  S r#   )r	   random_gamma_grad)r  samples     r&   r   z_gamma_grad.<locals>.<lambda>  s    s'<UF'K'Kf'T r(   cpuc                     |  S r#   rs   )args
gamma_grads    r&   r   z_gamma_grad.<locals>.<lambda>  s    T!2 r(   )rN   r   r	   rw  lax_internal_constr   r   r;   tinyr   eqr  r   get_backendplatformmapr   rH   rI   )	r  r  r  r  alphasr  r  gradsr  s	           @r&   _gamma_gradr    s   K##';q"& 
' ggGvq))D=#)GM":":"?@@Dj..g>>GTTJJ&J&%//G2222VW4EFFEEDVW--E	rx{{	#	##r(   )use_vmapc                  t          j        |          }t          j        || j        d                    }|                                 } t          t          d          ||          }|                                }|                                }|rIt          |           t          j
        u r. t          t          t                              ||          }nt          j        fd||f          }t          j        ||          S )N)r   N)in_axesr  c                    t          | diS )Nr  )r  )r  r  s    r&   r   z_gamma_impl.<locals>.<lambda>  s    Z;;; r(   )rN   rI   r"  r#  rG   flattenr   r   r   r   threefry_prng_implr   r  r	   r  r   )	r-   r  r  r  a_shapesplit_countr~   r  r  s	     `      r&   _gamma_implr    s    IaLL'	'#()),--+	$	(fi	(	(	({	;	;$	$99;;& M)C..D$;;;<d7:;;;<<T6JJGGg;;;;dF^M MG 
Wg	&	&&r(   c                   | \  }}|\  }}t          d t          | |          D                       }t          j        |||          }t          j        |||          }t                              |||          dfS )Nc              3  :   K   | ]\  }}||j         |         V  d S r#   r   )ry   r   is      r&   r{   z'_gamma_batching_rule.<locals>.<genexpr>  s9       M MQamagajmmmmM Mr(   r  r   )nextzipr   bdim_at_frontrandom_gamma_pbind)batched_args
batch_dimsr  kr  bkbar  s           r&   _gamma_batching_ruler    s    	$!Q&"b	 M M z::M M M 
M 
M$QD))!QD))!			QY		7	7	::r(   random_gammac                *    t          j        |          S r#   )r   raise_to_shaped)r-   r  r   s      r&   r   r     s    T5I!5L5L r(   c                $    | t          ||fi |z  S r#   )r  )tangentansr-   r  kwdss        r&   r   r     s    ;sA3N3N3N3N)N r(   )multiple_resultsr  )r  c                ,   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | |||          S )a  Sample Gamma random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(x;a) \propto x^{a - 1} e^{-x}

  on the domain :math:`0 \le x < \infty`, with :math:`a > 0`.

  This is the standard gamma density, with a unit scale/rate parameter.
  Dividing the sample output by the rate is equivalent to sampling from
  *gamma(a, rate)*, and multiplying the sample output by the scale is equivalent
  to sampling from *gamma(a, scale)*.

  Args:
    key: a PRNG key used as the random key.
    a: a float or array of floats broadcast-compatible with ``shape``
      representing the parameter of the distribution.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``a``. The default (None)
      produces a result shape equal to ``a.shape``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape`` is not None, or else by ``a.shape``.

  See Also:
    loggamma : sample gamma values in log-space, which can provide improved
      accuracy for small values of ``a``.
  gamma5dtype argument to `gamma` must be a float dtype, got NrI   r;   rL   r   r   r:   rH   r   rA   r   r   r   _gammar-   r  rI   r;   r   s        r&   r  r    s    H 7C((&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	Qe5	1	1	11r(   c                .   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | |||d          S )aV  Sample log-gamma random values with given shape and float dtype.

  This function is implemented such that the following will hold for a
  dtype-appropriate tolerance::

    np.testing.assert_allclose(jnp.exp(loggamma(*args)), gamma(*args), rtol=rtol)

  The benefit of log-gamma is that for samples very close to zero (which occur frequently
  when `a << 1`) sampling in log space provides better precision.

  Args:
    key: a PRNG key used as the random key.
    a: a float or array of floats broadcast-compatible with ``shape``
      representing the parameter of the distribution.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``a``. The default (None)
      produces a result shape equal to ``a.shape``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape`` is not None, or else by ``a.shape``.

  See Also:
    gamma : standard gamma sampler.
  rv  r  NTrI   r;   r  r  r  s        r&   rv  rv    s    > :s++&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	Qe5D	A	A	AAr(   r  )static_argnamesc                4   |t          j        |          }n#t          d|t          j        |                     t          j        ||          }t          j        |          |k    rt          j        ||          }t                              | ||          S )Nr  r  )	rH   rI   r   r	   r   rN   ru  r  r  )r-   r  rI   r;   r  s        r&   r  r  2  s    
]HQKKEE%!---	q%((!Xa[[EE""A			S!y		9	99r(   )r6   r  r   c                    fd}fd}t          j        d|          }t          j        dt          j                  }t          j        ||d|| |f          d         }	|	dz
                      |          S )Nc                    | \  }}}}t          |          \  }}t          j        | k    |dz   |          }t          |t          j                  }|dz   |||t          j        |          z   fS Nr   )r   r	   r   r   rH   float32rN   r  )	carryr  r  rnglog_prodr  rJ  lamrI   s	          r&   body_fnz_poisson_knuth.<locals>.body_fnE  sp    Aq#x++KC
8sd?AE1--Arz**Aq5!S(SWQZZ///r(   c                d    | d         | d         }}| k                                     |k     z  S )Nr   r  any)r  r  r  r  	max_iterss      r&   cond_fnz_poisson_knuth.<locals>.cond_fnL  s5    (E!HxAtO  ""a)m44r(   r   r   )r	   r   rH   r   r  r   )
r-   r  rI   r;   r	  r  r
  k_initlog_rate_initr  s
    `` `     r&   _poisson_knuthr  ?  s    0 0 0 0 0 05 5 5 5 5 5 =a..&-Q
E::-	nWg63'FGGJ!
a%		r(   c                  
 t          j                  ddt          j                  z  z   ddz  z   
dddz
  z  z   dd	d
z
  z  z
  
fd}fd}t          j        dj                  }t          j        dt
          j                  }t          j        ||d||| f          d         }	|	                    |          S )Ngn?=
ףp=@gh|?5g[	m?g$~?gr?g333333@gr鷯?gB>٬@r6   c                8   | \  }}}}t          |d          \  }}}t          |j                  dz
  }t          |j                  }dt          |          z
  }	t	          j        dz  |	z  z   |z  z   dz             }
t	          j        |z  |	|	z  z  z   z            } |
z  z   t	          j        |
dz             z
  }|	dk    |k    z  }|
dk     |	dk     ||	k    z  z  }||k    }|| |z  z  }t	          j        ||
|          }||z  }|dz   |||fS )	Nr  rk  r6   gQ?r   Q?r   g9v?)	r   r   r;   absr	   floorr  lgammar   )r  r  k_outacceptedr-   subkey_0subkey_1rJ  r\  	u_shiftedr  rz   r   accept1rejectaccept2acceptr  ri  	inv_alphar  log_lamrI   v_rs                    r&   r  z#_poisson_rejection.<locals>.body_fna  sN   #Auh$S!nnC8%++c1A%++Ac!ffI	1q59$q(A-3d:;;AIi)&;!<q!@ABBA	q7{SZA...AD Q#X.G!eU*q9}=>F1fG')*FJvq%((EHq5%3&&r(   c                J    | \  }}}}|                                  |k     z  S r#   r  )r  r  r  r  r-   r	  s        r&   r
  z#_poisson_rejection.<locals>.cond_fnw  s,    #AuhI??I..r(   r!  Fr   r   )	r	   r  r;  r   r;   rN   bool_r  r   )r-   r  rI   r;   r	  r  r
  r  r  r  r  ri  r  r  r   s    `` `     @@@@@r&   _poisson_rejectionr#  V  s   
 GCLL'dSXc]]""!w{!vS)))1q5!!#' ' ' ' ' ' ' ' ' ' ',/ / / / / =b#)U33&]3sy%88(	nWg68S'ABB1E!	
%r(   c                   t          |          |dk     z  }t          j        ||t          j        |d                    }t          j        |t          j        |d          |          }|                    t          j        |          j                  }t          j        |t          | ||||          t          | ||||                    }t          j        |dk    t          j
        |          |          S )N
   r   g     j@r   )r'   r	   r   r   rF   rN   r   r   r  r#  
zeros_like)	r-   r  rI   r;   	use_knuth	lam_knuthlam_rejectionr	  r/  s	            r&   _poissonr*    s     SkkS2X&)jCsC)@)@AA) *Yc3(?(?EE-jj5))-..):3	5%;;sM5%CC &
 
C1HcnV44f	=	==r(   r  c                   t          d|           \  } }t          j        |           t          j        t
          j        | j                  }|j        }|t
          j	        urt          d|           t          j        |          }|t          j        |          }nt          j        |          }t!          j        ||          }t%          j        |t          j                  }t+          | |||          S )a\  Sample Poisson random values with given shape and integer dtype.

  The values are distributed according to the probability mass function:

  .. math::
     f(k; \lambda) = \frac{\lambda^k e^{-\lambda}}{k!}

  Where `k` is a non-negative integer and :math:`\lambda > 0`.

  Args:
    key: a PRNG key used as the random key.
    lam: rate parameter (mean of the distribution), must be >= 0. Must be broadcast-compatible with ``shape``
    shape: optional, a tuple of nonnegative integers representing the result
      shape. Default (None) produces a result shape equal to ``lam.shape``.
    dtype: optional, a integer dtype for the returned values (default int64 if
      jax_enable_x64 is true, otherwise int32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape is not None, or else by ``lam.shape``.
  poissonz<`poisson` is only implemented for the threefry2x32 RNG, not )rL   r   r   r   r   r   r   r;   r^   r  NotImplementedErrorr   r   r   rH   rI   rN   ru  r	   r   r   r*  )r-   r  rI   r;   r   r   r   s          r&   r,  r,    s    2 9c**&#q#E*** {4:sy11*(T,,,
		 	   
#E
*
*%
#E**EEHSMMEe$$# bj11#	#sE5	)	))r(   c                $   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }t          j	        |          }t          | ||          S )a  Sample Gumbel random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(x) = e^{-(x + e^{-x})}

  Args:
    key: a PRNG key used as the random key.
    shape: optional, a tuple of nonnegative integers representing the result
      shape. Default ().
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified shape and dtype.
  r(  z6dtype argument to `gumbel` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _gumbelr8  s       r&   r(  r(    s    ( 8S))&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%

!%
(
(%	eU	#	##r(   c                    t          d|           t          j        t          j        t          | ||t          j        |          j        d                                S )Nr(  r   rd  )r   rN   r  r   r   r  r-   rI   r;   s      r&   r/  r/    sh    x
'37c5%	%(8(8(=bIIIK K K L L 
L Lr(   r!  logitsc                F   t          d|           \  } }t          d|           t          j        |          }|dk    r|t	          |j                  z  }t          t          j        |j        |                    }||}n%t          j
        |          }t          d||           |dt	          |          t	          |          z
           }t          |t	          |          t	          |          z
  d                   }|                    |t	          |j                  z  |j        |                    t          j        t          | g ||R |j                  t#          j        |t          t'          t	          |                                        z   |          S )a  Sample random values from categorical distributions.

  Args:
    key: a PRNG key used as the random key.
    logits: Unnormalized log probabilities of the categorical distribution(s) to sample from,
      so that `softmax(logits, axis)` gives the corresponding probabilities.
    axis: Axis along which logits belong to the same categorical distribution.
    shape: Optional, a tuple of nonnegative integers representing the result shape.
      Must be broadcast-compatible with ``np.delete(logits.shape, axis)``.
      The default (None) produces a result shape equal to ``np.delete(logits.shape, axis)``.

  Returns:
    A random array with int dtype and shape given by ``shape`` if ``shape``
    is not None, or else ``np.delete(logits.shape, axis)``.
  categoricalr   Nr  )rL   r   rN   r   r   rI   r   rH   r+  r   r   r   listr*  argmaxr(  r;   r	   expand_dimsr  )	r-   r2  r  rI   r   
logits_arrbatch_shapeshape_prefixlogits_shapes	            r&   r4  r4    s   & =#..&#q-((({6""*	QYYC
 !!!Dbi
 0$7788+
]EE#E**E{3333E

3{#3#3334,eCJJ[)9)99::;<<,dS!1222J4DT4JKKK	S0L0<00*2BCC	oj%c,.?.?(@(@"A"ABBC
 
 
 r(   c                $   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }t          j	        |          }t          | ||          S )a  Sample Laplace random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
    f(x) = \frac{1}{2}e^{-|x|}

  Args:
    key: a PRNG key used as the random key.
    shape: optional, a tuple of nonnegative integers representing the result
      shape. Default ().
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified shape and dtype.
  laplacez7dtype argument to `laplace` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _laplacer8  s       r&   r>  r>    s    ( 9c**&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%

!%
(
(%	#ue	$	$$r(   c           
     8   t          d|           t          | ||dt          j        |          j        z   d          }t          j        t          j        |          t          j        t          j	        t          j
        |                                        S )Nr>  rE  r   rd  )r   r   rN   r   epsnegr	   r   signr  r  r  r  s       r&   r?  r?  .  s|    y%   	5%ci&6&6&= =bJ J J!	!ci

(;(;<<	=	==r(   c                $   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }t          j	        |          }t          | ||          S )a%  Sample logistic random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(x) = \frac{e^{-x}}{(1 + e^{-x})^2}

  Args:
    key: a PRNG key used as the random key.
    shape: optional, a tuple of nonnegative integers representing the result
      shape. Default ().
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified shape and dtype.
  logisticz8dtype argument to `logistic` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   	_logisticr8  s       r&   rD  rD  6  s    ( :s++&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%

!%
(
(%	3u	%	%%r(   c                   t          d|           t          | ||t          j        |          j        d          }t          j        t          j        |t          j        t          |d          |                              S )NrD  r   rd  r   )
r   r   rN   r   r  r	   r  r  r  r   )r-   rI   r;   r    s       r&   rE  rE  S  si    z5!!!c5%	%(8(8(<RHHH!	CGJq!$4$4a8899	:	::r(   c                *   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | |||          S )a~  Sample Pareto random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(x; b) = b / x^{b + 1}

  on the domain :math:`1 \le x < \infty` with :math:`b > 0`

  Args:
    key: a PRNG key used as the random key.
    b: a float or array of floats broadcast-compatible with ``shape``
      representing the parameter of the distribution.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``b``. The default (None)
      produces a result shape equal to ``b.shape``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape`` is not None, or else by ``b.shape``.
  paretoz6dtype argument to `pareto` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _pareto)r-   ri  rI   r;   r   s        r&   rH  rH  Z  s    6 8S))&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	a	&	&&r(   c                    |t          j        |          }nt          d|           t          j        ||          }t          | ||          }t          j        ||z            S )NrH  )rH   rI   r   r	   r   r  rw  )r-   ri  rI   r;   es        r&   rI  rI    s[    
]HQKKEE5!!!	q%((!#ue$$!	Qr(   dfc                &   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }t          j	        |          }t          | |||          S )a  Sample Student's t random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(t; \nu) \propto \left(1 + \frac{t^2}{\nu}\right)^{-(\nu + 1)/2}

  Where :math:`\nu > 0` is the degrees of freedom, given by the parameter ``df``.

  Args:
    key: a PRNG key used as the random key.
    df: a float or array of floats broadcast-compatible with ``shape``
      representing the degrees of freedom parameter of the distribution.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``df``. The default (None)
      produces a result shape equal to ``df.shape``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape`` is not None, or else by ``df.shape``.
  r   z1dtype argument to `t` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _tr-   rL  rI   r;   r   s        r&   r   r     s    6 3$$&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%

!%
(
(%	CUE	"	""r(   c                   |t          j        |          }n#t          d|t          j        |                     t          j        ||          }t          |           \  }}t          |||          }t          |d          }t          j        ||          }t          ||||          }	|t          j        ||	z            z  S )Nr   r6   )rH   rI   r   r	   r   r   r5  r   r  r  rN   r;  )
r-   rL  rI   r;   key_nkey_grV  twohalf_dfr3  s
             r&   rN  rN    s    
]HRLLEEeRXb\\***
E**",%UE5!!!1a#GB'E7E5))!	
SXgk""	""r(   c                *   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | |||          S )a  Sample Chisquare random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(x; \nu) \propto x^{\nu/2 - 1}e^{-x/2}

  on the domain :math:`0 < x < \infty`, where :math:`\nu > 0` represents the
  degrees of freedom, given by the parameter ``df``.

  Args:
    key: a PRNG key used as the random key.
    df: a float or array of floats broadcast-compatible with ``shape``
      representing the parameter of the distribution.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``df``. The default (None)
      produces a result shape equal to ``df.shape``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape`` is not None, or else by ``df.shape``.
  	chisquarez9dtype argument to `chisquare` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   
_chisquarerO  s        r&   rV  rV    s    8 ;,,&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	CUE	*	**r(   c                b   |t          j        |          }n#t          d|t          j        |                     t          j        ||          }t          |d          }t          j        ||          }t          | |||          }t          j        t          j
        |          |          }|S )NrV  r6   )r  rI   r;   )rH   rI   r   r	   r   r   r  rv  r   rN   rw  )r-   rL  rI   r;   rS  rT  log_gchi2s           r&   rW  rW    s    
]HRLLEEeRXb\\222
E**"2q#GB'
3'e
<
<
<%		%	%$	+r(   dfnumdfdenc                ,   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | ||||          S )a-  Sample F-distribution random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
     f(x; \nu_1, \nu_2) \propto x^{\nu_1/2 - 1}\left(1 + \frac{\nu_1}{\nu_2}x\right)^{
      -(\nu_1 + \nu_2) / 2}

  on the domain :math:`0 < x < \infty`. Here :math:`\nu_1` is the degrees of
  freedom of the numerator (``dfnum``), and :math:`\nu_2` is the degrees of
  freedom of the denominator (``dfden``).

  Args:
    key: a PRNG key used as the random key.
    dfnum: a float or array of floats broadcast-compatible with ``shape``
      representing the numerator's ``df`` of the distribution.
    dfden: a float or array of floats broadcast-compatible with ``shape``
      representing the denominator's ``df`` of the distribution.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``dfnum`` and ``dfden``.
      The default (None) produces a result shape equal to ``dfnum.shape``,
      and ``dfden.shape``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape`` is not None, or else by ``df.shape``.
  fz1dtype argument to `f` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _f)r-   r[  r\  rI   r;   r   s         r&   r^  r^    s    D 3$$&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	Cue	,	,,r(   c                |   |:t          j        t          j        |          t          j        |                    }n6t	          d|t          j        |          t          j        |                     t          j        ||          }t          j        ||          }t          |           \  }}t          ||||          }t          ||||          }t          j	        ||          }t          j	        ||          }t          j
        ||          }	t          j
        ||          }
t          j
        |	|
          }|S )Nr^  )r	   r   rH   rI   r   r   r   rV  rN   ru  r  )r-   r[  r\  rI   r;   key_dfdkey_dfnchi2_dfnchi2_dfdr   denr^  s               r&   r_  r_    s   
]!"(5//28E??CCEEeRXe__bhuoo>>>

"5%
0
0%

"5%
0
0%C[['7wue44(wue44(

5%
(
(%

5%
(
(%%  #%  #	gc3!	
(r(   c                    t          d|           \  } }t          j        |           t          j        |          }t	          j        |          }t          | ||          S )a  Sample from a Rademacher distribution.

  The values are distributed according to the probability mass function:

  .. math::
     f(k) = \frac{1}{2}(\delta(k - 1) + \delta(k + 1))

  on the domain :math:`k \in \{-1, 1\}`, where :math:`\delta(x)` is the dirac delta function.

  Args:
    key: a PRNG key.
    shape: The shape of the returned samples. Default ().
    dtype: The type used for samples.

  Returns:
    A jnp.array of samples, of shape `shape`. Each element in the output has
    a 50% change of being 1 or -1.

  
rademacher)rL   r   r   r   r   r   _rademacherr8  s       r&   rg  rg  3  sZ    , <--&#q#E***

#E
*
*%

!%
(
(%	S%	'	''r(   c                    t          | d|                              |          }d|z  dz
                      |          S )Nrk  rp  r6   r   )rm  r   )r-   rI   r;   bernoulli_sampless       r&   rh  rh  P  sD    C3e<<<CCEJJ

!
#	+	+E	2	22r(   c                $   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }t          j	        |          }t          | ||          S )a  Sample from a one sided Maxwell distribution.

  The values are distributed according to the probability density function:

  .. math::
     f(x) \propto x^2 e^{-x^2 / 2}

  on the domain :math:`0 \le x < \infty`.

  Args:
    key: a PRNG key.
    shape: The shape of the returned samples.
    dtype: The type used for samples.

  Returns:
    A jnp.array of samples, of shape `shape`.

  maxwellz7dtype argument to `maxwell` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _maxwellr8  s       r&   rl  rl  V  s    . 9c**&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%

!%
(
(%	#ue	$	$$r(   c                r    |dz   }t          | ||          }t          j                            |d          S )N)r  r1  r!  r5  )r5  rN   linalgnorm)r-   rI   r;   norm_rvss       r&   rm  rm  w  s7    
$,%5666(		+	++r(   locscalec                (   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }t          j	        |          }t          | ||||          S )ar  Sample from a double sided Maxwell distribution.

  The values are distributed according to the probability density function:

  .. math::
     f(x;\mu,\sigma) \propto z^2 e^{-z^2 / 2}

  where :math:`z = (x - \mu) / \sigma`, with the center :math:`\mu` specified by
  ``loc`` and the scale :math:`\sigma` specified by ``scale``.

  Args:
    key: a PRNG key.
    loc: The location parameter of the distribution.
    scale: The scale parameter of the distribution.
    shape: The shape added to the parameters loc and scale broadcastable shape.
    dtype: The type used for samples.

  Returns:
    A jnp.array of samples.

  double_sided_maxwellzDdtype argument to `double_sided_maxwell` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _double_sided_maxwell)r-   rr  rs  rI   r;   r   s         r&   ru  ru  ~  s    4 1377&#q#E***		5"+	.	. -
 ,$), , - - -

#E
*
*%

!%
(
(%	sCu	=	==r(   c                ,   t          j        t          j        |          t          j        |                    }|s|}||z   }t	          |           \  }}t          |||          }t          |||          }	|	j        |j        k    sJ |	|z  |z  |z   S )Nr  )r	   r   rH   rI   r   rl  rg  )
r-   rr  rs  rI   r;   params_shapesmaxwell_keyrademacher_keymaxwell_rvsrandom_signs
             r&   rv  rv    s    &rx}}bhuooFF-	 E
-
% &s+~5>>>+>eDDD+		k/	/	/	/	/	{	"U	*S	00r(   concentrationc                (   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }t          j	        |          }t          | ||||          S )a~  Sample from a Weibull distribution.

  The values are distributed according to the probability density function:

  .. math::
     f(x;\sigma,c) \propto x^{c - 1} \exp(-(x / \sigma)^c)

  on the domain :math:`0 < x < \infty`, where :math:`c > 0` is the concentration
  parameter, and :math:`\sigma > 0` is the scale parameter.

  Args:
    key: a PRNG key.
    scale: The scale parameter of the distribution.
    concentration: The concentration parameter of the distribution.
    shape: The shape added to the parameters loc and scale broadcastable shape.
    dtype: The type used for samples.

  Returns:
    A jnp.array of samples.

  weibull_minz;dtype argument to `weibull_min` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _weibull_min)r-   rs  r}  rI   r;   r   s         r&   r  r    s    4 =#..&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%

!%
(
(%	c5-	>	>>r(   c                    t          | |dd|          }t          j        t          j        |            d|z            |z  S )Nr   r   )r-   rI   r   r   r;   r   )r   rN   powerr  )r-   rs  r}  rI   r;   random_uniforms         r&   r  r    sN    
U1Qe= = =. 
CI~o...M0A	B	BU	JJr(   rV  c                2   t          j        |          }t          d|           \  } }t          j        |           t          d|           t          j        t          |d          }t          | g |||R |          }t          j
                            |          \  }}t          j        |ddd          }t          j        |t          j        t          j        |t#          |                              |j                            dg                    S )a  Sample uniformly from the orthogonal group O(n).

  If the dtype is complex, sample uniformly from the unitary group U(n).

  Args:
    key: a PRNG key used as the random key.
    n: an integer indicating the resulting dimension.
    shape: optional, the batch dimensions of the result. Default ().
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array of shape `(*shape, n, n)` and specified dtype.
  
orthogonalz-The error occurred in jax.random.orthogonal()r   rU  r!  )r   r   rL   r   r   r   r  r   r5  rN   ro  qrdiagonalr	   r   r8  r  r  r   r;   )	r-   rV  rI   r;   r   zqr  r  s	            r&   r  r    s    ( 
!%
(
(%<--&#q#E***|U###
UA'VWW!S.E.1.a..%((!	q		$!Q	l1aR  !	COCGAs1vv}}QW/E/E$F$FMM	N	NNr(   floatc                0   t          j        |          }t          d|           \  } }t          j        |           t          d|           t          |           }t          |d         d|z  ||          }t          |d         ||          }||d|z  z  z  S )au  Sample from the generalized normal distribution.

  The values are returned according to the probability density function:

  .. math::
     f(x;p) \propto e^{-|x|^p}

  on the domain :math:`-\infty < x < \infty`, where :math:`p > 0` is the
  shape parameter.

  Args:
    key: a PRNG key used as the random key.
    p: a float representing the shape parameter.
    shape: optional, the batch dimensions of the result. Default ().
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified shape and dtype.
  generalized_normalr   r   )	r   r   rL   r   r   r   r   r  rg  )r-   r  rI   r;   r   r~   r3  r  s           r&   r  r    s    4 
!%
(
(%/55&#q#E***#U+++	s$DGQqS%''!a%''!	
Q1q5\	r(   r  c                   t          j        |          }t          d|           \  } }t          j        |           t          d|           t          j        t          |d          }t          |           \  }}t          ||g ||R |          }t          |||          }	|t          j        |          |z                      d          |	z   d|z  z  d         z  S )a$  Sample uniformly from the unit Lp ball.

  Reference: https://arxiv.org/abs/math/0503650.

  Args:
    key: a PRNG key used as the random key.
    d: a nonnegative int representing the dimensionality of the ball.
    p: a float representing the p parameter of the Lp norm.
    shape: optional, the batch dimensions of the result. Default ().
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array of shape `(*shape, d)` and specified dtype.
  ballz'The error occurred in jax.random.ball()r!  r   ).N)r   r   rL   r   r   r   r  r   r   r  r  rN   r  r  )
r-   r  r  rI   r;   r   r   r   r3  rK  s
             r&   r  r     s    , 
!%
(
(%63''&#q#E***vu
UA'PQQ!::&"bQ%U33!"eU##!	


a$$R((1,!a%8)D	DDr(   c                *   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | |||          S )a  Sample Rayleigh random values with given shape and float dtype.

  The values are returned according to the probability density function:

  .. math::
     f(x;\sigma) \propto xe^{-x^2/(2\sigma^2)}

  on the domain :math:`-\infty < x < \infty`, and where :math:`\sigma > 0` is the scale
  parameter of the distribution.

  Args:
    key: a PRNG key used as the random key.
    scale: a float or array of floats broadcast-compatible with ``shape``
      representing the parameter of the distribution.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``scale``. The default (None)
      produces a result shape equal to ``scale.shape``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape`` is not None, or else by ``scale.shape``.
  rayleighz8dtype argument to `rayleigh` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   	_rayleigh)r-   rs  rI   r;   r   s        r&   r  r  A  s    8 :s++&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	3ue	,	,,r(   c                   |t          j        |          }n#t          d|t          j        |                     t          | ||          }|                    |          }t          j        ||          }t          j        |          }t          |d          }t          j
        t          j        ||                    }t          j        ||          }|S )Nr  rU  )rH   rI   r   r   r   rN   ru  r	   r  r   r;  r   )	r-   rs  rI   r;   rJ  log_un_twosqrt_urays	            r&   r  r  g  s    
]HUOOEEUBHUOO444c5%  !
,,u

%

5%
(
(%
'!**%
UB

%8CGE5))**&v#	*r(   c                *   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | |||          S )a  Sample Wald random values with given shape and float dtype.

  The values are returned according to the probability density function:

  .. math::
     f(x;\mu) = \frac{1}{\sqrt{2\pi x^3}} \exp\left(-\frac{(x - \mu)^2}{2\mu^2 x}\right)

  on the domain :math:`-\infty < x < \infty`, and where :math:`\mu > 0` is the location
  parameter of the distribution.


  Args:
    key: a PRNG key used as the random key.
    mean: a float or array of floats broadcast-compatible with ``shape``
      representing the mean parameter of the distribution.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``mean``. The default
      (None) produces a result shape equal to ``np.shape(mean)``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape`` is not None, or else by ``mean.shape``.
  waldz4dtype argument to `wald` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _wald)r-   rK  rI   r;   r   s        r&   r  r  v  s    : 63''&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	sD%	'	''r(   c                   |t          j        |          }n#t          d|t          j        |                     t          | d          \  }}|                    |          }t          j        ||          }t          |||          }t          |||          }t          j
        |d          }t          j
        |d          }	t          j
        |d          }
t          j        d|z  |z  |
|	z  z             }||
|z  dz  z   |dz  |z  z
  }t          j        t          j        ||||z   z            ||
|z            }|S )Nr  r6   r   )rH   rI   r   r   r   rN   ru  r5  r   r	   integer_powr;  r   r  )r-   rK  rI   r;   r   r   r\  r  yy_sqmean_sq	sqrt_termr    r[  s                 r&   r  r    s*   
]Xd^^EE///#q>>&"b	U		$		$	&	&$R!b%!	oa!	A		$OD!$$'hq4x!|gn455)
Wq[1_tax)33!	jDD1H-..7Q;??!	
(r(   c                *   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | |||          S )ao  Sample Geometric random values with given shape and float dtype.

  The values are returned according to the probability mass function:

  .. math::
      f(k;p) = p(1-p)^{k-1}

  on the domain :math:`0 < p < 1`.

  Args:
    key: a PRNG key used as the random key.
    p: a float or array of floats broadcast-compatible with ``shape``
      representing the probability of success of an individual trial.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``p``. The default
      (None) produces a result shape equal to ``np.shape(p)``.
    dtype: optional, a int dtype for the returned values (default int64 if
      jax_enable_x64 is true, otherwise int32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape`` is not None, or else by ``p.shape``.
  	geometricz8dtype argument to `geometric` must be an int dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   
_geometric)r-   r  rI   r;   r   s        r&   r  r    s    6 ;,,&#q#E***		5"*	-	- ,
 +#(+ + , , ,

#E
*
*%
#E**E	CE5	)	))r(   c                   |t          j        |          }n#t          d|t          j        |                     t          d|           t	          |          \  }t          | ||j                  }t          j        |          }t          j	        |           }t          j        ||          }t          j        t          j        ||                    dz   }|                    |          S )Nr  r   )rH   rI   r   r   r   r   r;   r	   r  r  rN   ru  r  r  r   )r-   r  rI   r;   rJ  r  log_one_minus_pr3  s           r&   r  r    s    
]Xa[[EEeRXa[[111+q!!!a  "!c5!'""!
'!**%IqbMM/$_e<</	i//0014!	
%r(   leftmoderightc                .   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | |||||          S )a  Sample Triangular random values with given shape and float dtype.

  The values are returned according to the probability density function:

  .. math::
      f(x; a, b, c) = \frac{2}{c-a} \left\{ \begin{array}{ll} \frac{x-a}{b-a} & a \leq x \leq b \\ \frac{c-x}{c-b} & b \leq x \leq c \end{array} \right.

  on the domain :math:`a \leq x \leq c`.

  Args:
    key: a PRNG key used as the random key.
    left: a float or array of floats broadcast-compatible with ``shape``
      representing the lower limit parameter of the distribution.
    mode: a float or array of floats broadcast-compatible with ``shape``
      representing the peak value parameter of the distribution, value must
      fulfill the condition ``left <= mode <= right``.
    right: a float or array of floats broadcast-compatible with ``shape``
      representing the upper limit parameter of the distribution, must be
      larger than ``left``.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``left``,``mode`` and ``right``.
      The default (None) produces a result shape equal to ``left.shape``, ``mode.shape``
      and ``right.shape``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape`` if
    ``shape`` is not None, or else by ``left.shape``, ``mode.shape`` and ``right.shape``.
  
triangularz:dtype argument to `triangular` must be a float dtype, got )rL   r   r   r:   rH   r   rA   r   r   r   _triangular)r-   r  r  r  rI   r;   r   s          r&   r  r    s    H <--&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	S$eUE	:	::r(   )r   rS  )r   inlinec           	        |Mt          j        t          j        |          t          j        |          t          j        |                    }nIt	          d|t          j        |          t          j        |          t          j        |                     t          j        ||          }t          j        ||          }t          j        ||          }||z
  ||z
  z  }t          | ||          }|t          j        |||z
  z  ||z
  z            z   }|t          j        d|z
  ||z
  z  ||z
  z            z
  }	t          j	        ||k     ||	          }
|
S )Nr  r   )
r	   r   rH   rI   r   rN   ru  r   r;  r   )r-   r  r  r  rI   r;   fcrJ  out1out2tris              r&   r  r  	  s*    ]!"(4.."(4.."(5//RREEubhtnnbhtnnbhuooVVV		$	&	&$		$	&	&$

5%
(
(%t%"c5%  !	edl+td{;<<	<$	1q5UT\2edlCDD	D$
1r64&&#	*r(   r   sigmac                *   t          d|           \  } }t          j        |           t          j        |t          j                  st          d|           t          j        |          }|t          j	        |          }t          | |||          S )ac   Sample lognormal random values with given shape and float dtype.

  The values are distributed according to the probability density function:

  .. math::
      f(x) = \frac{1}{x\sqrt{2\pi\sigma^2}}\exp\left(-\frac{(\log x)^2}{2\sigma^2}\right)

  on the domain :math:`x > 0`.

  Args:
    key: a PRNG key used as the random key.
    sigma: a float or array of floats broadcast-compatible with ``shape`` representing
      the standard deviation of the underlying normal distribution. Default 1.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. The default (None) produces a result shape equal to ``()``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by ``shape``.
  	lognormalzDdtype argument to `lognormal` must be a float or complex dtype, got )rL   r   r   r:   rH   r6  rA   r   r   r   
_lognormal)r-   r  rI   r;   r   s        r&   r  r  %	  s    2 ;,,&#q#E***		5"*	-	- %
 $!$ $ % % %

#E
*
*%
#E**E	Cu	-	--r(   c                    |t          j        |          }n#t          d|t          j        |                     t          j        ||          }t          | ||          |z  }t          j        |          S )Nr  )rH   rI   r   rN   ru  r5  r	   rw  )r-   r  rI   r;   scaled_norms        r&   r  r  H	  sh    
]Xe__EEubhuoo666

5%
(
(%sE5))E1+			r(   c                6   t          j        g d| j                  }| dk    }t          j        d| d          } | dz   | dz   z  }ddd	|z  z
  |z  z
  | dz   z  }t          j        |           } t          j        ||t          j        |                    |          S )
N)
gW
ڼq?g;>*?g&W?gxb&J?g?QN?g{k?g^J.aM]?g?0{^R?gb?gCL?r   	   r   g      "@r   gUUUUUU?gllf?gJ?)rN   r   r;   r	   clampr  r   int32)r  stirling_tail_valsuse_tail_valueskp1sqapproxs        r&   _stirling_approx_tailr  S	  s    y   G   F/	iQ!q5QU
%	J$66%??AEJ&	ill!	O%7	!%Ev	N	NNr(   c                   t           j        j        r&t          j        j        t          j                  sJ t          j                   fd}fd}t          j	        dj                  }t          j	        dj                  }	d||	| f}
t          j
        |||
          d         }|dz
                      |          S )Nc                
   | \  }}}}t          |          \  }}t          j        |	k    |dz   |          }t          |j                  }t          j        t          j        |          
z            }||z   }|dz   |||fS r  )r   r	   r   r   r;   rN   r  r  )r  r  num_geomgeom_sumr-   r  num_geom_outrJ  geomcountlog1minusprobprobrI   s            r&   r  z$_binomial_inversion.<locals>.body_fnr	  s    !&Ax3**KFC:h%/AxHHLtz**A8CGAJJ.//D$Hq5,#--r(   c                b    | d         | d         }}|k                                     |k     z  S Nr   r6   r  )r  r  r  r  r	  s      r&   r
  z$_binomial_inversion.<locals>.cond_fn{	  s4    (E!HxA""$$I66r(   r   r   )r   enable_checksr@   rN   r:   r;   r   r  r	   r   r  r   )r-   r  r  rI   r;   r	  r  r
  num_geom_initgeom_sum_initr  r  r  s    ``` `      @r&   _binomial_inversionr  k	  s     4>$*cl33333)TE""-. . . . . . . .7 7 7 7 7 7 -aU;;--aU;;-m]C
0%	nWgu--a0!
a%		r(   c           
        t          j        z  dz
  z            }dd|z  z   ddz  z   dz  z   z  dz   dd	z  z
  dz
  z  d
dz  z   |z  t          j        dz   z            f
d}fd}t          j        dj                  }	d|	t          j        dt           j                  | f}
t          j        |||
          d         	                    |          S )Nr   gffffff?r  gEJYga+e?{Gz?rk  gq=
ףp?g@gp=
ף@gffffff@c                v  
 | \  }}}}t          |d          \  }}}t          |j                  }t          |j                  }|dz
  }dt          j        |          z
  }	|	dk    |k    z  }
t          j        dz  |	z  z   |z  z             }|dk     |k    z  }t          j        |z  |	|	z  z  z   z            }dz   t          j        dz   z
  dz   z  z            z  dz   t          j        z
  dz   |z
  dz   z            z  z   |dz   t          j        |z
  dz   z  |dz   z            z  z   t                    z   t          z
            z   t          |          z
  t          |z
            z
  }||k    }|
| |z  z  }t          j	        |||          }||z  }|dz   |||fS )Nr  rk  r  r6   r   r   )
r   r   r;   rN   r  r  r  r  r	   r   )r  r  r  r  r-   r  r  rJ  r\  usr  r  r  ubr  r  r  r  ri  r  r  mr  r  rI   r   s                   r&   r  z_btrs.<locals>.body_fn	  s   #Auh#CmmC8%,,A%,,A	CA	swqzz	BTza3h'G	1q52:>Q&*++A!eE	"FE	Q"r']Q./00A3w#'1q5Q%!)a-%89:::	cguqy1}Q?@@@A	
SCGAQ/1q59:::; 	a  ! 	eai((	)
 	a  ! 	eai(()  2gG')*FJvq%((EHq5%3&&r(   c                \    | d         | d         }}|                                  |k     z  S r  r  )r  r  r  r	  s      r&   r
  z_btrs.<locals>.cond_fn	  s/    (E!HxAI??I..r(   r!  r   F)
rN   r;  r  r	   r   r;   fullr"  r  r   )r-   r  r  rI   r;   r	  stddevr  r
  r  r  r  r  ri  r  r  r  r   s    ``` `     @@@@@@@r&   _btrsr  	  s`    8EDLAH-..&
TF]!
TD[(!dlS!sQw#
a$h!#'>V
#%	id"##!' ' ' ' ' ' ' ' ' ' ' ' ' '4/ / / / / =r4:u55&fchueSY77
=%	%	0	0	3	:	:5	A	AAr(   c                   |:t          j        t          j        |          t          j        |                    }n6t          d|t	          j        |          t	          j        |                     t          |          \  }t          j        ||j                  }t          j	        ||          }t          j	        ||          }|dk     }t          j
        ||d|z
            }t          |          |dk     z  }t          j        |          }t          |          }	|dk     }
t          j
        |	|
z  t          j        |d          |          }|||z  dk    z  }t          j        |          }t          j
        ||t          j        |d                    }t          j
        |t          j        |d          |          }t          j
        |t          j        |d          |          }|                    t          j        |          j                  }t          j
        |t%          | |||||          t'          | |||||                    }|
|	z  |z  }t          j
        |t          j        |t           j        |          |          }t          j
        || z  t          j        |t           j        |          |          }t          j
        ||z  |	z  |z  ||                    |          |z
            }|S )Nbinomialrk  r   r   r  g      $@g     @)rN   r   rI   r   rH   r   r	   r   r;   ru  r   r'   isinfr   r  rF   r   r   r  r  nanrh  r   )r-   r  r  rI   r;   	p_lt_halfr  count_nan_or_neg	count_infq_is_nanq_l_0use_inversion	count_inv
count_btrsq_btrsr	  r  invalids                     r&   	_binomialr  	  s    ] 5!1!139T??CCEEUBHUOORXd^^DDD"4(('4

"5$*
5
5%

5%
(
(%		$	&	&$Sj)	jD#*--!E]]eck2i)AYY(
c'%	jE!3=D#9#91==!"eai4&78- )E

%js}UC/H/HII)z-uc)B)BEJJ*:mS]1c%:%:A>>&jj5))-..)JY5%CC	#z65%;; ' X 00'JM'37E** ' J'M'37E** ' J  8+i7	LL'! '
 
.r(   c                H   t          d|           \  } }t          d||           t          j        |           t          j        |t
          j                  st          d          t          j        |          }|t          j
        |          }t          | ||||          S )a  Sample Binomial random values with given shape and float dtype.

  The values are returned according to the probability mass function:

  .. math::
      f(k;n,p) = \binom{n}{k}p^k(1-p)^{n-k}

  on the domain :math:`0 < p < 1`, and where :math:`n` is a nonnegative integer
  representing the number of trials and :math:`p` is a float representing the
  probability of success of an individual trial.

  Args:
    key: a PRNG key used as the random key.
    n: a float or array of floats broadcast-compatible with ``shape``
      representing the number of trials.
    p: a float or array of floats broadcast-compatible with ``shape``
      representing the probability of success of an individual trial.
    shape: optional, a tuple of nonnegative integers specifying the result
      shape. Must be broadcast-compatible with ``n`` and ``p``.
      The default (None) produces a result shape equal to ``np.broadcast(n, p).shape``.
    dtype: optional, a float dtype for the returned values (default float64 if
      jax_enable_x64 is true, otherwise float32).

  Returns:
    A random array with the specified dtype and with shape given by
    ``np.broadcast(n, p).shape``.
  r  z?dtype argument to `binomial` must be a float dtype, got {dtype})rL   r   r   r   r:   rH   r   rA   r   r   r   r  )r-   rV  r  rI   r;   r   s         r&   r  r  	  s    D :s++&#q*a####E***		5"+	.	. 
I   
#E
*
*%
#E**E	31eU	+	++r(   random_clonec                    | S r#   rs   r%   s    r&   r   r   #
  s    1 r(   c                    |gS r#   rs   )r   r  s     r&   r   r   %
  s    QC r(   c                6    t                               |           S )a}  Clone a key for reuse

  Outside the context of key reuse checking (see :mod:`jax.experimental.key_reuse`)
  this function operates as an identity.

  Examples:

    >>> import jax
    >>> key = jax.random.key(0)
    >>> data = jax.random.uniform(key)
    >>> cloned_key = jax.random.clone(key)
    >>> same_data = jax.random.uniform(cloned_key)
    >>> assert data == same_data
  )random_clone_pr  )r-   s    r&   cloner  '
  s     
		S	!	!!r(   )r    r   r!   r   )r+   r,   r-   r.   r*   r/   r!   r0   )r-   rR   rS   rT   rI   rU   r!   r   )rt   ru   r!   r_   )r   r,   r   r   rt   ru   r!   rR   )r   r   r3   ru   r!   rR   )r-   r.   r   r   r!   rR   )r-   rR   r   r   r!   rR   )r-   r.   r   r   r!   rR   )r~   rR   r!   r_   )r~   r.   r!   r   )r~   rR   r!   r   )r~   r.   r!   r   )r   r   r3   ru   )r+   r,   rI   rU   r!   r   )rs   N)r-   r.   rI   rU   r;   r   r!   r   )r-   r.   rI   rU   r;   r   r   r   r   r   r!   r   )r!   r   )r-   r.   rI   rU   r   r   r   r   r;   r   r!   r   )r   F)
r-   r.   r    r   r  rT   r  r/   r!   r   )rs   TNr   )r-   r.   r  r   rI   rU   r  r/   r  r  r  rT   r!   r   )r-   r.   rI   rU   r;   r   r!   r   )NNr
   )r-   r.   rK  r   rL  r   rI   rM  r;   rN  rO  r,   r!   r   )r-   r.   r^  r   r_  r   rI   rM  r;   r   r!   r   )r-   r.   r  r   rI   rM  r!   r   )r-   r.   r  r   ri  r   rI   rM  r;   r   r!   r   )
r-   r.   r  r   rI   rM  r;   r   r!   r   )r-   rR   r!   r   )
r-   r.   r  r   rI   rM  r;   r   r!   r   )F)
r-   r.   r  r   rI   rM  r;   r   r!   r   )r!  N)
r-   r.   r2  r   r  rT   rI   rM  r!   r   )
r-   r.   ri  r   rI   rM  r;   r   r!   r   )
r-   r.   rL  r   rI   rU   r;   r   r!   r   )
r-   r.   rL  r   rI   rM  r;   r   r!   r   )r-   r.   r[  r   r\  r   rI   rM  r;   r   r!   r   )r-   r.   rI   rU   r;   r   r!   r   )r-   r.   rr  r   rs  r   rI   rU   r;   r   r!   r   )r-   r.   rs  r   r}  r   rI   rU   r;   r   r!   r   )
r-   r.   rV  rT   rI   rU   r;   r   r!   r   )
r-   r.   r  r  rI   rU   r;   r   r!   r   )
r-   r.   r  rT   r  r  rI   rU   r;   r   )
r-   r.   rs  r   rI   rM  r;   r   r!   r   )
r-   r.   rK  r   rI   rM  r;   r   r!   r   )
r-   r.   r  r   rI   rM  r;   r   r!   r   )r-   r.   r  r   r  r   r  r   rI   rM  r;   r   r!   r   )
r-   r.   r  r   rI   rM  r;   r   r!   r   )r-   rR   rV  r   r  r   rI   rM  r;   r   r!   r   )
__future__r   collections.abcr   r   	functoolsr   r"  operatorr   r   r   rB   numpyrH   	jax.numpyrN   jaxr	   jax.numpy.linalgr
   r   r   jax._srcr   r   r   r   r   r   jax._src.apir   r   jax._src.interpretersr   r   r   jax._src.laxr  jax._src.numpy.lax_numpyr   jax._src.numpy.utilr   r   r   jax._src.typingr   r   r   jax._src.utilr   r   r   r   DTypeLikeUIntr   rT   rU   r_   rR   r.   r   r  r   r'   rL   rQ   rX   r>   r]   r,   PRNGSpecDescr   r   r-   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r  r	  r  r5  r7  r=  rQ  rR  ra  rb  r   rm  rn  rr  rs  r  r  r  r  r  r  r  r  r  r  r  	Primitiver  def_impldef_abstract_evaldefjvp2register_lowering	lower_funprimitive_batchersr  rv  r  r  r#  r*  r,  r(  r/  r4  r>  r?  rD  rE  rH  rI  r   rN  rV  rW  r^  r_  rg  rh  rl  rm  ru  rv  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  simple_impldefvectorizedr  rs   r(   r&   <module>r
     s   # " " " " " . . . . . . . .                                      0 0 0 0 0 0 0 0 0 0                                     " " " " " " " " $ $ $ $ $ $ * * * * * * & & & & & & , , , , , , > > > > > > S S S S S S S S S S 7 7 7 7 7 7 7 7 7 7 + + + + + + 	 =
  
   
 +0           F; ; ;A A A A  "% % % % % % % %$ S(H,-P P P P.
+ 
+ 
+ 
+ %)! ! ! ! ! !( )-> > > > > >(- - - -&	- 	- 	- 	- 	-< < < < <   
) ) ) )
" " " "    /39 9 9 9 9 9*8 8 8 8 '+- - - - -< $) " "	5 5 5 5 5: 	V$$$%? %? %? %$%?X #&	5 5 5 5 54 	V$$$;I ;I ;I %$;I@ $)5 5 5 5 5> 	T"""   #": !%JL JL JL JL JL\ #($ $ $ $ $> 	V$$$
+ 
+ 
+ %$
+ 	V$$$> > > %$> /37;&00D 0D 0D 0D 0Dd 	Y'''   ('F ,0-2	(< (< (< (< (<T 	V$$$O O O %$O0 (RZ__$( #  #  #  #  #D 	T"""/ / / #"/  $!&	&( &( &( &( &(R< < < <* #($ $ $ $ $> 	V$$$> > > %$> %)&++. +. +. +. +.Z 	V$$$) ) ) %$)"> > > >  "(-) ) ) ) )> 	V$$$( ( ( %$(A) A) A) A)H$ $ $( 05 ' ' ' ' '"; ; ;  //    $ $ $     !L!L M M M 

DNNP P P  ~~t~GK$'''( ( (     ~~t~GK$'''( ( (&+- - - - /C N + !%"',2 ,2 ,2 ,2 ,2b $(%*'B 'B 'B 'B 'BT 	=>>>	: 	: 	: 	: ?>	: 	Y'''   (', 	Y'''' ' ' (''T 	V$$$> > > %$>, #'"%** ** ** ** **\ #($ $ $ $ $: 	V$$$L L L %$L &*' ' ' ' 'V $)% % % % %: 	V$$$> > > %$> %*& & & & &: 	V$$$; ; %$; "&#(#' #' #' #' #'J 	V$$$   %$ #"# "# "# "# "#H 	V$$$# # # %$#" %)&+$+ $+ $+ $+ $+L 	V$$$
 
 
 %$
  !#	*- *- *- *- *-X 	V$$$   %$( !%(( ( ( ( (: 	V$$$3 3 3 %$3 $)% % % % %B 	V$$$, , , %$, )+16	!> !> !> !> !>H 	V$$$1 1 1 %$1$  "(-	!? !? !? !? !?H 	V$$$K K K %$K 	O O O O OB 	! ! ! ! !L E E E E EF $(%*$- $- $- $- $-L 	V$$$   %$   $!&%( %( %( %( %(N 	V$$$   %$( %)$'#* #* #* #* #*J 	V$$$   %$& &*',,; ,; ,; ,; ,;\ 	VD111   21$ ",A$(&+!. !. !. !. !.F 	VD111   21O O O0 	Yt444  544 	Yt444,B ,B 54,B^ 	VD1117 7 7 217| !,, ,, ,, ,, ,,`  //  ^ $ $ $      - - -  ~ & & &  ~'7'7 8 8 8" " " " "r(   