
    Wh             	      l   d dl mZ d dl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.m/Z/ d dl0m1Z1 e.Z2e.Z3e/Z4e/Z5e/Z6ee7         Z8ej9        Z9ej:        Z:e%j;        Z<ddZ=dddd$Z>d% Z?dd*Z@d+ ZA G d, d-          ZBe
eCeBe9f         ZDdd1ZEdd5ZFdd6dd8ZGdd6dd9ZHdd<ZIdbdd@ZJdbddAZKddCZLddEZMddFZNddGZOddHZPdd6ddJZQddLZR	 	 dddPZSdMeTdQdRfddWZU eedXY          ddZ            ZVe7fdd\ZW eed]Y          dd^            ZX	 	 dddaZY eedbY          ddc            ZZ	 	 	 	 dddiZ[dMeTfddjZ\ eedXY          ddk            Z] eedXY          ddl            Z^	 	 	 dddsZ_ eedtY          ddu            Z`deTfddxZa eedyY          ddz            Zb ejc        d{          dfdd|Zd eedbY          dd}            ZedeTfddZfddZgdMeTfddZh eedXY          dd            ZideTfddZj eedY          dd            ZkddZldMeTfddZm eedXY          dd            ZnddZod ZpdddZqd Zr ejs        d          Ztetu                    eq           etv                    d             e!jw        etdd             e#jx        et e#jy         eeqdd          d                      e#jx        et e#jy         eeqdd          d          d           ere"jz        et<   deTfd dZ{deTfd dZ| eed          ddd            Z} eedY          dd            Z~ eedY          dd            Z eedY          dd            Zde7fddZdMeTfddZ eedXY          dd            Z	 	 dddZdMeTfddZ eedXY          dd            ZdMeTfddZ eedXY          d             ZdeTfddZ eedY          dd            ZdMeTfddZ eedY          dd            ZdeTfddZ eedY          dd            ZdeTfddZ eedyY          dd            ZdMe7fd	dZ eedXY          dd            ZdMeTfddZ eedXY          dd            ZdMeTfd
dZ eedyY          dd            ZdMeTfddZ eedyY          dd            ZdMeTfddZdMeTfddZd=dMeTfddĄZdeTfddńZ eedY          ddƄ            ZdeTfddǄZ eedY          ddȄ            Zde7fddɄZ eedY          ddʄ            ZdeTfdd΄Z eedddЦ          ddф            Z ejc        dҦ          deTfddԄZ eedddЦ          ddՄ            Zdք Z eedtddЦ          dׄ             Z eedtddЦ          d؄             Z eedyddЦ          ddل            ZdeTfddڄZ ejs        dۦ          Z ej        e           ev                    d܄             e"j        e            e#jx        ed݄            dބ ZdS (      )annotations)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    U/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/jax/_src/random.py_isnanr&   B   s    	1    Fallow_batchednamestrkeyr)   booltuple[Array, 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warningsr3   enable_custom_prngFutureWarning	TypeErrortypendimnpshape)r*   r,   r)   wrapped_keywrappeds        r%   _check_prng_keyrJ   F   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"   )
jnpr8   r9   r   r:   r   rA   r>   r   random_unwrap)was_wrappedr,   s     r%   _return_prng_keysrO   i   sL    		6?	3	333	3$ ;J&1:4c"""s:r'   	bit_widthintrG   Shapec                |    t          j        | j        t          j                  sJ t          j        | ||          S )N)rP   rG   )rL   r8   r9   r   r:   r   random_bits)r,   rP   rG   s      r%   _random_bitsrU   r   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<   y   s7     &,)	dj	 	 	 )	 	 	 	I	r'   c                  J    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dZ
dS )PRNGSpecz$Specifies a PRNG key implementation._implPRNGImplc                    || _         d S r"   )r[   )selfr1   s     r%   __init__zPRNGSpec.__init__   s    DJJJr'   r    r+   c                "    d| j         j        dS )Nz	PRNGSpec())r[   r*   r^   s    r%   __repr__zPRNGSpec.__repr__   s    +tz++++r'   c                *    t          | j                  S r"   )r+   r[   rb   s    r%   __str__zPRNGSpec.__str__   s    tz??r'   rQ   c                *    t          | j                  S r"   )hashr[   rb   s    r%   __hash__zPRNGSpec.__hash__   s    
r'   r-   c                L    t          |t                    o| j        |j        k    S r"   )r7   rZ   r[   )r^   others     r%   __eq__zPRNGSpec.__eq__   s     eX&&D4:+DDr'   N)r    r+   )r    rQ   )r    r-   )__name__
__module____qualname____doc__	__slots____annotations__r_   rc   re   rh   rk    r'   r%   rZ   rZ      s         ,,i)///  , , , ,      E E E E E Er'   rZ   	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 )"Nrr   ).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<   rD   r\   rZ   r[   r+   r   rW   joinkeysr?   rC   )rs   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 )Nr9   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 batchingr0   )r   hasattrrL   r8   r9   r   r:   rC   rF   rE   rG   r   random_seed)r   r   rs   r1   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'   r0   r1   c               $    t          d| |          S )ai  Create a pseudo-random number generator (PRNG) key given an integer seed.

  The result is a scalar array containing a key, whose dtype indicates
  the default PRNG implementation, as determined by the optional
  ``impl`` argument or, otherwise, by the ``jax_default_prng_impl``
  config flag at the time when this function is called.

  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   r1   s     r%   r,   r,      s    $ 
eT4	 	  r'   c               @    t          dt          d| |                    S )a  Create a legacy PRNG key given an integer seed.

  This function produces old-style legacy PRNG keys, which are arrays
  of dtype ``uint32``. For more, see the note in the `PRNG keys
  <https://jax.readthedocs.io/en/latest/jax.random.html#prng-keys>`_
  section. When possible, :func:`jax.random.key` is recommended for
  use instead.

  The resulting key does not carry a PRNG implementation. The returned
  key matches the implementation given by the optional ``impl``
  argument or, otherwise, determined by the ``jax_default_prng_impl``
  config flag. Callers must ensure that same implementation is set as
  the default when passing this key as an argument to other functions
  (such as ``jax.random.split`` and ``jax.random.normal``).

  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)rO   r   r   s     r%   r   r      s     4 
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 r6   )
rJ   rF   rE   rC   rG   r   random_fold_inrL   uint32rO   )r,   r   rI   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'   r4   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 r6   rG   )rL   r8   r9   r   r:   rE   rC   rG   r7   r   tupler   random_split)r,   r   rG   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)rJ   rO   r   )r,   r   	typed_keyrI   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"   )
rL   r8   r9   r   r:   typingcastr   KeyTyr[   )r}   
keys_dtypes     r%   	_key_implr   &  s<    	
FO	4	444	4{4:tz22*		r'   str | PRNGSpecc                r    t          |           }|j        t          j        v r|j        nt	          |          S r"   )r   r*   r   rW   rZ   )r}   r1   s     r%   	_key_specr   +  s-    	4$i4:--8D>>Ar'   c                J    t          d| d          \  }}t          |          S )Nkey_implTr(   )rJ   r   )r}   
typed_keys_s      r%   r   r   /  s(    !*d$GGG-*a	:		r'   c                v    t          j        | j        t          j                  sJ t          j        |           S r"   )rL   r8   r9   r   r:   r   rM   )r}   s    r%   	_key_datar   4  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(   )rJ   r   )r}   r   s     r%   r   r   8  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.
  r0   )r   r   r;   )r   r1   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_shapesr?   format)r*   rG   param_shapesshape_msgs        r%   _check_shaper   S  sb     8!%7,777FLc szz$667778 8r'   rr   r9   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    )rJ   r   canonicalize_dtyperL   uintcheck_user_dtype_supportedr8   rF   unsignedintegerr?   r   canonicalize_shapeitemsizerU   )r,   rG   r9   r   rP   s        r%   r   r   ]  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 )rJ   r   r   r   r   r8   rF   floatingr?   r   _uniform)r,   rG   r9   r   r   r   s         r%   r   r   z  s    & 9c**&#q#E***

