
    
9j	                    J   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKrS SKrS SKJr  S SKrS SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S SKrS SKrS
 r\" S5      rSrSr " S S5      rSS jr 0 q!\RD                  S 5       r#S r$S r%S r&g)    )annotationsN)LinAlgError)_core)cuda)device)_kernels)FeistelBijection)_utilc                (   [         R                  R                  U 5      n[         R                  R                  UR                  5      nX!l        [         R                  R                  U5      nU[        R                  U '   UR                  U5        U$ N)		importlibutil	find_spec
LazyLoaderloadermodule_from_specsysmodulesexec_module)namespecr   modules       P/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/random/_generator.pylazy_importr      sh    >>##D)D^^&&t{{3FK^^,,T2FCKK
vM    cupyxl    l    c                  
   \ rS rSrSrS\S jrS rS rS\4S jr	S\
4S jrS\4S	 jrS\4S
 jrSS\4S jrS\4S jrSS\4S jrS]S jrS]S jr\R(                  " SSSS5      rSSS\4S jrSSS\4S jrSSS\4S jrS]S jrSSSS\4S jrS\
4S jrSSS\4S jrS\4S  jrS\4S! jrS\4S" jrS^S# jr S\4S$ jr!S% r"S& r#\R(                  " S'S(S)S*5      r$S+ r%S\4S, jr&SS\4S- jr'\R(                  " S.S/S0S15      r(\R(                  " S.S2S3S45      r)S5 r*S6 r+S7 r,\R(                  " S8S9S:S;5      r-S_S< jr.S\4S= jr/S\4S> jr0S\4S? jr1S\4S@ jr2S\4SA jr3S_SB jr4\R(                  " SCS(SDSE5      r5S\4SF jr6\R(                  " SGS(SHSI5      r7SSS\4SJ jr8S\4SK jr9\R(                  " SLSMSNSO5      r:S\4SP jr;S\4SQ jr<S\
4SR jr=S`SS jr>ST r?SU r@SV rA\R(                  " SSSWSX5      rBSSS\4SY jrCSS\
4SZ jrDS[rEg)aRandomState.   a
  Portable container of a pseudo-random number generator.

An instance of this class holds the state of a random number generator. The
state is available only on the device which has been current at the
initialization of the instance.

Functions of :mod:`cupy.random` use global instances of this class.
Different instances are used for different devices. The global state for
the current device can be obtained by the
:func:`cupy.random.get_random_state` function.

Args:
    seed (None or int): Seed of the random number generator. See the
        :meth:`~cupy.random.RandomState.seed` method for detail.
    method (int): Method of the random number generator. Following values
        are available::

           cupy.cuda.curand.CURAND_RNG_PSEUDO_DEFAULT
           cupy.cuda.curand.CURAND_RNG_PSEUDO_XORWOW
           cupy.cuda.curand.CURAND_RNG_PSEUDO_MRG32K3A
           cupy.cuda.curand.CURAND_RNG_PSEUDO_MTGP32
           cupy.cuda.curand.CURAND_RNG_PSEUDO_MT19937
           cupy.cuda.curand.CURAND_RNG_PSEUDO_PHILOX4_32_10

Nc                   SSK Jn  Uc  UR                  n[        R                  " 5       U l        UR                  U5      U l        [        R                  " XR                  U R                  5      U l        X l        U R                  U5        g )Nr   curand)cupy_backends.cuda.libsr"   CURAND_RNG_PSEUDO_DEFAULT	threadingLock_lockcreateGenerator
_generatorweakreffinalizedestroyGenerator
_finalizermethodseed)selfr/   r.   r"   s       r   __init__RandomState.__init__J   sh    2>55F ^^%
 008!**))4??<		$r   c                    U R                      U R                  nX!-   [        -  U l        S S S 5        U$ ! , (       d  f       W$ = fr   )r'   _rk_seed_UINT64_MAX)r0   sizerk_seeds      r   	_get_seedRandomState._get_seedZ   s;    ZZmmG$^{:DM   Z s	   4
Ac                j   [         R                  " U5      n[         R                  R                  U5      nUS-  S:X  a^  [        R
                  " X#S9nU R                     U" U R                  UR                  R                  UR                  /UQ76   S S S 5        U$ [        R
                  " US-   4US9nU R                     U" U R                  UR                  R                  UR                  /UQ76   S S S 5        US U R                  U5      $ ! , (       d  f       U$ = f! , (       d  f       N4= f)N   r   dtype   )r   get_sizeinternalprodcupyemptyr'   r)   dataptrr6   reshape)r0   funcr6   r=   argselement_sizeouts          r   _generate_normalRandomState._generate_normal`   s     ~~d#~~**40!q **T/CT__chhllCHHDtD J**lQ.0>CT__chhllCHHDtD }%--d33 J s   4D4D$
D!$
D2c                .   [         R                  " U5      [         R                  " U5      p!Uc   [         R                  " X5      R                  n[         R                  " X4S9nU R                  UR                  5      n[        R                  " XXe5        U$ )zReturns an array of samples drawn from the beta distribution.

.. seealso::
    - :func:`cupy.random.beta` for full documentation
    - :meth:`numpy.random.RandomState.beta`
shaper=   )	rB   asarray	broadcastrO   rC   r8   r6   r   beta_kernel)r0   abr6   r=   yr7   s          r   betaRandomState.betau   si     ||AQ1<>>!'--DJJT/..(Q7.r   c                .   [         R                  " U5      [         R                  " U5      p!Uc   [         R                  " X5      R                  n[         R                  " X4S9nU R                  UR                  5      n[        R                  " XXe5        U$ )zReturns an array of samples drawn from the binomial distribution.

.. seealso::
    - :func:`cupy.random.binomial` for full documentation
    - :meth:`numpy.random.RandomState.binomial`
rN   )	rB   rP   rQ   rO   rC   r8   r6   r   binomial_kernel)r0   npr6   r=   rU   r7   s          r   binomialRandomState.binomial   si     ||AQ1<>>!'--DJJT/..(  w2r   c                    [         R                  " U5      nUc  UR                  n[         R                  " X#S9nU R	                  UR
                  5      n[        R                  " XU5        U$ )zReturns an array of samples drawn from the chi-square distribution.

.. seealso::
    - :func:`cupy.random.chisquare` for full documentation
    - :meth:`numpy.random.RandomState.chisquare`
rN   )rB   rP   rO   rC   r8   r6   r   chisquare_kernelr0   dfr6   r=   rU   r7   s         r   	chisquareRandomState.chisquare   sU     \\"<88DJJT/..(!!"q1r   c                   [         R                  " U5      nUc  UR                  nOD[        U[        [         R
                  45      (       a  U4UR                  -   nOX!R                  -  n[         R                  " X#S9nU R                  UR                  5      n[        R                  " XU5        XDR                  SSS9-  nU$ )zReturns an array of samples drawn from the dirichlet distribution.

.. seealso::
    - :func:`cupy.random.dirichlet` for full documentation
    - :meth:`numpy.random.RandomState.dirichlet`
rN   T)axiskeepdims)rB   rP   rO   
isinstanceintintegerrC   r8   r6   r   standard_gamma_kernelsum)r0   alphar6   r=   rU   r7   s         r   	dirichletRandomState.dirichlet   s     U#<;;DsDLL1227U[[(DKKDJJT/..(&&uq9	UUTU**r         ?c                    [         R                  " X5      nUS:  R                  5       (       a  [        S5      eUc  UR                  nU R                  X#5      nXA-  nU$ )zReturns an array of samples drawn from a exponential distribution.

