cuRAND
======

.. raw:: html

    <p>Provides <cite>pseudo-random number generator</cite> (PRNG) and <cite>quasi-random generator</cite> (QRNG).
    See <a class="reference external" href="http://docs.nvidia.com/cuda/curand/index.html">NVIDIA cuRAND</a>.</p>
    <div class="section" id="class-prng">
    <h2>class PRNG<a class="headerlink" href="#class-prng" title="Permalink to this headline">¶</a></h2>
    <dl class="class">
    <dt id="accelerate.cuda.rand.PRNG">
    <em class="property">class </em><code class="descclassname">accelerate.cuda.rand.</code><code class="descname">PRNG</code><span class="sig-paren">(</span><em>*args</em>, <em>**kws</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.PRNG" title="Permalink to this definition">¶</a></dt>
    <dd><p>cuRAND pseudo random number generator</p>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
    <li><strong>rndtype</strong> &#8211; Algorithm type.  All possible values are listed as
    class attributes of this class, e.g. TEST, DEFAULT,
    XORWOW, MRG32K3A, MTGP32.</li>
    <li><strong>seed</strong> &#8211; Seed for the RNG.</li>
    <li><strong>offset</strong> &#8211; Offset to the random number stream.</li>
    <li><strong>stream</strong> &#8211; CUDA stream.</li>
    </ul>
    </td>
    </tr>
    </tbody>
    </table>
    <p>Example:</p>
    <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">accelerate.cuda</span> <span class="kn">import</span> <span class="n">rand</span>
    <span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">numpy</span> <span class="kn">import</span> <span class="n">empty</span>
    <span class="gp">&gt;&gt;&gt; </span><span class="n">prng</span> <span class="o">=</span> <span class="n">rand</span><span class="o">.</span><span class="n">PRNG</span><span class="p">(</span><span class="n">rndtype</span><span class="o">=</span><span class="n">rand</span><span class="o">.</span><span class="n">PRNG</span><span class="o">.</span><span class="n">XORWOW</span><span class="p">)</span>
    <span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="n">empty</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
    <span class="gp">&gt;&gt;&gt; </span><span class="n">prng</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
    <span class="gp">&gt;&gt;&gt; </span><span class="n">r</span>
    <span class="go">array([ ... ])</span>
    </pre></div>
    </div>
    <dl class="method">
    <dt id="accelerate.cuda.rand.PRNG.lognormal">
    <code class="descname">lognormal</code><span class="sig-paren">(</span><em>ary</em>, <em>mean</em>, <em>sigma</em>, <em>size=None</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.PRNG.lognormal" title="Permalink to this definition">¶</a></dt>
    <dd><dl class="docutils">
    <dt>Generate floating point random number sampled</dt>
    <dd>from a log-normal distribution and fill into ary.</dd>
    </dl>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
    <li><strong>ary</strong> &#8211; Numpy array or cuda device array.</li>
    <li><strong>mean</strong> &#8211; Center of the distribution.</li>
    <li><strong>sigma</strong> &#8211; Standard deviation of the distribution.</li>
    <li><strong>size</strong> &#8211; Number of samples. Default to array size.</li>
    </ul>
    </td>
    </tr>
    </tbody>
    </table>
    </dd></dl>

    <dl class="method">
    <dt id="accelerate.cuda.rand.PRNG.normal">
    <code class="descname">normal</code><span class="sig-paren">(</span><em>ary</em>, <em>mean</em>, <em>sigma</em>, <em>size=None</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.PRNG.normal" title="Permalink to this definition">¶</a></dt>
    <dd><p>Generate floating point random number sampled
    from a normal distribution and fill into ary.</p>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
    <li><strong>ary</strong> &#8211; Numpy array or cuda device array.</li>
    <li><strong>mean</strong> &#8211; Center of the distribution.</li>
    <li><strong>sigma</strong> &#8211; Standard deviation of the distribution.</li>
    <li><strong>size</strong> &#8211; Number of samples. Default to array size.</li>
    </ul>
    </td>
    </tr>
    </tbody>
    </table>
    </dd></dl>

    <dl class="method">
    <dt id="accelerate.cuda.rand.PRNG.poisson">
    <code class="descname">poisson</code><span class="sig-paren">(</span><em>ary</em>, <em>lmbd</em>, <em>size=None</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.PRNG.poisson" title="Permalink to this definition">¶</a></dt>
    <dd><p>Generate floating point random number sampled
    from a poisson distribution and fill into ary.</p>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
    <li><strong>ary</strong> &#8211; Numpy array or cuda device array.</li>
    <li><strong>lmbda</strong> &#8211; Lambda for the distribution.</li>
    <li><strong>size</strong> &#8211; Number of samples. Default to array size.</li>
    </ul>
    </td>
    </tr>
    </tbody>
    </table>
    </dd></dl>

    <dl class="attribute">
    <dt id="accelerate.cuda.rand.PRNG.seed">
    <code class="descname">seed</code><a class="headerlink" href="#accelerate.cuda.rand.PRNG.seed" title="Permalink to this definition">¶</a></dt>
    <dd><p>Mutatable attribute for the seed for the RNG</p>
    </dd></dl>

    <dl class="attribute">
    <dt id="accelerate.cuda.rand.PRNG.stream">
    <code class="descname">stream</code><a class="headerlink" href="#accelerate.cuda.rand.PRNG.stream" title="Permalink to this definition">¶</a></dt>
    <dd><p>Associate a CUDA stream to the generator object.
    All subsequent calls will use this stream.</p>
    </dd></dl>

    <dl class="method">
    <dt id="accelerate.cuda.rand.PRNG.uniform">
    <code class="descname">uniform</code><span class="sig-paren">(</span><em>ary</em>, <em>size=None</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.PRNG.uniform" title="Permalink to this definition">¶</a></dt>
    <dd><dl class="docutils">
    <dt>Generate floating point random number sampled</dt>
    <dd>from a uniform distribution and fill into ary.</dd>
    </dl>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
    <li><strong>ary</strong> &#8211; Numpy array or cuda device array.</li>
    <li><strong>size</strong> &#8211; Number of samples. Default to array size.</li>
    </ul>
    </td>
    </tr>
    </tbody>
    </table>
    </dd></dl>

    </dd></dl>

    </div>
    <div class="section" id="class-qrng">
    <h2>class QRNG<a class="headerlink" href="#class-qrng" title="Permalink to this headline">¶</a></h2>
    <dl class="class">
    <dt id="accelerate.cuda.rand.QRNG">
    <em class="property">class </em><code class="descclassname">accelerate.cuda.rand.</code><code class="descname">QRNG</code><span class="sig-paren">(</span><em>*args</em>, <em>**kws</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.QRNG" title="Permalink to this definition">¶</a></dt>
    <dd><p>cuRAND quasi random number generator</p>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
    <li><strong>rndtype</strong> &#8211; Algorithm type.
    Also control output data type.
    All possible values are listed as class
    attributes of this class, e.g. TEST, DEFAULT, SOBOL32,
    SCRAMBLED_SOBOL32, SOBOL64, SCRAMABLED_SOBOL64.</li>
    <li><strong>ndim</strong> &#8211; Number of dimension for the QRNG.</li>
    <li><strong>offset</strong> &#8211; Offset to the random number stream.</li>
    <li><strong>stream</strong> &#8211; CUDA stream.</li>
    </ul>
    </td>
    </tr>
    </tbody>
    </table>
    <dl class="method">
    <dt id="accelerate.cuda.rand.QRNG.generate">
    <code class="descname">generate</code><span class="sig-paren">(</span><em>ary</em>, <em>size=None</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.QRNG.generate" title="Permalink to this definition">¶</a></dt>
    <dd><p>Generate quasi random number in ary.</p>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
    <li><strong>ary</strong> &#8211; Numpy array or cuda device array.</li>
    <li><strong>size</strong> &#8211; Number of samples;
    Default to array size.  Must be multiple of ndim.</li>
    </ul>
    </td>
    </tr>
    </tbody>
    </table>
    </dd></dl>

    <dl class="attribute">
    <dt id="accelerate.cuda.rand.QRNG.ndim">
    <code class="descname">ndim</code><a class="headerlink" href="#accelerate.cuda.rand.QRNG.ndim" title="Permalink to this definition">¶</a></dt>
    <dd><p>Mutatable attribute for number of dimension for the QRNG.</p>
    </dd></dl>

    <dl class="attribute">
    <dt id="accelerate.cuda.rand.QRNG.stream">
    <code class="descname">stream</code><a class="headerlink" href="#accelerate.cuda.rand.QRNG.stream" title="Permalink to this definition">¶</a></dt>
    <dd><p>Associate a CUDA stream to the generator object.
    All subsequent calls will use this stream.</p>
    </dd></dl>

    </dd></dl>

    </div>
    <div class="section" id="top-level-prng-functions">
    <h2>Top Level PRNG Functions<a class="headerlink" href="#top-level-prng-functions" title="Permalink to this headline">¶</a></h2>
    <p>Simple interface to the PRNG methods.</p>
    <div class="admonition note">
    <p class="first admonition-title">Note</p>
    <p class="last">This methods automatically create a PRNG object.</p>
    </div>
    <dl class="function">
    <dt id="accelerate.cuda.rand.uniform">
    <code class="descclassname">accelerate.cuda.rand.</code><code class="descname">uniform</code><span class="sig-paren">(</span><em>size</em>, <em>dtype=&lt;type 'float'&gt;</em>, <em>device=False</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.uniform" title="Permalink to this definition">¶</a></dt>
    <dd><p>Generate floating point random number sampled
    from a uniform distribution</p>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
    <li><strong>size</strong> &#8211; Number of samples.</li>
    <li><strong>dtype</strong> &#8211; np.float32 or np.float64.</li>
    <li><strong>device</strong> &#8211; Set to True to return a device array instead or numpy array.</li>
    </ul>
    </td>
    </tr>
    <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A numpy array or a device array.</p>
    </td>
    </tr>
    </tbody>
    </table>
    <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">accelerate.cuda</span> <span class="kn">import</span> <span class="n">rand</span>
    <span class="gp">&gt;&gt;&gt; </span><span class="n">rand</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
    <span class="go">array([...])</span>
    </pre></div>
    </div>
    <div class="admonition seealso">
    <p class="first admonition-title">See also</p>
    <p class="last"><a class="reference internal" href="#accelerate.cuda.rand.PRNG.uniform" title="accelerate.cuda.rand.PRNG.uniform"><code class="xref py py-meth docutils literal"><span class="pre">accelerate.cuda.rand.PRNG.uniform()</span></code></a></p>
    </div>
    </dd></dl>

    <dl class="function">
    <dt id="accelerate.cuda.rand.normal">
    <code class="descclassname">accelerate.cuda.rand.</code><code class="descname">normal</code><span class="sig-paren">(</span><em>mean</em>, <em>sigma</em>, <em>size</em>, <em>dtype=&lt;type 'float'&gt;</em>, <em>device=False</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.normal" title="Permalink to this definition">¶</a></dt>
    <dd><p>Generate floating point random number sampled
    from a normal distribution</p>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
    <li><strong>mean</strong> &#8211; Center point of the distribution.</li>
    <li><strong>sigma</strong> &#8211; Standard deviation of the distribution.</li>
    <li><strong>size</strong> &#8211; &#8212; Number of samples.</li>
    <li><strong>dtype</strong> &#8211; np.float32 or np.float64.</li>
    <li><strong>device</strong> &#8211; Set to True to return a device array instead or ndarray.</li>
    </ul>
    </td>
    </tr>
    <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A numpy array or a device array.</p>
    </td>
    </tr>
    </tbody>
    </table>
    <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">accelerate.cuda</span> <span class="kn">import</span> <span class="n">rand</span>
    <span class="gp">&gt;&gt;&gt; </span><span class="n">rand</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="n">mean</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">sigma</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
    <span class="go">array([...])</span>
    </pre></div>
    </div>
    <div class="admonition seealso">
    <p class="first admonition-title">See also</p>
    <p class="last"><a class="reference internal" href="#accelerate.cuda.rand.PRNG.normal" title="accelerate.cuda.rand.PRNG.normal"><code class="xref py py-meth docutils literal"><span class="pre">accelerate.cuda.rand.PRNG.normal()</span></code></a></p>
    </div>
    </dd></dl>

    <dl class="function">
    <dt id="accelerate.cuda.rand.lognormal">
    <code class="descclassname">accelerate.cuda.rand.</code><code class="descname">lognormal</code><span class="sig-paren">(</span><em>mean</em>, <em>sigma</em>, <em>size</em>, <em>dtype=&lt;type 'float'&gt;</em>, <em>device=False</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.lognormal" title="Permalink to this definition">¶</a></dt>
    <dd><p>Generate floating point random number sampled
    from a log-normal distribution.</p>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
    <li><strong>mean</strong> &#8211; Center point of the distribution.</li>
    <li><strong>sigma</strong> &#8211; Standard deviation of the distribution.</li>
    <li><strong>size</strong> &#8211; Number of samples.</li>
    <li><strong>dtype</strong> &#8211; np.float32 or np.float64.</li>
    <li><strong>device</strong> &#8211; set to True to return a device array instead or ndarray.</li>
    </ul>
    </td>
    </tr>
    <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A numpy array or a device array.</p>
    </td>
    </tr>
    </tbody>
    </table>
    <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">accelerate.cuda</span> <span class="kn">import</span> <span class="n">rand</span>
    <span class="gp">&gt;&gt;&gt; </span><span class="n">rand</span><span class="o">.</span><span class="n">lognormal</span><span class="p">(</span><span class="n">mean</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">sigma</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
    <span class="go">array([...])</span>
    </pre></div>
    </div>
    <div class="admonition seealso">
    <p class="first admonition-title">See also</p>
    <p class="last"><a class="reference internal" href="#accelerate.cuda.rand.PRNG.lognormal" title="accelerate.cuda.rand.PRNG.lognormal"><code class="xref py py-meth docutils literal"><span class="pre">accelerate.cuda.rand.PRNG.lognormal()</span></code></a></p>
    </div>
    </dd></dl>

    <dl class="function">
    <dt id="accelerate.cuda.rand.poisson">
    <code class="descclassname">accelerate.cuda.rand.</code><code class="descname">poisson</code><span class="sig-paren">(</span><em>lmbd</em>, <em>size</em>, <em>device=False</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.poisson" title="Permalink to this definition">¶</a></dt>
    <dd><p>Generate int32 random number sampled
    from a poisson distribution.</p>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
    <li><strong>lmbda</strong> &#8211; Lambda of the distribution.</li>
    <li><strong>size</strong> &#8211; Number of samples</li>
    <li><strong>device</strong> &#8211; Set to True to return a device array instead or ndarray.</li>
    </ul>
    </td>
    </tr>
    <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A numpy array or a device array.</p>
    </td>
    </tr>
    </tbody>
    </table>
    <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">accelerate.cuda</span> <span class="kn">import</span> <span class="n">rand</span>
    <span class="gp">&gt;&gt;&gt; </span><span class="n">rand</span><span class="o">.</span><span class="n">poisson</span><span class="p">(</span><span class="n">lmbd</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
    <span class="go">array([...], dtype=uint32)</span>
    </pre></div>
    </div>
    <div class="admonition seealso">
    <p class="first admonition-title">See also</p>
    <p class="last"><a class="reference internal" href="#accelerate.cuda.rand.PRNG.poisson" title="accelerate.cuda.rand.PRNG.poisson"><code class="xref py py-meth docutils literal"><span class="pre">accelerate.cuda.rand.PRNG.poisson()</span></code></a></p>
    </div>
    </dd></dl>

    </div>
    <div class="section" id="top-level-qrng-functions">
    <h2>Top Level QRNG Functions<a class="headerlink" href="#top-level-qrng-functions" title="Permalink to this headline">¶</a></h2>
    <p>Simple interface to the QRNG methods.</p>
    <div class="admonition note">
    <p class="first admonition-title">Note</p>
    <p class="last">This methods automatically create a QRNG object.</p>
    </div>
    <dl class="function">
    <dt id="accelerate.cuda.rand.quasi">
    <code class="descclassname">accelerate.cuda.rand.</code><code class="descname">quasi</code><span class="sig-paren">(</span><em>size</em>, <em>bits=32</em>, <em>nd=1</em>, <em>device=False</em><span class="sig-paren">)</span><a class="headerlink" href="#accelerate.cuda.rand.quasi" title="Permalink to this definition">¶</a></dt>
    <dd><p>Generate quasi random number using SOBOL{bits} RNG type.</p>
    <table class="docutils field-list" frame="void" rules="none">
    <col class="field-name" />
    <col class="field-body" />
    <tbody valign="top">
    <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
    <li><strong>size</strong> &#8211; Number of samples.</li>
    <li><strong>bits</strong> &#8211; Bit length of output element; e.g. 32 or 64.</li>
    <li><strong>nd</strong> &#8211; Number of dimension .</li>
    <li><strong>device</strong> &#8211; Set to True to return a device array instead or ndarray.</li>
    </ul>
    </td>
    </tr>
    <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A numpy array or a device array.</p>
    </td>
    </tr>
    </tbody>
    </table>
    <div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">accelerate.cuda</span> <span class="kn">import</span> <span class="n">rand</span>
    <span class="gp">&gt;&gt;&gt; </span><span class="n">rand</span><span class="o">.</span><span class="n">quasi</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
    <span class="go">array([...], dtype=uint32)</span>
    </pre></div>
    </div>
    <div class="admonition seealso">
    <p class="first admonition-title">See also</p>
    <p class="last"><a class="reference internal" href="#accelerate.cuda.rand.QRNG.generate" title="accelerate.cuda.rand.QRNG.generate"><code class="xref py py-meth docutils literal"><span class="pre">accelerate.cuda.rand.QRNG.generate()</span></code></a></p>
    </div>
    </dd></dl>