!%
(
(%		5"+	.	. %
 $!$ $ % % %

#E
*
*%	#ueVV	4	44r'   )   r4   )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   rL   r8   rF   r   rC   r   convert_element_typebroadcast_to_ranklenfinfor   nmantrU   UINT_DTYPES
bitwise_orshift_right_logicalarrayviewbitcast_convert_typemaxreshape)r,   rG   r9   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)rJ   r   r   r   r   r   _randint)r,   rG   r   r   r9   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"   )rU   )r,   r   rG   s    r%   <lambda>z_randint.<locals>.<lambda>  s    l3u55 r'   r   r4   )r   rF   rG   rL   r8   integerrC   r   asarrayr9   astyperQ   r   gtr   r   iinfor   r   r   r   r   r   r   select	full_likeadd
_lax_constremmul)r,   rG   r   r   r9   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)rJ   r   r   rF   rE   r8   r   r9   r   rC   r   concrete_or_errorrQ   _shufflerL   arangerG   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'   )r4   c                   d}t          j        t          j                  j        }t          j        |j                  st          d|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   zSshape polymorphism for `permutation` or `shuffle` for arrays of non-constant size: r   r   )rL   r   rF   r   r   r   is_constant_dimsizeNotImplementedErrorrQ   ceillogranger   rU   rG   r   sort_key_val)	r,   r   r  exponent	uint32max
num_roundsr   subkey	sort_keyss	            r%   r  r  8  s      (i	""&)		af	%	% 7
	6-.V	6 	67 7 7 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|	 d| d	          ||r7t%          | |d|          }