.. warning::

    This function may synchronize the device.

.. seealso::
    - :func:`cupy.random.exponential` for full documentation
    - :meth:`numpy.random.RandomState.exponential`
r   	scale < 0)rB   rP   any
ValueErrorrO   standard_exponentialr0   scaler6   r=   xs        r   exponentialRandomState.exponential   sX     U*AI??[))<;;D%%d2	
r   c                .   [         R                  " U5      [         R                  " U5      p!Uc   [         R                  " X5      R                  n[         R                  " X4S9nU R                  UR                  5      n[        R                  " XXe5        U$ )zReturns an array of samples drawn from the f distribution.

.. seealso::
    - :func:`cupy.random.f` for full documentation
    - :meth:`numpy.random.RandomState.f`
rN   )	rB   rP   rQ   rO   rC   r8   r6   r   f_kernel)r0   dfnumdfdenr6   r=   rU   r7   s          r   fRandomState.f   sk     ||E*DLL,?u<>>%/55DJJT/..(%3r   c                6   [         R                  " U5      [         R                  " U5      p!Uc   [         R                  " X5      R                  n[         R                  " X4S9nU R                  UR                  5      n[        R                  " XU5        XR-  nU$ )zReturns an array of samples drawn from a gamma distribution.

.. seealso::
    - :func:`cupy.random.gamma` for full documentation
    - :meth:`numpy.random.RandomState.gamma`
rN   )	rB   rP   rQ   rO   rC   r8   r6   r   rk   )r0   rO   rw   r6   r=   rU   r7   s          r   gammaRandomState.gamma   sr     ||E*DLL,?u<>>%/55DJJT/..(&&uq9	
r   c                    [         R                  " U5      nUc  UR                  n[         R                  " X#S9nU R	                  UR
                  5      n[        R                  " XU5        U$ )zReturns an array of samples drawn from the geometric distribution.

.. seealso::
    - :func:`cupy.random.geometric` for full documentation
    - :meth:`numpy.random.RandomState.geometric`
rN   )rB   rP   rO   rC   r8   r6   r   geometric_kernelr0   r[   r6   r=   rU   r7   s         r   	geometricRandomState.geometric   sT     LLO<77DJJT/..(!!!a0r   c                f   [        U[        [        45      (       a  US:  a  [        S5      e[        U[        [        45      (       a  US:  a  [        S5      e[        U[        [        45      (       a  US:  a  [        S5      e[        R
                  " U5      [        R
                  " U5      [        R
                  " U5      p2nUc!  [        R                  " XU5      R                  n[        R                  " XES9nU R                  UR                  5      n[        R                  " XX7U5        U$ )zReturns an array of samples drawn from the hypergeometric distribution.

.. seealso::
    - :func:`cupy.random.hypergeometric` for full documentation
    - :meth:`numpy.random.RandomState.hypergeometric`
r   z	ngood < 0znbad < 0r>   znsample < 1rN   )rh   ri   floatrt   rB   rP   rQ   rO   rC   r8   r6   r   hypergeometric_kernel)r0   ngoodnbadnsampler6   r=   rU   r7   s           r   hypergeometricRandomState.hypergeometric   s     ec5\**uqy[))dS%L))dQhZ((gU|,,1]++LLd!3T\\'5J <>>%w7==DJJT/..(&&uGaHr   zT x, T loc, T scalezT yz>y = loc + scale * ((x <= 0.5) ? log(x + x): -log(x + x - 1.0))cupy_laplace_kernel        c                    [         R                  " X5      n[         R                  " X$5      nUc   [         R                  " X5      R                  nU R	                  X45      n[
        R                  XQX%5        U$ )zReturns an array of samples drawn from the laplace distribution.

.. seealso::
    - :func:`cupy.random.laplace` for full documentation
    - :meth:`numpy.random.RandomState.laplace`
)rB   rP   rQ   rO   _random_sample_rawr   _laplace_kernelr0   locrw   r6   r=   rx   s         r   laplaceRandomState.laplace  s^     ll3&U*<>>#-33D##D0##AE5r   c                   [         R                  " U5      [         R                  " U5      p!Uc   [         R                  " X5      R                  n[         R                  " X4S9nU R                  UR                  5      n[        R                  " Xe5        SU-
  U-  n[         R                  " XUS9  [         R                  " XRUS9  [         R                  " XQUS9  U$ )zReturns an array of samples drawn from the logistic distribution.

.. seealso::
    - :func:`cupy.random.logistic` for full documentation
    - :meth:`numpy.random.RandomState.logistic`
rN   rp   rJ   )rB   rP   rQ   rO   rC   r8   r6   r   open_uniform_kernellogmultiplyadd)r0   r   rw   r6   r=   rx   r7   s          r   logisticRandomState.logistic$  s     \\#&U(;U<>>#-33DJJT/..($$W01WMaA&Qr   c                &   SSK Jn  [        S X4 5       5      (       a(  U R                  XX45      n[        R
                  " XfS9  U$ Uc  Sn[        U5      nUR                  S:X  a  UR                  nOUR                  nU R                  XsXAU5      $ )zReturns an array of samples drawn from a log normal distribution.

.. seealso::
    - :func:`cupy.random.lognormal` for full documentation
    - :meth:`numpy.random.RandomState.lognormal`

r   r!   c              3  V   #    U  H  n[        U[        R                  5      v   M!     g 7fr   )rh   rB   ndarray).0args     r   	<genexpr>(RandomState.lognormal.<locals>.<genexpr>A  s     Fz#t||,,s   ')r    r   )r#   r"   rs   normalrB   exp_check_and_get_dtypechargenerateLogNormalgenerateLogNormalDoublerK   )r0   meansigmar6   r=   r"   rx   rG   s           r   	lognormalRandomState.lognormal7  s     	3FFFFD5AHHQH<D$U+::++D11D$$TeDDr   c                   [         R                  " U5      n[         R                  " US:*  5      (       a  [        S5      e[         R                  " US:  5      (       a  [        S5      eUc  UR                  n[         R
                  " X#S9nU R                  UR                  5      n[        R                  " XU5        U$ )zReturns an array of samples drawn from a log series distribution.

.. warning::

    This function may synchronize the device.

.. seealso::
    - :func:`cupy.random.logseries` for full documentation
    - :meth:`numpy.random.RandomState.logseries`

r   zp <= 0.0r>   zp >= 1.0rN   )
rB   rP   rs   rt   rO   rC   r8   r6   r   logseries_kernelr   s         r   	logseriesRandomState.logseriesN  s     LLO88AFZ((88AFZ((<77DJJT/..(!!!a0r   ignoreg:0yE>choleskyc           
     b	   [         R                  " S5        [        R                  " XS9n[        R                  " X'S9nUc  / nO+[	        U[
        [        R                  45      (       a  U/nOUn[        UR                  5      S:w  a  [        S5      e[        UR                  5      S:w  d   UR                  S   UR                  S   :w  a  [        S5      eUR                  S   UR                  S   :w  a  [        S	5      e[        USS 5      n	U	R                  UR                  S   5        US
;  a  [        S5      eUS:w  a  US:w  a  US:w  a  [        S5      eUS:X  a=  [        R                  SS9    [        R                  R                  U5      n
SSS5        O[        R                  US9    US:X  a   [        R                  R                  U5      n
OUS:X  aO  [        R                  R#                  U5      u  pU[        R.                  " [        R0                  " U5      5      -  n
OUUS:X  aO  [        R                  R'                  U5      u  pnU[        R.                  " [        R0                  " U5      5      -  n
SSS5        U R9                  U	US9R;                  SUR                  S   5      n[        R*                  " W
UR,                  5      nUR,                  nX-  n[=        U	5      Ul        U$ ! [          Gai    [        R                  SS9   US:w  a  US:X  a?  [        R                  R#                  U5      u  p[        R$                  " X* :  5      (       + nUS:X  aZ  [        R                  R'                  U5      u  pn[        R(                  " [        R*                  " UR,                  U-  U5      X%US9nW[        R.                  " [        R0                  " W5      5      -  n
W(       d  [2        R4                  " S[6        5        O:[2        R4                  " S[6        5        [        R                  R                  U5      n
SSS5         GM  ! , (       d  f        GN= ff = f! , (       d  f       GN= f! [          a    [!        S5      ef = f! , (       d  f       GN!= f)a  Returns an array of samples drawn from the multivariate normal
distribution.

.. warning::
    This function calls one or more cuSOLVER routine(s) which may yield
    invalid results if input conditions are not met.
    To detect these invalid results, you can set the `linalg`
    configuration to a value that is not `ignore` in
    :func:`cupyx.errstate` or :func:`cupyx.seterr`.

.. seealso::
    - :func:`cupy.random.multivariate_normal` for full documentation
    - :meth:`numpy.random.RandomState.multivariate_normal`
z+cupy.random.RandomState.multivariate_normalr<   Nr>   zmean must be 1 dimensionalr;   r   z$cov must be 2 dimensional and squarez"mean and cov must have same length>   svdeighr   z1method must be one of {'eigh', 'svd', 'cholesky'}r   warnraisez3check_valid must equal 'warn', 'raise', or 'ignore')linalgr   r   r   )rtolatolz?covariance is not positive-semidefinite, output may be invalid.z=covariance is not positive-semidefinite, output *is* invalid.z_Matrix is not positive definite; if matrix is positive-semidefinite, set'check_valid' to 'warn're   )r
   experimentalrB   rP   rh   ri   rj   lenrO   rt   listappendr   errstater   r   r   r   rs   r   allclosedotTsqrtabswarningsr   RuntimeWarningstandard_normalrF   tuple)r0   r   covr6   check_validtolr.   r=   rO   final_shapedecompsupsdvhrx   s                   r   multivariate_normalRandomState.multivariate_normalf  s     	HI||D.ll3,<EsDLL122FEEtzz?a9::		NaSYYq\SYYq\%ACDD::a=CIIaL(ABB58n4::a=)44CE E ("f$)? IK K & w/?![[11#6F 0/4 {3A+!%!5!5c!:6)!%!1!1#!6!"TYYtxx{%;!;5%)[[__S%9
r!"TYYtxx{%;!; 4    ', ! ..5gb$**Q-.H 	
HHVQSS!CC		$[ # ?x8!Z/%/)-)9)9#)>*.((1t8*<&<%-1[[__S-A
r&*mmDHHRTTAXr4J47'M%&488A;)?%?F#& ( /9:H!J
 %MM +56DF &*[[%9%9#%>F' 9888? 0/J # A% '@ A AA 43s   6Q48K=3R5%RRAR/R0AR=Q1D6QQ1Q4
Q-'Q1*Q4-Q11Q44
RRR
R.c                   [         R                  " U5      n[         R                  " U5      n[         R                  " US:*  5      (       a  [        S5      e[         R                  " US:  5      (       a  [        S5      e[         R                  " US:  5      (       a  [        S5      eU R	                  USU-
  U-  U5      nU R                  XTS9$ )a  Returns an array of samples drawn from the negative binomial distribution.

.. warning::

    This function may synchronize the device.

.. seealso::
    - :func:`cupy.random.negative_binomial` for full documentation
    - :meth:`numpy.random.RandomState.negative_binomial`
r   zn <= 0zp < 0r>   zp > 1r<   )rB   rP   rs   rt   r   poisson)r0   rZ   r[   r6   r=   rU   s         r   negative_binomialRandomState.negative_binomial  s     LLOLLO88AFX&&88AE??W%%88AE??W%%JJq1Q3'4(||A|++r   c                8   SSK Jn  [        U5      nUc   [        R                  " X5      R
                  nUR                  S:X  a  UR                  nOUR                  n[        U[        R                  5      (       a@  U R                  XcUSS5      n[        R                  " XrUS9  [        R                  " XqUS9  U$ [        U[        R                  5      (       a+  U R                  XcUSU5      n[        R                  " XqUS9  U$ U R                  XcXAU5      nU$ )zReturns an array of normally distributed samples.

.. seealso::
    - :func:`cupy.random.normal` for full documentation
    - :meth:`numpy.random.RandomState.normal`

r   r!   r   r   rp   r   )r#   r"   r   rB   rQ   rO   r   generateNormalgenerateNormalDoublerh   r   rK   r   r   )r0   r   rw   r6   r=   r"   rG   rx   s           r   r   RandomState.normal  s     	3$U+<>>#-33D::((D..DeT\\**%%d%cBAMM!*HHQ#  T\\**%%d%eDAHHQ#  %%d%eDAr   c                    [         R                  " U5      nUc  UR                  nU R                  X#5      n[         R                  " XDS9  [         R
                  " U* U-  US9  US-
  $ )zReturns an array of samples drawn from the pareto II distribution.

.. seealso::
    - :func:`cupy.random.pareto` for full documentation
    - :meth:`numpy.random.RandomState.pareto`
r   r>   )rB   rP   rO   r   r   r   r0   rS   r6   r=   rx   s        r   paretoRandomState.pareto  sX     LLO<77D##D0!A11ur   c                   [         R                  " U5      [         R                  " U5      p![         R                  " US:*  5      (       a  [        S5      e[         R                  " US:  5      (       a  [        S5      eUc   [         R                  " X5      R
                  n[         R                  " X4S9nU R                  UR                  5      n[        R                  " XXe5        U$ )a  Returns an array of samples drawn from the noncentral chi-square
distribution.

.. warning::

    This function may synchronize the device.

.. seealso::
    - :func:`cupy.random.noncentral_chisquare` for full documentation
    - :meth:`numpy.random.RandomState.noncentral_chisquare`
r   zdf <= 0nonc < 0rN   )rB   rP   rs   rt   rQ   rO   rC   r8   r6   r   noncentral_chisquare_kernel)r0   ra   noncr6   r=   rU   r7   s          r   noncentral_chisquare RandomState.noncentral_chisquare  s     <<#T\\$%7D88B!GY''88D1HZ((<>>"+11DJJT/..(,,RwBr   c                T   [         R                  " U5      [         R                  " U5      [         R                  " U5      p2n[         R                  " US:*  5      (       a  [        S5      e[         R                  " US:*  5      (       a  [        S5      e[         R                  " US:  5      (       a  [        S5      eUc!  [         R                  " XU5      R
                  n[         R                  " XES9nU R                  UR                  5      n[        R                  " XX7U5        U$ )a  Returns an array of samples drawn from the noncentral F distribution.

.. warning::

    This function may synchronize the device.

.. seealso::
    - :func:`cupy.random.noncentral_f` for full documentation
    - :meth:`numpy.random.RandomState.noncentral_f`
r   z
dfnum <= 0z
dfden <= 0r   rN   )rB   rP   rs   rt   rQ   rO   rC   r8   r6   r   noncentral_f_kernel)r0   r}   r~   r   r6   r=   rU   r7   s           r   noncentral_fRandomState.noncentral_f  s     LLe!4dll46H 88EQJ\**88EQJ\**88D1HZ((<>>%5;;DJJT/..($$U4!Dr   c                    [         R                  " U5      nUc  UR                  n[         R                  " X#S9nU R	                  UR
                  5      n[        R                  " XU5        U$ )zReturns an array of samples drawn from the poisson distribution.

.. seealso::
    - :func:`cupy.random.poisson` for full documentation
    - :meth:`numpy.random.RandomState.poisson`
rN   )rB   rP   rO   rC   r8   r6   r   poisson_kernel)r0   lamr6   r=   rU   r7   s         r   r   RandomState.poisson9  sU     ll3<99DJJT/..(a0r   c                L   [         R                  " U5      n[         R                  " US:  5      (       a  [        S5      eUc  UR                  nU R                  X#S9n[         R                  " U* US9  [         R                  " SU* US9  [         R                  " USU-  US9  U$ )zReturns an array of samples drawn from the power distribution.

.. warning::

    This function may synchronize the device.

.. seealso::
    - :func:`cupy.random.power` for full documentation
    - :meth:`numpy.random.RandomState.power`
r   a < 0r6   r=   r   r>   rp   )	rB   rP   rs   rt   rO   ru   r   r   powerr   s        r   r   RandomState.powerH  s     LLO88AE??W%%<77D%%4%=!QBA

1bd"r   c                    UR                  S[        5      nU(       a+  [        SSR                  UR	                  5       5      -  5      eU R                  XS9$ )zReturns uniform random values over the interval ``[0, 1)``.

.. seealso::
    - :func:`cupy.random.rand` for full documentation
    - :meth:`numpy.random.RandomState.rand`

r=   z*rand() got unexpected keyword arguments %s, r   )popr   	TypeErrorjoinkeysrandom_sampler0   r6   kwargr=   s       r   randRandomState.rand^  sR     		'5)H"ii

56 7 7!!t!99r   c                    UR                  S[        5      nU(       a+  [        SSR                  UR	                  5       5      -  5      eU R                  XS9$ )zReturns an array of standard normal random values.

.. seealso::
    - :func:`cupy.random.randn` for full documentation
    - :meth:`numpy.random.RandomState.randn`

r=   z+randn() got unexpected keyword arguments %sr   r   )r   r   r   r   r   r   r  s       r   randnRandomState.randnl  sO     		'5)I"ii

56 7 7{{{22r    zT xzx = (x == (T)1) ? 0 : xcupy_random_x_mod_1c                T   SSK Jn  [        U5      n[        R                  " XS9nUR
                  S:X  a  UR                  nOUR                  nU R                     U" U R                  UR                  R                  UR                  5        S S S 5        U$ ! , (       d  f       U$ = f)Nr   r!   r<   r   )r#   r"   r   rB   rC   r   generateUniformgenerateUniformDoubler'   r)   rD   rE   r6   )r0   r6   r=   r"   rJ   rG   s         r   r   RandomState._random_sample_raw}  sy    2$U+jj+::))D//DZZ#((,,9 
 Z
s   3B
B'c                \    Uc  SnU R                  X5      n[        R                  U5        U$ )zReturns an array of random values over the interval ``[0, 1)``.

.. seealso::
    - :func:`cupy.random.random_sample` for full documentation
    - :meth:`numpy.random.RandomState.random_sample`

r   )r   r   _mod1_kernel)r0   r6   r=   rJ   s       r   r   RandomState.random_sample  s1     <D%%d2  %
r   c                j   [         R                  " U5      nUc  UR                  n[         R                  " US:  5      (       a  [	        S5      eU R                  X#5      n[         R                  " XDS9n[         R                  " USUS9n[         R                  " XDS9n[         R                  " XAUS9nU$ )zReturns an array of samples drawn from a rayleigh distribution.

.. warning::

    This function may synchronize the device.

.. seealso::
    - :func:`cupy.random.rayleigh` for full documentation
    - :meth:`numpy.random.RandomState.rayleigh`
r   rr   r   g       )	rB   rP   rO   rs   rt   r   r   r   r   rv   s        r   rayleighRandomState.rayleigh  s     U#<;;D88EAI[))##D0HHQMM!Sa(IIaMM!*r   zT max, T mxzT outz3out = max - (mx != max ? (max - mx) % (mx + 1) : 0) cupy_random_interval_upper_limitzT samplez$if (mx != max) { sample %= mx + 1; }"cupy_random_interval_sample_moduloc                h   Uc  SnO[        U[        5      (       a  U4n[        R                  " U5      nU(       a  US:X  a#  [        R
                  " U[        R                  S9$ US:  a  [        SR                  U5      5      eU[        ::  a'  [        R                  nU" [        SUS-   -  -
  5      nGO.U[        ::  a&  [        R                  nU" [        SUS-   -  -
  5      nO[        S	R                  U5      5      eUR                  nU[        R                  :X  d  U[        R                  :X  a7  [        R                  nUR                  US
S9nU R                  [        U5      nOyU[        R                   :X  d  U[        R                  :X  a7  [        R                  nUR                  US
S9nU R                  [        U5      nO[        SR                  U5      5      e["        R$                  " [&        R(                  US5      nUS:X  a  [        R*                  " X$S9$ U R-                  Xd5      nU(       aJ  US-   nUSUR/                  5       S-
  -  :X  a+  SUR/                  5       -  S-
  n	Xy-  nUR1                  U5      $ U R3                  XuS
5      n
U
R4                  nUS:  a  [        R                  " U5      (       d  XZ   nUS:  a  U(       a  [7        US-  S5      OUR4                  nU R-                  X5      nU R3                  XS5      nUR4                  nX:  a  XSU    Xz'   SnOX   XzSU '   XS n
U(       d  X_S nX-  nUS:  a  M  U(       a  UW-  nOAU[        R                  :X  a  U R9                  [        X5      nOU R9                  [        X5      nUR1                  U5      $ )a   Generate multiple integers independently sampled uniformly from ``[0, mx]``.

Args:
    mx (int): Upper bound of the interval
    size (None or int or tuple): Shape of the array or the scalar
        returned.
Returns:
    int or cupy.ndarray: If ``None``, an :class:`cupy.ndarray` with
    shape ``()`` is returned.
    If ``int``, 1-D array of length size is returned.
    If ``tuple``, multi-dimensional array with shape
    ``size`` is returned.
    Currently, only 32 bit or 64 bit integers can be sampled.
Nr   r   r<   z$mx must be non-negative (actual: {})        r>               z+mx must be within uint64 range (actual: {})Fcopyzdtype must be integer, got: {}r;   i   T)rh   ri   numpyisscalarrB   zerosuint32rt   format_UINT32_MAXr5   uint64r=   int32astype_interval_upper_limitint64	functoolsreduceoperatormulrC   _curand_generate
bit_lengthrF   _get_indicesr6   max_interval_sample_modulo)r0   mxr6   is_mx_scalarr=   upper_limitn_samplesamplemx1mask
ng_indicesn_ngn_supplement
supplement
ok_indicesn_oks                   r   	_intervalRandomState._interval  sU    <Dc""5D~~b)Qwzz$ell;;Av :AA"EG G{"#K7rAv2F$FG{"#K7rAv2F$FG AHHLN N HHE

"et{{&:YYu5Y1"88bI$**$(<YYu5Y1"88bI 4;;EBD D ##HLL$:q=::d00&&x7q&CaCNN,q011R]]_,1~~d++ &&vEB
!8ENN2..%1KQh+  q$/1<1A1A ..|CJ **:DIJ??D |%/5D0A%B",6,B%4()'.
#"-e"4K% Qh( cMFdkk!11+rJF11+rJF~~d##r   c                <   SSK Jn  [        R                  " U4US9nUR	                  [
        R                  S9R                  nU R                     UR                  U R                  UR                  R                  U5        S S S 5        U$ ! , (       d  f       U$ = f)Nr   r!   r<   )r#   r"   rB   rC   viewr  r  r6   r'   generater)   rD   rE   )r0   numr=   r"   r3  size32s         r   r*  RandomState._curand_generate  sk    2SF%05<<055ZZOODOOV[[__fE  Zs   2B
Bc                &   UR                   S:  a  [        R                  O[        R                  nU(       a  X:*  OX:  n[        R
                  " XTS9nA[        R                  " [        US   5      4US9nU R                  XgUR                   S9  U$ )Nr  r<   re   r6   )	r6   r  r  r!  rB   cumsumrC   ri   _kernel_get_indices)r0   r3  r1  condr=   flagscsumindicess           r   r,  RandomState._get_indices&  ss     &e 3+/&f6J{{5.**c$r(m-U;  TYY ?r   z
raw U csumzraw U indiceszo
        int j = 0;
        if (i > 0) { j = csum[i-1]; }
        if (csum[i] > j) { indices[j] = i; }
        cupy_get_indicesc                R   SSK Jn  Uc8   [        R                  " [        R
                  " S5      5      n[        US5      nO[        U[        R                  5      (       a1  [        [        R                  " USS9R                  5       SS S5      nO][        R                   " U5      nUR"                  R$                  S	;  a  ['        S
5      e[        U5      nUS:  d  US:  a  [)        S5      eU R*                     UR-                  U R.                  U5        U R0                  UR2                  UR4                  4;  a  UR7                  U R.                  S5        Xl        SSS5        g! [         a"    [        R                  " 5       S-  [        -  n Nf = f! , (       d  f       g= f)zResets the state of the random number generator with a seed.

.. seealso::
    - :func:`cupy.random.seed` for full documentation
    - :meth:`numpy.random.RandomState.seed`

r   r!   N      i@B F)usedforsecuritybiuzSeed must be an integer.r  z/Seed must be an integer between 0 and 2**64 - 1)r#   r"   binasciihexlifyosurandomri   NotImplementedErrortimer5   rh   r  r   hashlibmd5	hexdigestrP   r=   kindr   rt   r'   setPseudoRandomGeneratorSeedr)   r.   CURAND_RNG_PSEUDO_MT19937CURAND_RNG_PSEUDO_MTGP32setGeneratorOffsetr4   )r0   r/   r"   seed_strseed_arrs        r   r/   RandomState.seed8  s\    	3<=#++BJJqM:8R( $..7;;%11:SbBCEG !==.>>&&e3#$>??8}!8tu}$IK K ZZ//FF$D$D$*$C$C$E E))$//1= M Z! ' =		g-<=  Zs   6E) ;A%F))FF
F&c                t    U R                  XS9n[        R                  " [        R                  US-
  -  5      $ )zReturns an array of samples drawn from the standard cauchy distribution.

.. seealso::
    - :func:`cupy.random.standard_cauchy` for full documentation
    - :meth:`numpy.random.RandomState.standard_cauchy`
r   g      ?)uniformrB   tanpir0   r6   r=   rx   s       r   standard_cauchyRandomState.standard_cauchy]  s0     LLdL0xx1s7+,,r   c                X    Uc  SnU R                  X5      n[        R                  " X3S9* $ )zReturns an array of samples drawn from the standard exp distribution.

.. seealso::
   - :func:`cupy.random.standard_exponential` for full documentation
   - :meth:`numpy.random.RandomState.standard_exponential`
r   r   )r   rB   r   rh  s       r   ru    RandomState.standard_exponentialg  s0     <D##D0"""r   c                    [         R                  " U5      nUc  UR                  n[         R                  " X#S9nU R	                  UR
                  5      n[        R                  " XU5        U$ )zReturns an array of samples drawn from a standard gamma distribution.

.. seealso::
    - :func:`cupy.random.standard_gamma` for full documentation
    - :meth:`numpy.random.RandomState.standard_gamma`
rN   )rB   rP   rO   rC   r8   r6   r   rk   )r0   rO   r6   r=   rU   r7   s         r   standard_gammaRandomState.standard_gammas  sU     U#<;;DJJT/..(&&uq9r   c                     U R                  XS9$ )zReturns samples drawn from the standard normal distribution.

.. seealso::
    - :func:`cupy.random.standard_normal` for full documentation
    - :meth:`numpy.random.RandomState.standard_normal`

r   )r   )r0   r6   r=   s      r   r   RandomState.standard_normal  s     {{{22r   c                    [         R                  " U5      nUc  UR                  n[         R                  " X#S9nU R	                  UR
                  5      n[        R                  " XU5        U$ )zReturns an array of samples drawn from the standard t distribution.

.. seealso::
    - :func:`cupy.random.standard_t` for full documentation
    - :meth:`numpy.random.RandomState.standard_t`
rN   )rB   rP   rO   rC   r8   r6   r   standard_t_kernelr`   s         r   
standard_tRandomState.standard_t  sU     \\"<88DJJT/..(""22r   c                   SSK Jn  Uc  Sn[        R                  " U[        R                  S9nUR
                  R                  S-  nU R                     UR                  U R                  UR                  R                  UR                  U-  5        SSS5        U[        R                  " [        R                  5      R                  -  nU$ ! , (       d  f       NA= f)a  Draws integers between 0 and max integer inclusive.

Return a sample of uniformly distributed random integers in the
interval [0, ``np.iinfo(np.int_).max``]. The `np.int_` type translates
to the C long integer type and its precision is platform dependent.

Args:
    size (int or tuple of ints): Output shape.

Returns:
    cupy.ndarray: Drawn samples.

.. seealso::
    :meth:`numpy.random.RandomState.tomaxint`

r   r!   Nr   r<      )r#   r"   rB   rC   int_r=   itemsizer'   r@  r)   rD   rE   r6   iinfor-  )r0   r6   r"   r3  size_in_ints        r   tomaxintRandomState.tomaxint  s    " 	3<DD		2ll++q0ZZOO&++2KM 
 	$**TYY'+++ Zs   ?C
CzL left, M mode, R righta  
        T base, leftbase, ratio, leftprod, rightprod;

        base = right - left;
        leftbase = mode - left;
        ratio = leftbase / base;
        leftprod = leftbase*base;
        rightprod = (right - mode)*base;

        if (x <= ratio)
        {
            x = left + sqrt(x*leftprod);
        } else
        {
            x = right - sqrt((1.0 - x) * rightprod);
        }
        cupy_triangular_kernelc                   [         R                  " U5      [         R                  " U5      [         R                  " U5      p2n[         R                  " X:  5      (       a  [        S5      e[         R                  " X#:  5      (       a  [        S5      e[         R                  " X:H  5      (       a  [        S5      eUc!  [         R                  " XU5      R
                  nU R                  XES9n[        R                  XX65      $ )zReturns an array of samples drawn from the triangular distribution.

.. warning::

    This function may synchronize the device.

.. seealso::
    - :func:`cupy.random.triangular` for full documentation
    - :meth:`numpy.random.RandomState.triangular`
zleft > modezmode > rightzleft == rightr   )	rB   rP   rs   rt   rQ   rO   r   r   _triangular_kernel)r0   leftmoderightr6   r=   rx   s          r   
triangularRandomState.triangular  s     LLT 2DLL4G 88DK  ]++88DL!!^,,88DM""_--<>>$e4::DD6--d%CCr   zT low, T highzx = T(low) + x * T(high - low)
cupy_scalec                   [         R                  " U5      (       d  [        R                  " X5      n[         R                  " U5      (       d  [        R                  " X$5      nUc   [        R                  " X5      R
                  n[         R                  " U5      nU R                  X4S9n[        R                  XU5      $ )zReturns an array of uniformly-distributed samples over an interval.

.. seealso::
    - :func:`cupy.random.uniform` for full documentation
    - :meth:`numpy.random.RandomState.uniform`

r   )
r  r  rB   rP   rQ   rO   r=   r   r   _scale_kernel)r0   lowhighr6   r=   r  s         r   re  RandomState.uniform  s     ~~c"",,s*C~~d##<<,D<>>#,22DE"!!t!9((D99r   c                .   [         R                  " U5      [         R                  " U5      p!Uc   [         R                  " X5      R                  n[         R                  " X4S9nU R                  UR                  5      n[        R                  " XXe5        U$ )zReturns an array of samples drawn from the von Mises distribution.

.. seealso::
    - :func:`cupy.random.vonmises` for full documentation
    - :meth:`numpy.random.RandomState.vonmises`
rN   )	rB   rP   rQ   rO   rC   r8   r6   r   vonmises_kernel)r0   mukappar6   r=   rU   r7   s          r   vonmisesRandomState.vonmises  sk     LL$dll5&9E<>>",22DJJT/..(  G7r   zT mean, T scale, T UzT Xa	  
            T mu_2l;
            T Y;
            mu_2l = mean / (2*scale);
            Y = mean*X*X;
            X = mean + mu_2l*(Y - sqrt(4*scale*Y + Y*Y));
            if (U > mean/(mean+X))
            {
                X = mean*mean/X;
            }
        cupy_wald_scalec                    [         R                  " XS9[         R                  " X$S9p!Uc   [         R                  " X5      R                  nU R	                  X4S9nU R                  X4S9n[        R                  XXe5      $ )zReturns an array of samples drawn from the Wald distribution.

.. seealso::
   - :func:`cupy.random.wald` for full documentation
   - :meth:`numpy.random.RandomState.wald`
r<   r   )rB   rP   rQ   rO   r   r   r   _wald_kernel)r0   r   rw   r6   r=   rx   r   s          r   waldRandomState.wald   so     LL+T\\%-M <>>$.44DKKTK/D6''Q::r   c                    [         R                  " U5      n[         R                  " US:  5      (       a  [        S5      eUc  UR                  nU R                  X#5      n[         R                  " USU-  US9  U$ )zReturns an array of samples drawn from the weibull distribution.

.. warning::

    This function may synchronize the device.

.. seealso::
    - :func:`cupy.random.weibull` for full documentation
    - :meth:`numpy.random.RandomState.weibull`
r   r   rp   r   )rB   rP   rs   rt   rO   ru   r   r   s        r   weibullRandomState.weibull/  sd     LLO88AE??W%%<77D%%d2

1bd"r   c                .   [         R                  " U5      n[         R                  " US:*  5      (       a  [        S5      eUc  UR                  n[         R
                  " X#S9nU R                  UR                  5      n[        R                  " XU5        U$ )zReturns an array of samples drawn from the Zipf distribution.

.. warning::

    This function may synchronize the device.

.. seealso::
    - :func:`cupy.random.zipf` for full documentation
    - :meth:`numpy.random.RandomState.zipf`
rp   z'a' must be a valid float > 1.0rN   )
rB   rP   rs   rt   rO   rC   r8   r6   r   zipf_kernel)r0   rS   r6   r=   rU   r7   s         r   zipfRandomState.zipfE  ss     LLO88AH@AA<77DJJT/..(Q+r   c                   Uc  [        S5      e[        U[        R                  5      (       a  UR                  S:X  a  [
        e[        U[        5      (       a  UnUS:  a  [        S5      eO;[        R                  " USS9nUR                  S:w  a  [        S5      e[        U5      nUb  [        R                  " U5      nUR                  S:w  a  [        S5      e[        U5      U:w  a  [        S	5      eUS:  R                  5       (       d  [        S
5      e[        R                  " U5      R                  5       n[        R                  " US5      (       d  [        S5      eUc  [        S5      eUn [        R                  R!                  U5      nUS:X  a  US:  a  [        S5      eU(       d  Uc  XR:  a  [        S5      e[        U[        5      (       a  [$        R&                  nU R)                  U5      n	[        R*                  R-                  U	5      n
U
R/                  S[0        S-   U[        R2                  S9n[%        X[5      nU" U5      nUR5                  U5      $ UR7                  5       nU R9                  U5        USU R5                  U5      $ U(       d  [
        eUb9  UR;                  5       nXS   -  nU R=                  U5      nUR?                  USS9nO6US:X  a  SnU RA                  SXWS9nURC                  [        RD                  SS9n[        U[        5      (       a  U$ UR                  S:X  a"  [        R                  " UU   URF                  S9$ UU   $ ! ["         a     GNf = f)zReturns an array of random values from a given 1-D array.

.. seealso::
    - :func:`cupy.random.choice` for full documentation
    - :meth:`numpy.random.choice`

Nz%a must be 1-dimensional or an integerr   z$a must be greater than or equal to 0Fr  r>   zp must be 1-dimensionalza and p must have same sizez"probabilities are not non-negativezprobabilities do not sum to 1z5choice() without specifying size is not supported yetz-a cannot be empty unless no samples are takenz@Cannot take a larger sample than population when 'replace=False'r   re   r  )siderE  r<   )$rt   rh   rB   r   ndimrW  ri   arrayr   allrl   getr  r   r   r@   rA   r   r	   
num_roundsr8   randomdefault_rngintegersr   r  rF   r  shufflerF  r   searchsortedrandintr#  r%  r=   )r0   rS   r6   replacer[   a_sizep_sumrO   n_roundsr7   rngr   	bijectionrK  cdfuniform_samplesindexs                    r   choiceRandomState.choiceZ  s    9DEEa&&166Q;%%aFz !GHH  

15)Avv{ !HIIVF=

1Avv{ !:;;1v !>??F<<>> !EFFHHQKOO%E>>%++ !@AA<%GI I	>>&&u-D
 Q;4!8LMM19} () ) !S!!+66..2ll..w7||{QXU\\ $ K,V:	#D/u--&&(W%u~--e44%%=((*Cr7NC"007O$$_7$CE{LLFL7ELL%L8EaL::?::ahagg66xe  		s   5M' '
M54M5c                    [        U[        R                  5      (       d  [        S5      eUR                  S:X  a  [        S5      eXR                  [        U5      5         USS& g)zReturns a shuffled array.

.. seealso::
    - :func:`cupy.random.shuffle` for full documentation
    - :meth:`numpy.random.shuffle`

zThe array must be cupy.ndarrayr   z)An array whose ndim is 0 is not supportedN)rh   rB   r   r   r  _permutationr   r0   rS   s     r   r  RandomState.shuffle  sS     !T\\**<==66Q;GHH""3q6*+!r   c                    [        U[        5      (       a  U R                  U5      $ XR                  [        U5      5         $ )z6Returns a permuted range or a permutation of an array.)rh   ri   r  r   r  s     r   permutationRandomState.permutation  s8    a$$Q''&&s1v.//r   c                4   SSK Jn  [        R                  " U4[        R
                  S9nU R                     UR                  U R                  UR                  R                  U5        SSS5        [        R                  " U5      nU$ ! , (       d  f       N&= f)zReturns a permuted range.r   r!   r<   N)r#   r"   rB   rC   r  r"  r'   r@  r)   rD   rE   argsort)r0   rA  r"   r3  r  s        r   r  RandomState._permutation  s^    2SF%++6ZZOODOOV[[__cB V$ Zs   2B		
Bz$y = T(loc) - log(-log(x)) * T(scale)cupy_gumbel_kernelc                Z   [         R                  " U5      (       d  [        R                  " X5      n[         R                  " U5      (       d  [        R                  " X$5      nUc   [        R                  " X5      R
                  nU R                  X4S9n[        R                  XQX%5        U$ )zReturns an array of samples drawn from a Gumbel distribution.

.. seealso::
    - :func:`cupy.random.gumbel` for full documentation
    - :meth:`numpy.random.RandomState.gumbel`
r   )	r  r  rB   rP   rQ   rO   r   r   _gumbel_kernelr   s         r   gumbelRandomState.gumbel  s     ~~c"",,s*C~~e$$LL.E<>>#-33D###;""154r   c                   [         R                  " U5      (       Gd  [        R                  " U5      nUc  [        R                  " U5      nUS-
  nOUn[        R                  " U5      S-
  nUc   [        R
                  " XV5      R                  nXe-
  n[        R                  " [        R                  US5      nU R                  UR                  5       U5      n	U	R                  U5      n	[        R                  " X5      n	UR                  USS9n[        R                  " XU	S9  U	$ Uc  Sn[!        U5      S-
  n
O[!        U5      n[!        U5      S-
  n
XZ:  a  [#        S5      eU[        R$                  " U5      R&                  :  a8  [#        SR)                  [        R*                  " U5      R,                  5      5      eU
[        R$                  " U5      R.                  :  a8  [#        SR)                  [        R*                  " U5      R,                  5      5      eX-
  nU R                  Xs5      R                  USS9n[        R                  " XUS9  U$ )	zReturns a scalar or an array of integer values over ``[low, high)``.

.. seealso::
    - :func:`cupy.random.randint` for full documentation
    - :meth:`numpy.random.RandomState.randint`
r>   Fr  r   r   zlow >= highzlow is out of bounds for {}zhigh is out of bounds for {})r  r  rB   rP   
zeros_likerQ   rO   r&  r'  r(  r)  r<  flattenr#  rF   r   ri   rt   rz  minr  r=   r   r-  )r0   r  r  r6   r=   lohidifftotal_elemsrJ   hi1rx   s               r   r  RandomState.randint  s    ~~c"",,s#C|__S)1W\\$'!+|~~b-337D#**8<<qAK..=C**U#C,,s)C5u-BHHS#&J|#hlX$i!mx //DJJu%))) 188

5)..01 1 TZZ&*** 299

5)..01 1 8Dt*11%e1DAHHQ"Hr   )r-   r)   r'   r4   r.   )NN)Nl)rp   Nr  r   )NTN)F__name__
__module____qualname____firstlineno____doc__r1   r8   rK   r   rV   ri   r\   rb   rn   ry   r   r   r   r   r   ElementwiseKernelr   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r   r  r$  r.  r<  r*  r,  rG  r/   ri  ru   rn  r   rt  r|  r  r  r  re  r  r  r  r  r  r  r  r  r  r  r  r  __static_attributes__r   r   r   r   r   .   s-   4 4* #%  #'c  "&U  %) ( !$$e ( $(u  "%4u  0 --uHO
 St5  cE & !$e E.0 37H %j^@ ,0s ,, Cd% 8 "  37e 0 59 4 ! ,:3 **
E,.CEL "&U  !t5 . "33w=*,
 $55z.,.
a$F  11o	
 	#!J $(u - )-E 
# *.U  $(u 3 #'e @ 00!5	" 	!', 26U D0 ++(M
 Cd% :( (,5  **
	 	L &* ; #% ,  s *Zx, 0 ,,u.N
 Cd% " !%4s 1r   r   c                6    [        5       R                  U 5        g)a  Resets the state of the random number generator with a seed.

This function resets the state of the global random number generator for
the current device. Be careful that generators for other devices are not
affected.

Args:
    seed (None or int): Seed for the random number generator. If ``None``,
        it uses :func:`os.urandom` if available or :func:`time.time`
        otherwise. Note that this function does not support seeding by
        an integer array.

N)get_random_stater/   )r/   s    r   r/   r/   !  s     D!r   c                     0 q g r   )_random_statesr   r   r   reset_statesr  7  s	     Nr   c                 <   [         R                  " 5       n [        R                  U R                  S5      nUcc  [
        R                  " S5      nUb  [        R                  " [        U5      5      n[        U5      n[        R                  U R                  U5      nU$ )a<  Gets the state of the random number generator for the current device.

If the state for the current device is not created yet, this function
creates a new one, initializes it, and stores it as the state for the
current device.

Returns:
    RandomState: The state of the random number generator for the
    device.

N	CUPY_SEED)r   Devicer  r  idrU  getenvr  r!  ri   r   
setdefault)devrsr/   s      r   r  r  =  su     ++-C			CFFD	)B	zyy%<<D	*D&&svvr2Ir   c                    [        U [        5      (       d#  [        SR                  [	        U 5      5      5      eU [
        [        R                  " 5       '   g)zSets the state of the random number generator for the current device.

Args:
    state(RandomState): Random state to set for the current device.
z;Random state must be an instance of RandomState. Actual: {}N)rh   r   r   r  typer  r   get_device_id)r  s    r   set_random_stater  T  sF     b+&&R)+ 	+ .0N6'')*r   c                h    [         R                  " U 5      n U R                  S;  a  [        S5      eU $ )N)r   dz-cupy.random only supports float32 and float64)r  r=   r   r   r<   s    r   r   r   a  s-    KKEzz#GHHLr   r   )'
__future__r   atexitrS  r&  rY  r(  rU  rX  r%   r*   r  r   numpy.linalgr   rB   r   r   	cupy.cudar   cupy.randomr   cupy.random._generator_apir	   r
   r   r   r   r   r   r5   r   r/   r  registerr  r  r  r   r   r   r   <module>r     s    "      	      $       7   
 	G  p pf'"&   
.
0r   