Modified: incubator/singa/site/trunk/en/docs/tensor.html URL: http://svn.apache.org/viewvc/incubator/singa/site/trunk/en/docs/tensor.html?rev=1831260&r1=1831259&r2=1831260&view=diff ============================================================================== --- incubator/singa/site/trunk/en/docs/tensor.html (original) +++ incubator/singa/site/trunk/en/docs/tensor.html Wed May 9 15:25:26 2018 @@ -97,7 +97,7 @@ <li class="toctree-l2"><a class="reference internal" href="device.html">Device</a></li> <li class="toctree-l2 current"><a class="current reference internal" href="#">Tensor</a><ul> <li class="toctree-l3"><a class="reference internal" href="#tensor-implementation">Tensor implementation</a></li> -<li class="toctree-l3"><a class="reference internal" href="#python-api">Python API</a></li> +<li class="toctree-l3"><a class="reference internal" href="#module-singa.tensor">Python API</a></li> <li class="toctree-l3"><a class="reference internal" href="#cpp-api">CPP API</a></li> </ul> </li> @@ -210,8 +210,1496 @@ type of Device.</p> <li>âtensor_math_opencl.hâ implements operations using OpenCL for OpenclGPU devices.</li> </ul> </div> -<div class="section" id="python-api"> -<h2>Python API<a class="headerlink" href="#python-api" title="Permalink to this headline">¶</a></h2> +<div class="section" id="module-singa.tensor"> +<span id="python-api"></span><h2>Python API<a class="headerlink" href="#module-singa.tensor" title="Permalink to this headline">¶</a></h2> +<p>Example usage:</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> +<span class="kn">from</span> <span class="nn">singa</span> <span class="k">import</span> <span class="n">tensor</span> +<span class="kn">from</span> <span class="nn">singa</span> <span class="k">import</span> <span class="n">device</span> + +<span class="c1"># create a tensor with shape (2,3), default CppCPU device and float32</span> +<span class="n">x</span> <span class="o">=</span> <span class="n">tensor</span><span class="o">.</span><span class="n">Tensor</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> +<span class="n">x</span><span class="o">.</span><span class="n">set_value</span><span class="p">(</span><span class="mf">0.4</span><span class="p">)</span> + +<span class="c1"># create a tensor from a numpy array</span> +<span class="n">npy</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span> +<span class="n">y</span> <span class="o">=</span> <span class="n">tensor</span><span class="o">.</span><span class="n">from_numpy</span><span class="p">(</span><span class="n">npy</span><span class="p">)</span> + +<span class="n">y</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># sample values from the uniform distribution</span> + +<span class="n">z</span> <span class="o">=</span> <span class="n">tensor</span><span class="o">.</span><span class="n">mult</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span> <span class="c1"># gemm -> z of shape (2, 3)</span> + +<span class="n">x</span> <span class="o">+=</span> <span class="n">z</span> <span class="c1"># element-wise addition</span> + +<span class="n">dev</span> <span class="o">=</span> <span class="n">device</span><span class="o">.</span><span class="n">get_default_device</span><span class="p">()</span> +<span class="n">x</span><span class="o">.</span><span class="n">to_device</span><span class="p">(</span><span class="n">dev</span><span class="p">)</span> <span class="c1"># move the data to a gpu device</span> + +<span class="n">r</span> <span class="o">=</span> <span class="n">tensor</span><span class="o">.</span><span class="n">relu</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> + +<span class="n">s</span> <span class="o">=</span> <span class="n">tensor</span><span class="o">.</span><span class="n">to_numpy</span><span class="p">(</span><span class="n">r</span><span class="p">)</span> <span class="c1"># tensor -> numpy array</span> +</pre></div> +</div> +<p>There are two sets of tensor functions,</p> +<dl class="docutils"> +<dt>Tensor member functions</dt> +<dd>which would change the internal state of the Tensor instance.</dd> +<dt>Tensor module functions</dt> +<dd>which accept Tensor instances as arguments and return Tensor instances.</dd> +</dl> +<p>Every Tesor instance must be initialized before reading data from it.</p> +<dl class="class"> +<dt id="singa.tensor.AddBias"> +<em class="property">class </em><code class="descclassname">singa.tensor.</code><code class="descname">AddBias</code><span class="sig-paren">(</span><em>axis=0</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.AddBias" title="Permalink to this definition">¶</a></dt> +<dd><p>Add Bias to each row / column of the Tensor, depending on the parameter axis.</p> +<dl class="method"> +<dt id="singa.tensor.AddBias.backward"> +<code class="descname">backward</code><span class="sig-paren">(</span><em>dy</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.AddBias.backward" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>dy</strong> (<em>CTensor</em>) â data for the dL / dy, L is the loss.</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a tuple for (db, dx), db is data for dL / db, dx is data +for dL / dx.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.AddBias.forward"> +<code class="descname">forward</code><span class="sig-paren">(</span><em>x</em>, <em>b</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.AddBias.forward" title="Permalink to this definition">¶</a></dt> +<dd><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>x</strong> â matrix.</li> +<li><strong>b</strong> â bias to be added.</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">the result Tensor</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +</dd></dl> + +<dl class="class"> +<dt id="singa.tensor.CrossEntropy"> +<em class="property">class </em><code class="descclassname">singa.tensor.</code><code class="descname">CrossEntropy</code><a class="headerlink" href="#singa.tensor.CrossEntropy" title="Permalink to this definition">¶</a></dt> +<dd><p>Calculte CrossEntropy loss for a batch of training data.</p> +<dl class="method"> +<dt id="singa.tensor.CrossEntropy.backward"> +<code class="descname">backward</code><span class="sig-paren">(</span><em>dy=1.0</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.CrossEntropy.backward" title="Permalink to this definition">¶</a></dt> +<dd><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>dy</strong> (<em>float</em><em> or </em><em>CTensor</em>) â scalar, accumulate gradient from outside of current network, usually</li> +<li><strong>to 1.0</strong> (<em>equal</em>) â </li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">data for the dL /dx, L is the loss, x is the output of current network. +note that this is true for dy = 1.0</p> +</td> +</tr> +<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">dx (CTensor)</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.CrossEntropy.forward"> +<code class="descname">forward</code><span class="sig-paren">(</span><em>x</em>, <em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.CrossEntropy.forward" title="Permalink to this definition">¶</a></dt> +<dd><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>x</strong> (<em>CTensor</em>) â 1d or 2d tensor, the prediction data(output) of current network.</li> +<li><strong>t</strong> (<em>CTensor</em>) â 1d or 2d tensor, the target data for training.</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">scalar.</p> +</td> +</tr> +<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">loss (CTensor)</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +</dd></dl> + +<dl class="class"> +<dt id="singa.tensor.Dummy"> +<em class="property">class </em><code class="descclassname">singa.tensor.</code><code class="descname">Dummy</code><span class="sig-paren">(</span><em>tensor</em>, <em>name=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Dummy" title="Permalink to this definition">¶</a></dt> +<dd><p>Dummy operation whice serves as a placehoder for autograd</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"><strong>name</strong> (<em>string</em>) â set it for debug</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="class"> +<dt id="singa.tensor.Matmul"> +<em class="property">class </em><code class="descclassname">singa.tensor.</code><code class="descname">Matmul</code><a class="headerlink" href="#singa.tensor.Matmul" title="Permalink to this definition">¶</a></dt> +<dd><p>For matrix multiplication</p> +<dl class="method"> +<dt id="singa.tensor.Matmul.backward"> +<code class="descname">backward</code><span class="sig-paren">(</span><em>dy</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Matmul.backward" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>dy</strong> (<em>CTensor</em>) â data for the dL / dy, L is the loss</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a tuple for (dx, dw)</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Matmul.forward"> +<code class="descname">forward</code><span class="sig-paren">(</span><em>x</em>, <em>w</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Matmul.forward" title="Permalink to this definition">¶</a></dt> +<dd><p>Do forward propgation.</p> +<p>Store the x(or w) if w(or x) requires gradient.</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>x</strong> (<em>CTensor</em>) â matrix</li> +<li><strong>w</strong> (<em>CTensor</em>) â matrix</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a CTensor for the result</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +</dd></dl> + +<dl class="class"> +<dt id="singa.tensor.Operation"> +<em class="property">class </em><code class="descclassname">singa.tensor.</code><code class="descname">Operation</code><a class="headerlink" href="#singa.tensor.Operation" title="Permalink to this definition">¶</a></dt> +<dd><p>An operation includes the forward and backward function of +tensor calculation.</p> +<p>To add a specific operation Xxxx, subclass Operation and implement +forward() and backward(). Then implement a function xxxx which creates +a Xxxx instance and calls __call__ to do forward. The autograd engine +is able to do backward propagation by calling the backward() of Xxxx +automatically. Notice that the tensors are CTensor. NOT Python Tensor. +The arguments of forward() and backward() should only include CTensor args;</p> +<dl class="method"> +<dt id="singa.tensor.Operation.backward"> +<code class="descname">backward</code><span class="sig-paren">(</span><em>*dys</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Operation.backward" title="Permalink to this definition">¶</a></dt> +<dd><p>Backward propagation.</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"><strong>dys</strong> â input args consisting of only CTensors.</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">CTensor instance(s)</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Operation.forward"> +<code class="descname">forward</code><span class="sig-paren">(</span><em>*xs</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Operation.forward" title="Permalink to this definition">¶</a></dt> +<dd><p>Forward propagation.</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"><strong>xs</strong> â input args consisting of only CTensors.</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">CTensor instance(s)</td> +</tr> +</tbody> +</table> +</dd></dl> + +</dd></dl> + +<dl class="class"> +<dt id="singa.tensor.ReLU"> +<em class="property">class </em><code class="descclassname">singa.tensor.</code><code class="descname">ReLU</code><a class="headerlink" href="#singa.tensor.ReLU" title="Permalink to this definition">¶</a></dt> +<dd><dl class="method"> +<dt id="singa.tensor.ReLU.backward"> +<code class="descname">backward</code><span class="sig-paren">(</span><em>dy</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.ReLU.backward" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>dy</strong> (<em>CTensor</em>) â dL / dy</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">dL / dx = dy if x >= 0; otherwise 0;</td> +</tr> +<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">dx(CTensor)</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.ReLU.forward"> +<code class="descname">forward</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.ReLU.forward" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>x</strong> (<em>CTensor</em>) â input tensor</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new CTensor whose element y = x if x >= 0; otherwise 0;</td> +</tr> +</tbody> +</table> +</dd></dl> + +</dd></dl> + +<dl class="class"> +<dt id="singa.tensor.SoftMax"> +<em class="property">class </em><code class="descclassname">singa.tensor.</code><code class="descname">SoftMax</code><span class="sig-paren">(</span><em>axis=0</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.SoftMax" title="Permalink to this definition">¶</a></dt> +<dd><p>Apply SoftMax for each row of the Tensor or each column of the Tensor +according to the parameter axis.</p> +<dl class="method"> +<dt id="singa.tensor.SoftMax.backward"> +<code class="descname">backward</code><span class="sig-paren">(</span><em>dy</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.SoftMax.backward" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>dy</strong> (<em>CTensor</em>) â data for the dL / dy, L is the loss</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">data for the dL / dx, L is the loss, +x is the input of current Opertion</td> +</tr> +<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">dx (Ctensor)</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.SoftMax.forward"> +<code class="descname">forward</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.SoftMax.forward" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>x</strong> (<em>data</em>) â the input 1d or 2d tensor</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">the result Tensor</td> +</tr> +</tbody> +</table> +</dd></dl> + +</dd></dl> + +<dl class="class"> +<dt id="singa.tensor.Tensor"> +<em class="property">class </em><code class="descclassname">singa.tensor.</code><code class="descname">Tensor</code><span class="sig-paren">(</span><em>shape=()</em>, <em>device=None</em>, <em>dtype=0</em>, <em>data=None</em>, <em>requires_grad=True</em>, <em>stores_grad=False</em>, <em>creator=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor" title="Permalink to this definition">¶</a></dt> +<dd><p>Python Tensor, which wraps a swig converted Tensor from CPP Tensor.</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>shape</strong> (<em>tuple<int></em>) â a tuple of integers for the tensor shape. If shape +is not specified, the created tensor is called a dummy tensor.</li> +<li><strong>device</strong> â a swig device. If None, the default host device is used.</li> +<li><strong>dtype</strong> â data type. currently, most operations only accept float32.</li> +<li><strong>data</strong> â a numpy array or swig tensor.</li> +<li><strong>requires_grad</strong> â boolean indicator for computing the gradient.</li> +<li><strong>stores_grad</strong> â boolean indicator for storing and returning the gradient. +Some intermediate tensorsâ gradient can be released +during the backward propagation. A tensor may require +grad but not store grad; But if a tensor stores grad +then it must require grad.</li> +</ul> +</td> +</tr> +</tbody> +</table> +<dl class="method"> +<dt id="singa.tensor.Tensor.T"> +<code class="descname">T</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.T" title="Permalink to this definition">¶</a></dt> +<dd><p>shallow copy, negate the transpose field.</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">Returns:</th><td class="field-body">a new Tensor which shares the underlying data memory (shallow copy) +but is marked as a transposed version of this tensor.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.add_column"> +<code class="descname">add_column</code><span class="sig-paren">(</span><em>v</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.add_column" title="Permalink to this definition">¶</a></dt> +<dd><p>Add a tensor to each column of this tensor.</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"><strong>v</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â a Tensor to be added as a column to this tensor.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.add_row"> +<code class="descname">add_row</code><span class="sig-paren">(</span><em>v</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.add_row" title="Permalink to this definition">¶</a></dt> +<dd><p>Add a tensor to each row of this tensor.</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"><strong>v</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â a Tensor to be added as a row to this tensor.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.bernoulli"> +<code class="descname">bernoulli</code><span class="sig-paren">(</span><em>p</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.bernoulli" title="Permalink to this definition">¶</a></dt> +<dd><p>Sample 0/1 for each element according to the given probability.</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"><strong>p</strong> (<em>float</em>) â with probability p, each element is sample to 1.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.clone"> +<code class="descname">clone</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.clone" title="Permalink to this definition">¶</a></dt> +<dd><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">Returns:</th><td class="field-body">a new Tensor which does deep copy of this tensor</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.copy"> +<code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.copy" title="Permalink to this definition">¶</a></dt> +<dd><p>shallow copy calls copy constructor of singa::Tensor</p> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.copy_data"> +<code class="descname">copy_data</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.copy_data" title="Permalink to this definition">¶</a></dt> +<dd><p>Copy data from other Tensor instance.</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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â source Tensor.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.copy_from_numpy"> +<code class="descname">copy_from_numpy</code><span class="sig-paren">(</span><em>np_array</em>, <em>offset=0</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.copy_from_numpy" title="Permalink to this definition">¶</a></dt> +<dd><p>Copy the data from the numpy array.</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>np_array</strong> â source numpy array</li> +<li><strong>offset</strong> (<em>int</em>) â destination offset</li> +</ul> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.deepcopy"> +<code class="descname">deepcopy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.deepcopy" title="Permalink to this definition">¶</a></dt> +<dd><p>Same as clone().</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">Returns:</th><td class="field-body">a new Tensor</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.div_column"> +<code class="descname">div_column</code><span class="sig-paren">(</span><em>v</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.div_column" title="Permalink to this definition">¶</a></dt> +<dd><p>Divide each column of this tensor by v.</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"><strong>v</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â 1d tensor of the same length the column of self.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.div_row"> +<code class="descname">div_row</code><span class="sig-paren">(</span><em>v</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.div_row" title="Permalink to this definition">¶</a></dt> +<dd><p>Divide each row of this tensor by v.</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"><strong>v</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â 1d tensor of the same length the row of self.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.gaussian"> +<code class="descname">gaussian</code><span class="sig-paren">(</span><em>mean</em>, <em>std</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.gaussian" title="Permalink to this definition">¶</a></dt> +<dd><p>Generate a value for each element following a Gaussian 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 last simple"> +<li><strong>mean</strong> (<em>float</em>) â mean of the distribution</li> +<li><strong>std</strong> (<em>float</em>) â standard variance of the distribution</li> +</ul> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.is_empty"> +<code class="descname">is_empty</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.is_empty" title="Permalink to this definition">¶</a></dt> +<dd><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">Returns:</th><td class="field-body">True if the tensor is empty according to its shape</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.is_transpose"> +<code class="descname">is_transpose</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.is_transpose" title="Permalink to this definition">¶</a></dt> +<dd><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">Returns:</th><td class="field-body">True if the internal data is transposed; otherwise False.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.l1"> +<code class="descname">l1</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.l1" title="Permalink to this definition">¶</a></dt> +<dd><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">Returns:</th><td class="field-body">the L1 norm.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.l2"> +<code class="descname">l2</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.l2" title="Permalink to this definition">¶</a></dt> +<dd><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">Returns:</th><td class="field-body">the L2 norm.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.memsize"> +<code class="descname">memsize</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.memsize" title="Permalink to this definition">¶</a></dt> +<dd><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">Returns:</th><td class="field-body">the number of Bytes allocated for this tensor.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.mult_column"> +<code class="descname">mult_column</code><span class="sig-paren">(</span><em>v</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.mult_column" title="Permalink to this definition">¶</a></dt> +<dd><p>Multiply each column of this tensor by v element-wisely.</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"><strong>v</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â 1d tensor of the same length the column of self.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.mult_row"> +<code class="descname">mult_row</code><span class="sig-paren">(</span><em>v</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.mult_row" title="Permalink to this definition">¶</a></dt> +<dd><p>Multiply each row of this tensor by v element-wisely.</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"><strong>v</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â 1d tensor of the same length the row of self.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.ndim"> +<code class="descname">ndim</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.ndim" title="Permalink to this definition">¶</a></dt> +<dd><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">Returns:</th><td class="field-body">the number of dimensions of the tensor.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.reset_like"> +<code class="descname">reset_like</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.reset_like" title="Permalink to this definition">¶</a></dt> +<dd><p>Reset the shape, dtype and device as the given tensor.</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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.reshape"> +<code class="descname">reshape</code><span class="sig-paren">(</span><em>shape</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.reshape" title="Permalink to this definition">¶</a></dt> +<dd><p>Change the tensor shape.</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"><strong>shape</strong> (<em>list<int></em>) â new shape, which should have the same volumn as +the original shape.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.set_value"> +<code class="descname">set_value</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.set_value" title="Permalink to this definition">¶</a></dt> +<dd><p>Set all elements of the tensor to be the give value.</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"><strong>x</strong> (<em>float</em>) â </td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.size"> +<code class="descname">size</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.size" title="Permalink to this definition">¶</a></dt> +<dd><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">Returns:</th><td class="field-body">the number of elements of the tensor.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.to_device"> +<code class="descname">to_device</code><span class="sig-paren">(</span><em>device</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.to_device" title="Permalink to this definition">¶</a></dt> +<dd><p>Move the tensor data onto a given device.</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"><strong>device</strong> â a swig Device converted from CudaGPU or CppCPU or OpenclGPU</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.to_host"> +<code class="descname">to_host</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.to_host" title="Permalink to this definition">¶</a></dt> +<dd><p>Move the tensor data onto the default host CppCPU device.</p> +</dd></dl> + +<dl class="method"> +<dt id="singa.tensor.Tensor.uniform"> +<code class="descname">uniform</code><span class="sig-paren">(</span><em>low</em>, <em>high</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor.uniform" title="Permalink to this definition">¶</a></dt> +<dd><p>Generate a value for each element following 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 last simple"> +<li><strong>low</strong> (<em>float</em>) â the lower bound</li> +<li><strong>high</strong> (<em>float</em>) â the hight bound</li> +</ul> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.abs"> +<code class="descclassname">singa.tensor.</code><code class="descname">abs</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.abs" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input Tensor</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new Tensor whose element y = abs(x), x is an element of t</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.add"> +<code class="descclassname">singa.tensor.</code><code class="descname">add</code><span class="sig-paren">(</span><em>lhs</em>, <em>rhs</em>, <em>ret=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.add" title="Permalink to this definition">¶</a></dt> +<dd><p>Elementi-wise addition.</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>lhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>rhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>ret</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a><em>, </em><em>optional</em>) â if not None, the result is stored in it; +otherwise, a new Tensor would be created for the result.</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">the result Tensor</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.add_column"> +<code class="descclassname">singa.tensor.</code><code class="descname">add_column</code><span class="sig-paren">(</span><em>alpha</em>, <em>v</em>, <em>beta</em>, <em>M</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.add_column" title="Permalink to this definition">¶</a></dt> +<dd><p>Add v to each column of M.</p> +<p>Denote each column of M as m, m = alpha * v + beta * m</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>alpha</strong> (<em>float</em>) â </li> +<li><strong>v</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>beta</strong> (<em>float</em>) â </li> +<li><strong>M</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â 2d tensor</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">M</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.add_row"> +<code class="descclassname">singa.tensor.</code><code class="descname">add_row</code><span class="sig-paren">(</span><em>alpha</em>, <em>v</em>, <em>beta</em>, <em>M</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.add_row" title="Permalink to this definition">¶</a></dt> +<dd><p>Add v to each row of M.</p> +<p>Denote each row of M as m, m = alpha * v + beta * m</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>alpha</strong> (<em>float</em>) â </li> +<li><strong>v</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>beta</strong> (<em>float</em>) â </li> +<li><strong>M</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â 2d tensor</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">M</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.average"> +<code class="descclassname">singa.tensor.</code><code class="descname">average</code><span class="sig-paren">(</span><em>t</em>, <em>axis=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.average" title="Permalink to this definition">¶</a></dt> +<dd><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>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input Tensor</li> +<li><strong>axis</strong> (<em>int</em><em>, </em><em>optional</em>) â if None, average all elements; otherwise average +along the given dimension. 0 for averaging each column; 1 for +averaging each row.</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a float value if axis is None; otherwise, a new Tensor for the result.</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.axpy"> +<code class="descclassname">singa.tensor.</code><code class="descname">axpy</code><span class="sig-paren">(</span><em>alpha</em>, <em>x</em>, <em>y</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.axpy" title="Permalink to this definition">¶</a></dt> +<dd><p>Element-wise operation for y += alpha * x.</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>alpha</strong> (<em>float</em>) â </li> +<li><strong>x</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>y</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">y</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.bernoulli"> +<code class="descclassname">singa.tensor.</code><code class="descname">bernoulli</code><span class="sig-paren">(</span><em>p</em>, <em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.bernoulli" title="Permalink to this definition">¶</a></dt> +<dd><p>Generate a binary value for each element of t.</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>p</strong> (<em>float</em>) â each element is 1 with probability p; and 0 with 1 - p</li> +<li><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â the results are put into t</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">t</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.copy_data_to_from"> +<code class="descclassname">singa.tensor.</code><code class="descname">copy_data_to_from</code><span class="sig-paren">(</span><em>dst</em>, <em>src</em>, <em>size</em>, <em>dst_offset=0</em>, <em>src_offset=0</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.copy_data_to_from" title="Permalink to this definition">¶</a></dt> +<dd><p>Copy the data between two Tensor instances which could be on different +devices.</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>dst</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â destination Tensor</li> +<li><strong>src</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â source Tensor</li> +<li><strong>size</strong> (<em>int</em>) â number of elements to copy</li> +<li><strong>dst_offset</strong> (<em>int</em>) â offset in terms of elements to the start of dst</li> +<li><strong>src_offset</strong> (<em>int</em>) â offset in terms of elements to the start of src</li> +</ul> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.copy_from_numpy"> +<code class="descclassname">singa.tensor.</code><code class="descname">copy_from_numpy</code><span class="sig-paren">(</span><em>data</em>, <em>np_array</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.copy_from_numpy" title="Permalink to this definition">¶</a></dt> +<dd><p>Copy the data from the numpy array.</p> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.ctensor2numpy"> +<code class="descclassname">singa.tensor.</code><code class="descname">ctensor2numpy</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.ctensor2numpy" title="Permalink to this definition">¶</a></dt> +<dd><p>To be used in SoftMax Operation. +Convert a singa_tensor to numpy_tensor.</p> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.div"> +<code class="descclassname">singa.tensor.</code><code class="descname">div</code><span class="sig-paren">(</span><em>lhs</em>, <em>rhs</em>, <em>ret=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.div" title="Permalink to this definition">¶</a></dt> +<dd><p>Elementi-wise division.</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>lhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>rhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>ret</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a><em>, </em><em>optional</em>) â if not None, the result is stored in it; +otherwise, a new Tensor would be created for the result.</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">the result Tensor</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.einsum"> +<code class="descclassname">singa.tensor.</code><code class="descname">einsum</code><span class="sig-paren">(</span><em>ops</em>, <em>*args</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.einsum" title="Permalink to this definition">¶</a></dt> +<dd><p>function TODO list to finish the function in cpp(just like numpy function): +1.sum(A,axis = None) +2.repeat(A,repeats) +3.transpose(A,axes = None) +Do the matrix to matrix einsum calculation according to the operands +Warning : this function could only support two matrixâ einsum calcultion +:param ops: the string specifies the subscripts for summation such as âki,kj->kijâ</p> +<blockquote> +<div>Here all the 26 lowercase letter can be used here.</div></blockquote> +<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"><strong>arg</strong> (<em>list of array_like</em>) â These are the tensors for the operation,but here only support two tensors.</td> +</tr> +</tbody> +</table> +<dl class="docutils"> +<dt>Returns: Singa.Tensor</dt> +<dd>the output matirx of the einsum calculation</dd> +</dl> +<p>The best way to understand this function is to try the examples below: +<a href="#id1"><span class="problematic" id="id2">A_</span></a> = [0,1,2,3,4,5,6,7,8,9,10,11] +A = <a href="#id3"><span class="problematic" id="id4">A_</span></a>.reshape(4,3) +B = <a href="#id5"><span class="problematic" id="id6">A_</span></a>.reshape(3,4)</p> +<p>Here this einsum calculation is the same as normal âmultâ +Res = einsum(âij,jk->ikâ,A,B)</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="p">[[</span> <span class="mi">20</span> <span class="mi">23</span> <span class="mi">26</span> <span class="mi">29</span><span class="p">]</span> +<span class="go"> [ 56 68 80 92]</span> +<span class="go"> [ 92 113 134 155]</span> +<span class="go"> [128 158 188 218]]</span> +</pre></div> +</div> +<p><a href="#id7"><span class="problematic" id="id8">A_</span></a> = [0,1,2,3,4,5,6,7,8,9,10,11] +A = <a href="#id9"><span class="problematic" id="id10">A_</span></a>.reshape(4,3) +B = <a href="#id11"><span class="problematic" id="id12">A_</span></a>.reshape(4,3)</p> +<p>Here the einsum calculation is the same as normol âeltwise_multâ +Res = einsum(âki,ki->kiâ,A,B)</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="p">[[</span> <span class="mi">0</span> <span class="mi">1</span> <span class="mi">4</span><span class="p">]</span> +<span class="go"> [ 9 16 25]</span> +<span class="go"> [ 36 49 64]</span> +<span class="go"> [ 81 100 121]]</span> +</pre></div> +</div> +<p>A = [0,1,2,3,4,5,6,7,8,9,10,11] +A = A.reshape(4,3)</p> +<p>Res = einsum(âki,kj->kijâ,A,A) +>>> [[[ 0 0 0]</p> +<blockquote> +<div><blockquote> +<div>[ 0 1 2] +[ 0 2 4]]</div></blockquote> +<dl class="docutils"> +<dt>[[ 9 12 15]</dt> +<dd>[ 12 16 20] +[ 15 20 25]]</dd> +<dt>[[ 36 42 48]</dt> +<dd>[ 42 49 56] +[ 48 56 64]]</dd> +<dt>[[ 81 90 99]</dt> +<dd>[ 90 100 110] +[ 99 110 121]]]</dd> +</dl> +</div></blockquote> +<p><a href="#id13"><span class="problematic" id="id14">A_</span></a> = [0,1,2,3,4,5,6,7,8,9,10,11] +A = <a href="#id15"><span class="problematic" id="id16">A_</span></a>.reshape(3,2,2)</p> +<p>Res = einsum(âkia,kja->kijâ,A,A) +>>> [[[ 1 3]</p> +<blockquote> +<div><blockquote> +<div>[ 3 13]]</div></blockquote> +<dl class="docutils"> +<dt>[[ 41 59]</dt> +<dd>[ 59 85]]</dd> +<dt>[[145 179]</dt> +<dd>[179 221]]]</dd> +</dl> +</div></blockquote> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.eltwise_mult"> +<code class="descclassname">singa.tensor.</code><code class="descname">eltwise_mult</code><span class="sig-paren">(</span><em>lhs</em>, <em>rhs</em>, <em>ret=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.eltwise_mult" title="Permalink to this definition">¶</a></dt> +<dd><p>Elementi-wise multiplication.</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>lhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>rhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>ret</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a><em>, </em><em>optional</em>) â if not None, the result is stored in it; +otherwise, a new Tensor would be created for the result.</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">the result Tensor</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.exp"> +<code class="descclassname">singa.tensor.</code><code class="descname">exp</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.exp" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input Tensor</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new Tensor whose element y = exp(x), x is an element of t</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.from_numpy"> +<code class="descclassname">singa.tensor.</code><code class="descname">from_numpy</code><span class="sig-paren">(</span><em>np_array</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.from_numpy" title="Permalink to this definition">¶</a></dt> +<dd><p>Create a Tensor instance with the shape, dtype and values from the numpy +array.</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"><strong>np_array</strong> â the numpy array.</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">A Tensor instance allocated on the default CppCPU device.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.gaussian"> +<code class="descclassname">singa.tensor.</code><code class="descname">gaussian</code><span class="sig-paren">(</span><em>mean</em>, <em>std</em>, <em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.gaussian" title="Permalink to this definition">¶</a></dt> +<dd><p>Generate values following a Gaussian 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> (<em>float</em>) â the mean of the Gaussian distribution.</li> +<li><strong>std</strong> (<em>float</em>) â the standard variance of the Gaussian distribution.</li> +<li><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â the results are put into t</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">t</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.ge"> +<code class="descclassname">singa.tensor.</code><code class="descname">ge</code><span class="sig-paren">(</span><em>t</em>, <em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.ge" title="Permalink to this definition">¶</a></dt> +<dd><p>Elementi-wise comparison for t >= x.</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>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â left hand side operand</li> +<li><strong>x</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a><em> or </em><em>float</em>) â right hand side operand</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">0.0f, +or t[i] >= x[i] ? 1.0f:0.0f</p> +</td> +</tr> +<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">a Tensor with each element being t[i] >= x ? 1.0f</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.gt"> +<code class="descclassname">singa.tensor.</code><code class="descname">gt</code><span class="sig-paren">(</span><em>t</em>, <em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.gt" title="Permalink to this definition">¶</a></dt> +<dd><p>Elementi-wise comparison for t > x.</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>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â left hand side operand</li> +<li><strong>x</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a><em> or </em><em>float</em>) â right hand side operand</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">0.0f, +or t[i] > x[i] ? 1.0f:0.0f</p> +</td> +</tr> +<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">a Tensor with each element being t[i] > x ? 1.0f</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.le"> +<code class="descclassname">singa.tensor.</code><code class="descname">le</code><span class="sig-paren">(</span><em>t</em>, <em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.le" title="Permalink to this definition">¶</a></dt> +<dd><p>Elementi-wise comparison for t <= x.</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>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â left hand side operand</li> +<li><strong>x</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a><em> or </em><em>float</em>) â right hand side operand</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">0.0f, +or t[i] <= x[i] ? 1.0f:0.0f</p> +</td> +</tr> +<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">a Tensor with each element being t[i] <= x ? 1.0f</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.log"> +<code class="descclassname">singa.tensor.</code><code class="descname">log</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.log" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input Tensor</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new Tensor whose element y = log(x), x is an element of t</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.lt"> +<code class="descclassname">singa.tensor.</code><code class="descname">lt</code><span class="sig-paren">(</span><em>t</em>, <em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.lt" title="Permalink to this definition">¶</a></dt> +<dd><p>Elementi-wise comparison for t < x</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>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â left hand side operand</li> +<li><strong>x</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a><em> or </em><em>float</em>) â right hand side operand</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">0.0f, +or t[i] < x[i] ? 1.0f:0.0f</p> +</td> +</tr> +<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">a Tensor with each element being t[i] < x ? 1.0f</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.mult"> +<code class="descclassname">singa.tensor.</code><code class="descname">mult</code><span class="sig-paren">(</span><em>A</em>, <em>B</em>, <em>C=None</em>, <em>alpha=1.0</em>, <em>beta=0.0</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.mult" title="Permalink to this definition">¶</a></dt> +<dd><p>Do matrix-matrix or matrix-vector multiplication.</p> +<p>This function returns C = alpha * A * B + beta * C</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>A</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â 2d Tensor</li> +<li><strong>B</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â If B is a 1d Tensor, GEMV would be invoked for matrix-vector +multiplication; otherwise GEMM would be invoked.</li> +<li><strong>C</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a><em>, </em><em>optional</em>) â for storing the result; If None, a new Tensor +would be created.</li> +<li><strong>alpha</strong> (<em>float</em>) â </li> +<li><strong>beta</strong> (<em>float</em>) â </li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">the result Tensor</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.pow"> +<code class="descclassname">singa.tensor.</code><code class="descname">pow</code><span class="sig-paren">(</span><em>t</em>, <em>x</em>, <em>out=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.pow" title="Permalink to this definition">¶</a></dt> +<dd><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>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input tensor</li> +<li><strong>x</strong> (<em>float</em><em> or </em><a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â y[i] = t[i]^x if x is a float value; otherwise, +y[i]= t[i]^x[i] if x is a tensor.</li> +<li><strong>out</strong> (<em>None</em><em> or </em><a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â if None, a new Tensor would be constructed to +store the result; otherwise, the result is put into out.</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">the result tensor.</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.reshape"> +<code class="descclassname">singa.tensor.</code><code class="descname">reshape</code><span class="sig-paren">(</span><em>t</em>, <em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.reshape" title="Permalink to this definition">¶</a></dt> +<dd><p>Reshape the input tensor with the given shape.</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>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â the tensor to be changed</li> +<li><strong>s</strong> (<em>list<int></em>) â the new shape, which should have the same volumn as the +old shape.</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">the new Tensor</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.sigmoid"> +<code class="descclassname">singa.tensor.</code><code class="descname">sigmoid</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.sigmoid" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input Tensor</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new Tensor whose element y = sigmoid(x); x is an element of t</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.sign"> +<code class="descclassname">singa.tensor.</code><code class="descname">sign</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.sign" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input Tensor</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new Tensor whose element y = sign(x)</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.sizeof"> +<code class="descclassname">singa.tensor.</code><code class="descname">sizeof</code><span class="sig-paren">(</span><em>dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.sizeof" title="Permalink to this definition">¶</a></dt> +<dd><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">Returns:</th><td class="field-body">the number of bytes of the given SINGA data type defined in core.proto</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.softmax"> +<code class="descclassname">singa.tensor.</code><code class="descname">softmax</code><span class="sig-paren">(</span><em>t</em>, <em>out=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.softmax" title="Permalink to this definition">¶</a></dt> +<dd><p>Apply SoftMax for each row of the Tensor. +:param t: the input 1d or 2d tensor +:type t: Tensor +:param out: if not None, it is used to store the result +:type out: Tensor, optional</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">Returns:</th><td class="field-body">the result Tensor</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.sqrt"> +<code class="descclassname">singa.tensor.</code><code class="descname">sqrt</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.sqrt" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input Tensor</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new Tensor whose element y = sqrt(x), x is an element of t</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.square"> +<code class="descclassname">singa.tensor.</code><code class="descname">square</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.square" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input Tensor</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new Tensor whose element y = x * x, x is an element of t</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.sub"> +<code class="descclassname">singa.tensor.</code><code class="descname">sub</code><span class="sig-paren">(</span><em>lhs</em>, <em>rhs</em>, <em>ret=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.sub" title="Permalink to this definition">¶</a></dt> +<dd><p>Elementi-wise subtraction.</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>lhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>rhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </li> +<li><strong>ret</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a><em>, </em><em>optional</em>) â if not None, the result is stored in it; +otherwise, a new Tensor would be created for the result.</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">the result Tensor</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.sum"> +<code class="descclassname">singa.tensor.</code><code class="descname">sum</code><span class="sig-paren">(</span><em>t</em>, <em>axis=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.sum" title="Permalink to this definition">¶</a></dt> +<dd><p>Sum elements of the input tensor long the given axis.</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>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input Tensor</li> +<li><strong>axis</strong> (<em>int</em><em>, </em><em>optional</em>) â if None, the summation is done over all elements; +if axis is provided, then it is calculated along the given axis, +e.g. 0 â sum each column; 1 â sum each row.</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a float value as the sum of all elements, or a new Tensor</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.sum_columns"> +<code class="descclassname">singa.tensor.</code><code class="descname">sum_columns</code><span class="sig-paren">(</span><em>M</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.sum_columns" title="Permalink to this definition">¶</a></dt> +<dd><p>Sum all columns into a single column.</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"><strong>M</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â the input 2d tensor.</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new Tensor as the resulted column.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.sum_rows"> +<code class="descclassname">singa.tensor.</code><code class="descname">sum_rows</code><span class="sig-paren">(</span><em>M</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.sum_rows" title="Permalink to this definition">¶</a></dt> +<dd><p>Sum all rows into a single row.</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"><strong>M</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â the input 2d tensor.</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new Tensor as the resulted row.</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.tanh"> +<code class="descclassname">singa.tensor.</code><code class="descname">tanh</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.tanh" title="Permalink to this definition">¶</a></dt> +<dd><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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â input Tensor</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a new Tensor whose element y = tanh(x), x is an element of t</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.to_host"> +<code class="descclassname">singa.tensor.</code><code class="descname">to_host</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.to_host" title="Permalink to this definition">¶</a></dt> +<dd><p>Copy the data to a host tensor.</p> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.to_numpy"> +<code class="descclassname">singa.tensor.</code><code class="descname">to_numpy</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.to_numpy" title="Permalink to this definition">¶</a></dt> +<dd><p>Copy the tensor into a numpy array.</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"><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â </td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a numpy array</td> +</tr> +</tbody> +</table> +</dd></dl> + +<dl class="function"> +<dt id="singa.tensor.uniform"> +<code class="descclassname">singa.tensor.</code><code class="descname">uniform</code><span class="sig-paren">(</span><em>low</em>, <em>high</em>, <em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.uniform" title="Permalink to this definition">¶</a></dt> +<dd><p>Generate values following 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>low</strong> (<em>float</em>) â the lower bound</li> +<li><strong>hight</strong> (<em>float</em>) â the higher bound</li> +<li><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) â the results are put into t</li> +</ul> +</td> +</tr> +<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">t</p> +</td> +</tr> +</tbody> +</table> +</dd></dl> + </div> <div class="section" id="cpp-api"> <h2>CPP API<a class="headerlink" href="#cpp-api" title="Permalink to this headline">¶</a></h2> @@ -281,9 +1769,7 @@ type of Device.</p> <script type="text/javascript"> jQuery(function () { - - SphinxRtdTheme.Navigation.enableSticky(); - + SphinxRtdTheme.Navigation.enable(true); }); </script>
Modified: incubator/singa/site/trunk/en/docs/utils.html URL: http://svn.apache.org/viewvc/incubator/singa/site/trunk/en/docs/utils.html?rev=1831260&r1=1831259&r2=1831260&view=diff ============================================================================== --- incubator/singa/site/trunk/en/docs/utils.html (original) +++ incubator/singa/site/trunk/en/docs/utils.html Wed May 9 15:25:26 2018 @@ -188,8 +188,26 @@ <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> <div itemprop="articleBody"> - <div class="section" id="utils"> -<h1>Utils<a class="headerlink" href="#utils" title="Permalink to this headline">¶</a></h1> + <div class="section" id="module-singa.utils"> +<span id="utils"></span><h1>Utils<a class="headerlink" href="#module-singa.utils" title="Permalink to this headline">¶</a></h1> +<dl class="function"> +<dt id="singa.utils.update_progress"> +<code class="descclassname">singa.utils.</code><code class="descname">update_progress</code><span class="sig-paren">(</span><em>progress</em>, <em>info</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.utils.update_progress" title="Permalink to this definition">¶</a></dt> +<dd><p>Display progress bar and user info.</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>progress</strong> (<em>float</em>) â progress [0, 1], negative for halt, and >=1 for done.</li> +<li><strong>info</strong> (<em>str</em>) â a string for user provided info to be displayed.</li> +</ul> +</td> +</tr> +</tbody> +</table> +</dd></dl> + </div> @@ -255,9 +273,7 @@ <script type="text/javascript"> jQuery(function () { - - SphinxRtdTheme.Navigation.enableSticky(); - + SphinxRtdTheme.Navigation.enable(true); }); </script> Modified: incubator/singa/site/trunk/en/downloads.html URL: http://svn.apache.org/viewvc/incubator/singa/site/trunk/en/downloads.html?rev=1831260&r1=1831259&r2=1831260&view=diff ============================================================================== --- incubator/singa/site/trunk/en/downloads.html (original) +++ incubator/singa/site/trunk/en/downloads.html Wed May 9 15:25:26 2018 @@ -358,9 +358,7 @@ ASF.</p> <script type="text/javascript"> jQuery(function () { - - SphinxRtdTheme.Navigation.enableSticky(); - + SphinxRtdTheme.Navigation.enable(true); }); </script>