|j        dk    r|
nt          j        ||
|          }nft)          d
          f|z  t)          |	          fz   }t+          | |j        dk    r|n||          |         }nt	          d|           t-          |          \  }|j        |fk    rt#          d|j         d| 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|n1|j        d|         t?          |          z   |j        |dz   d
         z             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()r9   z4a must be greater than 0 unless no samples are takenz"Cannot take a larger sample (size z) than population (size z) when 'replace=False'NzOp must be None or a 1D vector with the same size as a.shape[axis]. p has shape z and a.shape[axis] is r   r   ) rJ   r7   r   rC   r   rL   r   rE   r   r
  rQ   r   rG   mathprodzerosr9   r?   r   r  slicer  r   cumsumr   searchsortedr   gumbelr  argsortr   r   )r,   r  rG   r  r   r  r   arrn_inputsn_drawsr  resultslicesp_arrp_cumlr  gs                    r%   r#  r#  X  sF   @ 8S))&#q	E8	$	$ $
 # # # $ $ $(AA#X]]%c1.YZZHHT38,,DyHIe'\\9U#),,,,]]
K
L
LL	 >Wx''
	=W 	= 	=$	= 	= 	=> > > Y RC8,,ch!mmss#sD)A)Affd~$g'88f3CHMMsDII&QffHa   #A&&FE{xk!!HH H<DH H HI I I  %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	!D&)E%LL839T!VWW;MM
O 
O O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 )rJ   r   r   r   r   r8   rF   inexactr?   r   _normalr,   rG   r9   r   s       r%   r7  r7    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 )Nr4   r   y              ?)r   r8   rF   complexfloatingr   sqrtr   realr9   _normal_realr   )	r,   rG   r9   sqrt2key_rekey_im
real_dtype_re_ims	            r%   r9  r9    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 )Nr7        r   r$  r   r4   )	r   rF   	nextafterr   r   r   r   r=  erf_inv)r,   rG   r9   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 )rJ   r   r   r   r?   r9   r8   rF   r   r   r   _multivariate_normal)r,   rM  rN  rG   r9   rQ  r   s          r%   rS  rS    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 == {}r4   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}.)nrG   r7  r
   .r   allowz...ij,...j->...i)rF   rE   r?   r   rG   r   r   r   r
   rL   r=  r   r	   r7  r   numpy_rank_promotioneinsum)r,   rM  rN  rG   r9   rQ  r   rX  rL  ry   r   factorwvnormal_samplesr1  s                   r%   rT  rT    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   rJ   r   r   r8   rF   r   r?   r   _truncated_normal)r,   r`  ra  rG   r9   r   s         r%   rc  rc  1  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 )Nrc  r4   z4truncated_normal only accepts floating point dtypes.r   r   r$  )r   r   rF   rG   r   r   r=  r   erfrL   r8   r   rC   r   rI  cliprH  stop_gradientinf)
r,   r`  ra  rG   r9   r@  r  brL  outs
             r%   rd  rd  [  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   rJ   r   r   r   r9   rL   r8   rF   r   rC   r   r   
_bernoulli)r,   r   rG   r   r9   r   s         r%   ro  ro  s  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 )Nro  )rF   rG   r   r   r   r9   r,   r   rG   s      r%   rp  rp    sO    
]HQKKEEeRXa[[111	eSYq\\	*	*Q	..r'   rk  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 )rJ   r   r   r8   rF   r   r?   r   r   r   _beta)r,   r  rk  rG   r9   r   s         r%   rt  rt    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 )Nrt  )r   r   rF   rG   r   r   r   rL   broadcast_tologgammar   exp)r,   r  rk  rG   r9   key_akey_blog_gamma_alog_gamma_blog_maxgamma_a_scaledgamma_b_scaleds               r%   ru  ru    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 )rJ   r   r   r8   rF   r   r?   r   r   r   _cauchyr:  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   rf  rm  )r   r   rL   r   epsr   rF   pir   tanr   sub)r,   rG   r9   rL  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 )rJ   r   r   r8   rF   r   r?   r   r   r   
_dirichlet)r,   r  rG   r9   r   s        r%   r  r    s    F ;,,&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	Cu	-	--r'   )r4   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  )
rF   rE   r?   r   rG   r   r   r   rx  _softmax)r,   r  rG   r9   r   log_gamma_sampless         r%   r  r  1  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   r8   r9   rF   r   rC   rL   r   ry  r   ri  sum)r   r  x_maxunnormalizeds       r%   r  r  C  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 )rJ   r   r   r8   rF   r   r?   r   r   r   _exponentialr:  s       r%   r  r  L  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,   rG   r9   rL  s       r%   r  r  k  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%  rm  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_fn  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   rr   r$  )r   r7  r   r   r   )kxvr,   r  r   r^  cr9   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 )Nr4   )r   le)r  zeros    r%   r   z._gamma_one.<locals>._body_fn.<locals>.<lambda>  s    A)=)= r'   rr   r$  )r   r   
while_loopr   r   )r  r  r,   x_keyU_keyr   r   r^  r  r  r  r  r9   	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'   r4   rr   r$  )r   r   r9   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  r9   r  r  r  r  r  s                  @@@@@@@@r%   
_gamma_oner  s  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"   rr   )args
gamma_grads    r%   r   z_gamma_grad.<locals>.<lambda>  s    T!2 r'   )rL   r   r   ry  lax_internal_constr   r   r9   tinyr   eqr  r   get_backendplatformmapr   rF   rG   )	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'   )rL   rG   r&  r'  rE   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   )rx   r   is      r%   rz   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                    |S r"   rr   )r,   r  r   s      r%   r   r     s    Q 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rG   r9   rJ   r   r   r8   rF   r   r?   r   r   r   _gammar,   r  rG   r9   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.
  rx  r  NTrG   r9   r  r  r  s        r%   rx  rx  "  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  )	rF   rG   r   r   r   rL   rw  r  r  )r,   r  rG   r9   r  s        r%   r  r  L  s    
]HQKKEE%!---	q%((!Xa[[EE""A			S!y		9	99r'   )r4   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   rF   float32rL   r  )	carryr  r  rnglog_prodr  rL  lamrG   s	          r%   body_fnz_poisson_knuth.<locals>.body_fn_  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_fnf  s5    (E!HxAtO  ""a)m44r'   r   r   )r   r   rF   r  r  r   )
r,   r  rG   r9   r
  r  r  k_initlog_rate_initr  s
    `` `     r%   _poisson_knuthr  Y  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>٬@r4   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  rm  r4   gQ?r   Q?r   g9v?)	r   r   r9   absr   floorr  lgammar   )r  r  k_outacceptedr,   subkey_0subkey_1rL  r^  	u_shiftedr  ry   r   accept1rejectaccept2acceptr  rk  	inv_alphar  log_lamrG   v_rs                    r%   r  z#_poisson_rejection.<locals>.body_fn{  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_fn  s,    #AuhI??I..r'   r%  Fr   r   )	r   r  r=  r   r9   rL   bool_r  r   )r,   r  rG   r9   r
  r  r  r  r  r  r  rk  r  r   r!  s    `` `     @@@@@r%   _poisson_rejectionr$  p  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   rD   rL   r   r   r  r$  
zeros_like)	r,   r  rG   r9   	use_knuth	lam_knuthlam_rejectionr
  r1  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 )rJ   r   r   r   r   r   r   r9   r[   r  r  r   r   r   rF   rG   rL   rw  r   r   r  r+  )r,   r  rG   r9   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 )rJ   r   r   r8   rF   r   r?   r   r   r   _gumbelr:  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   rf  )r   rL   r  r   r   r  r,   rG   r9   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  )rJ   r   rL   r   r   rG   r   rF   deleter   r   r   listinsertargmaxr,  r9   r   expand_dimsr  )	r,   r2  r  rG   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 )rJ   r   r   r8   rF   r   r?   r   r   r   _laplacer:  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@  rG  r   rf  )r   r   rL   r   epsnegr   r   signr  r  r  r  s       r%   rA  rA  H  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 )rJ   r   r   r8   rF   r   r?   r   r   r   	_logisticr:  s       r%   rF  rF  P  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 )NrF  r   rf  r   )
r   r   rL   r   r  r   r  r  r  r   )r,   rG   r9   r   s       r%   rG  rG  m  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 )rJ   r   r   r8   rF   r   r?   r   r   r   _pareto)r,   rk  rG   r9   r   s        r%   rJ  rJ  t  s    6 8S))&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	a	&	&&r'   c                    |t          j        |          }nt          d|           t          j        ||          }t          | ||          }t          j        ||z            S )NrJ  )rF   rG   r   r   r   r  ry  )r,   rk  rG   r9   es        r%   rK  rK    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 )rJ   r   r   r8   rF   r   r?   r   r   r   _tr,   rN  rG   r9   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   r4   )rF   rG   r   r   r   r   r7  r   r  r  rL   r=  )
r,   rN  rG   r9   key_nkey_grX  twohalf_dfr5  s
             r%   rP  rP    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 )rJ   r   r   r8   rF   r   r?   r   r   r   
_chisquarerQ  s        r%   rX  rX    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 )NrX  r4   )r  rG   r9   )rF   rG   r   r   r   r   r  rx  r   rL   ry  )r,   rN  rG   r9   rU  rV  log_gchi2s           r%   rY  rY    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 )rJ   r   r   r8   rF   r   r?   r   r   r   _f)r,   r]  r^  rG   r9   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   rF   rG   r   r   r   rX  rL   rw  r  )r,   r]  r^  rG   r9   key_dfdkey_dfnchi2_dfnchi2_dfdr   denr`  s               r%   ra  ra  9  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)rJ   r   r   r   r   r   _rademacherr:  s       r%   ri  ri  M  sZ    , <--&#q#E***

#E
*
*%

!%
(
(%	S%	'	''r'   c                    t          | d|                              |          }d|z  dz
                      |          S )Nrm  rr  r4   r   )ro  r   )r,   rG   r9   bernoulli_sampless       r%   rj  rj  j  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 )rJ   r   r   r8   rF   r   r?   r   r   r   _maxwellr:  s       r%   rn  rn  p  s    . 9c**&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%

!%
(
(%	#ue	$	$$r'   c                r    |dz   }t          | ||          }t          j                            |d          S )N)r  r1  r%  r5  )r7  rL   linalgnorm)r,   rG   r9   norm_rvss       r%   ro  ro    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 )rJ   r   r   r8   rF   r   r?   r   r   r   _double_sided_maxwell)r,   rt  ru  rG   r9   r   s         r%   rw  rw    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   rF   rG   r   rn  ri  )
r,   rt  ru  rG   r9   params_shapesmaxwell_keyrademacher_keymaxwell_rvsrandom_signs
             r%   rx  rx    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 )rJ   r   r   r8   rF   r   r?   r   r   r   _weibull_min)r,   ru  r  rG   r9   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,   rG   r   r   r9   r   )r   rL   powerr  )r,   ru  r  rG   r9   random_uniforms         r%   r  r    sN    
U1Qe= = =. 
CI~o...M0A	B	BU	JJr'   rX  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.

  References:
    .. [1] Mezzadri, Francesco. (2007). "How to generate random matrices from
           the classical compact groups". Notices of the American Mathematical
           Society, 54(5), 592-604. https://arxiv.org/abs/math-ph/0609050.
  
orthogonalz-The error occurred in jax.random.orthogonal()r   rW  r%  )r   r   rJ   r   r   r   r
  r   r7  rL   rq  qrdiagonalr   r   r:  r  r  r   r9   )	r,   rX  rG   r9   r   zqr  r  s	            r%   r  r    s    2 
!%
(
(%<--&#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   rJ   r   r   r   r   r  ri  )r,   r   rG   r9   r   r}   r5  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   rJ   r   r   r   r
  r   r   r  r  rL   r  r  )
r,   r  r   rG   r9   r   r   r   r5  rM  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 )rJ   r   r   r8   rF   r   r?   r   r   r   	_rayleigh)r,   ru  rG   r9   r   s        r%   r  r  `  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  rW  )rF   rG   r   r   r   rL   rw  r   r  r   r=  r   )	r,   ru  rG   r9   rL  log_un_twosqrt_urays	            r%   r  r    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 )rJ   r   r   r8   rF   r   r?   r   r   r   _wald)r,   rM  rG   r9   r   s        r%   r  r    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  r4   r   )rF   rG   r   r   r   rL   rw  r7  r   r   integer_powr=  r   r  )r,   rM  rG   r9   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 )rJ   r   r   r8   rF   r   r?   r   r   r   
_geometric)r,   r   rG   r9   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   )rF   rG   r   r   r   r   r9   r   r  r  rL   rw  r  r  r   )r,   r   rG   r9   rL  r  log_one_minus_pr5  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 )rJ   r   r   r8   rF   r   r?   r   r   r   _triangular)r,   r  r  r  rG   r9   r   s          r%   r  r  	  s    H <--&#q#E***		5"+	.	. ,
 +#(+ + , , ,

#E
*
*%
#E**E	S$eUE	:	::r'   )r   rU  )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   rF   rG   r   rL   rw  r   r=  r   )r,   r  r  r  rG   r9   fcrL  out1out2tris              r%   r  r  2	  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 )rJ   r   r   r8   rF   r8  r?   r   r   r   
_lognormal)r,   r  rG   r9   r   s        r%   r  r  D	  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  )rF   rG   r   rL   rw  r7  r   ry  )r,   r  rG   r9   scaled_norms        r%   r  r  g	  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?)rL   r   r9   r   clampr  r   int32)r  stirling_tail_valsuse_tail_valueskp1sqapproxs        r%   _stirling_approx_tailr  r	  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   r9   rL   r  r  )r  r  num_geomgeom_sumr,   r  num_geom_outrL  geomcountlog1minusprobprobrG   s            r%   r  z$_binomial_inversion.<locals>.body_fn	  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   r4   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>   rL   r8   r9   r   r  r   r   r  r   )r,   r  r  rG   r9   r
  r  r  num_geom_initgeom_sum_initr  r  r  s    ``` `      @r%   _binomial_inversionr  	  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?rm  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  rm  r  r4   r   r   )
r   r   r9   rL   r  r  r  r  r   r   )r  r  r  r  r,   r  r  rL  r^  usr  r  r  ubr  r  r  r  rk  r  r  mr  r  rG   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)
rL   r=  r  r   r   r9   fullr#  r  r   )r,   r  r  rG   r9   r
  stddevr  r  r  r  r  r  rk  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binomialrm  r   r   r  g      $@g     @)rL   r   rG   r   rF   r   r   r   r9   rw  r   r&   isinfr   r  rD   r   r   r  r  nanrj  r   )r,   r  r  rG   r9   	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})rJ   r   r   r   r8   rF   r   r?   r   r   r   r  )r,   rX  r   rG   r9   r   s         r%   r  r  
  s    D :s++&#q*a####E***		5"+	.	. 
I   
#E
*
*%
#E**E	31eU	+	++r'   random_clonec                    | S r"   rr   r$   s    r%   r   r   B
  s    1 r'   c                    |gS r"   rr   )r   r  s     r%   r   r   D
  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  F
  s     
		S	!	!!r'   )r   r   r    r   )r*   r+   r,   r   r)   r-   r    r.   )r,   r   rP   rQ   rG   rR   r    r   )rs   rt   r    r\   )r   r+   r   r   rs   rt   r    r   )r   r   r1   rt   r    r   )r,   r   r   r   r    r   )r,   r   r   r   r    r   )r,   r   r   r   r    r   )r}   r   r    r\   )r}   r   r    r   )r}   r   r    r   )r}   r   r    r   )r}   r   r    r   )r   r   r1   rt   )r*   r+   rG   rR   r    r   )rr   N)r,   r   rG   rR   r9   r   r    r   )r,   r   rG   rR   r9   r   r   r   r   r   r    r   )r    r   )r,   r   rG   rR   r   r   r   r   r9   r   r    r   )r   F)
r,   r   r   r   r  rQ   r  r-   r    r   )rr   TNr   )r,   r   r  r   rG   rR   r  r-   r   r!  r  rQ   r    r   )r,   r   rG   rR   r9   r   r    r   )NNr	   )r,   r   rM  r   rN  r   rG   rO  r9   rP  rQ  r+   r    r   )r,   r   r`  r   ra  r   rG   rO  r9   r   r    r   )r,   r   r   r   rG   rO  r    r   )r,   r   r  r   rk  r   rG   rO  r9   r   r    r   )
r,   r   r  r   rG   rO  r9   r   r    r   )r,   r   r    r   )
r,   r   r  r   rG   rO  r9   r   r    r   )F)
r,   r   r  r   rG   rO  r9   r   r    r   )r%  N)
r,   r   r2  r   r  rQ   rG   rO  r    r   )
r,   r   rk  r   rG   rO  r9   r   r    r   )
r,   r   rN  r   rG   rR   r9   r   r    r   )
r,   r   rN  r   rG   rO  r9   r   r    r   )r,   r   r]  r   r^  r   rG   rO  r9   r   r    r   )r,   r   rG   rR   r9   r   r    r   )r,   r   rt  r   ru  r   rG   rR   r9   r   r    r   )r,   r   ru  r   r  r   rG   rR   r9   r   r    r   )
r,   r   rX  rQ   rG   rR   r9   r   r    r   )
r,   r   r   r  rG   rR   r9   r   r    r   )
r,   r   r  rQ   r   r  rG   rR   r9   r   )
r,   r   ru  r   rG   rO  r9   r   r    r   )
r,   r   rM  r   rG   rO  r9   r   r    r   )
r,   r   r   r   rG   rO  r9   r   r    r   )r,   r   r  r   r  r   r  r   rG   rO  r9   r   r    r   )
r,   r   r  r   rG   rO  r9   r   r    r   )r,   r   rX  r   r   r   rG   rO  r9   r   r    r   )
__future__r   collections.abcr   	functoolsr   r&  operatorr   r   r   r@   numpyrF   	jax.numpyrL   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   rQ   rR   r\   r   r  r   r&   rJ   rO   rU   r<   rZ   r+   PRNGSpecDescr   r   r,   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r  r  r#  r7  r9  r?  rS  rT  rc  rd  r  ro  rp  rt  ru  r  r  r  r  r  r  r  r  r  r  r  	Primitiver  def_impldef_abstract_evaldefjvp2register_lowering	lower_funprimitive_batchersr  rx  r  r  r$  r+  r-  r,  r/  r4  r@  rA  rF  rG  rJ  rK  r   rP  rX  rY  r`  ra  ri  rj  rn  ro  rw  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  simple_impldefvectorizedr  rr   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  "E E E E E E E E0 S(H,-P P P P.
+ 
+ 
+ 
+ %)! ! ! ! ! !* )-> > > > > >:- - - -&	- 	- 	- 	- 	-< < < < <   
B B B B   
" " " "    /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"""   #"B !%NO NO NO NO NOd #($ $ $ $ $> 	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 ' ' ' ' '"; ; ;  //    $ $ $     !6!6 7 7 7 

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L 	! ! ! ! !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'   