singa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wang...@apache.org
Subject svn commit: r1756485 [3/4] - in /incubator/singa/site/trunk: en/ en/_static/ en/community/ en/develop/ en/docs/ zh/ zh/_static/
Date Tue, 16 Aug 2016 07:30:21 GMT
Modified: incubator/singa/site/trunk/en/docs/optimizer.html
URL: http://svn.apache.org/viewvc/incubator/singa/site/trunk/en/docs/optimizer.html?rev=1756485&r1=1756484&r2=1756485&view=diff
==============================================================================
--- incubator/singa/site/trunk/en/docs/optimizer.html (original)
+++ incubator/singa/site/trunk/en/docs/optimizer.html Tue Aug 16 07:30:21 2016
@@ -33,7 +33,7 @@
   
     <link rel="top" title="incubator-singa 1.0.0 documentation" href="../index.html"/>
         <link rel="up" title="Documentation" href="index.html"/>
-        <link rel="next" title="Development Schedule" href="../develop/schedule.html"/>
+        <link rel="next" title="Examples" href="examples/index.html"/>
         <link rel="prev" title="Metric" href="metric.html"/>
     <link href="../_static/style.css" rel="stylesheet" type="text/css">
 
@@ -100,6 +100,7 @@
 <li class="toctree-l2"><a class="reference internal" href="loss.html">Loss</a></li>
 <li class="toctree-l2"><a class="reference internal" href="metric.html">Metric</a></li>
 <li class="toctree-l2 current"><a class="current reference internal" href="#">Optimizer</a></li>
+<li class="toctree-l2"><a class="reference internal" href="examples/index.html">Examples</a></li>
 </ul>
 </li>
 </ul>
@@ -160,8 +161,329 @@
           <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
            <div itemprop="articleBody">
             
-  <div class="section" id="optimizer">
-<h1>Optimizer<a class="headerlink" href="#optimizer" title="Permalink to this headline">¶</a></h1>
+  <div class="section" id="module-singa.optimizer">
+<span id="optimizer"></span><h1>Optimizer<a class="headerlink" href="#module-singa.optimizer" title="Permalink to this headline">¶</a></h1>
+<p>This module includes a set of optimizers for updating model parameters.</p>
+<p>Example usage:</p>
+<div class="highlight-default"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">singa</span> <span class="k">import</span> <span class="n">optimizer</span>
+<span class="kn">from</span> <span class="nn">singa</span> <span class="k">import</span> <span class="n">tensor</span>
+
+<span class="n">sgd</span> <span class="o">=</span> <span class="n">optimizer</span><span class="o">.</span><span class="n">SGD</span><span class="p">(</span><span class="n">lr</span><span class="o">=</span><span class="mf">0.01</span><span class="p">,</span> <span class="n">momentum</span><span class="o">=</span><span class="mf">0.9</span><span class="p">,</span> <span class="n">weight_decay</span><span class="o">=</span><span class="mi">1</span><span class="n">e</span><span class="o">-</span><span class="mi">4</span><span class="p">)</span>
+<span class="n">p</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">3</span><span class="p">,</span><span class="mi">5</span><span class="p">))</span>
+<span class="n">p</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="n">g</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">3</span><span class="p">,</span><span class="mi">5</span><span class="p">))</span>
+<span class="n">g</span><span class="o">.</span><span class="n">gaussian</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mf">0.01</span><span class="p">)</span>
+
+<span class="n">sgd</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="s">&#39;param&#39;</span><span class="p">)</span>  <span class="c"># use the global lr=0.1 for epoch 1</span>
+<span class="n">sgd</span><span class="o">.</span><span class="n">apply_with_lr</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mf">0.03</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="s">&#39;param&#39;</span><span class="p">)</span>  <span class="c"># use lr=0.03 for epoch 2</span>
+</pre></div>
+</div>
+<dl class="class">
+<dt id="singa.optimizer.Optimizer">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">Optimizer</code><span class="sig-paren">(</span><em>lr=None</em>, <em>momentum=None</em>, <em>weight_decay=None</em>, <em>lr_gen=None</em>, <em>regularizer=None</em>, <em>constraint=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.Optimizer" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
+<p>The base python optimizer class.</p>
+<p>Typically, an optimizer is used as follows:</p>
+<ol class="arabic simple">
+<li>construct the optimizer</li>
+<li>(optional) register each parameter with its specs.</li>
+<li>use the optimizer to update parameter values given parameter gradients
+and other optional info</li>
+</ol>
+<p>The subclasses should override the apply_with_lr function to do the real
+parameter udpate.</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>lr</strong> (<em>float</em>) &#8211; a constant for the learning rate, mutually exclusive with
+&#8216;lr_gen&#8217;.</li>
+<li><strong>momentum</strong> (<em>float</em>) &#8211; a constant for the momentum value</li>
+<li><strong>weight_decay</strong> (<em>float</em>) &#8211; the coefficent for L2 regularizer, which is
+mutually exclusive with &#8216;regularizer&#8217;.</li>
+<li><strong>lr_gen</strong> (<em>function</em>) &#8211; a function returns the learning rate given
+the current training step/epoch. It is mutually exclusive with lr.
+If both are not set, the apply_with_lr function should be used for
+param updating.</li>
+<li><strong>regularizer</strong> &#8211; an instance of Regularizer or RegularizerConf; If set,
+regularization would be applied in apply_with_lr().
+Users can also do regularization outside.</li>
+<li><strong>constraint</strong> &#8211; an instance of Constraint or ConstraintConf; If set,
+constraint would be applied inside apply_with_lr(). Users can
+also do regularization outside.</li>
+</ul>
+</td>
+</tr>
+</tbody>
+</table>
+<dl class="method">
+<dt id="singa.optimizer.Optimizer.register">
+<code class="descname">register</code><span class="sig-paren">(</span><em>name</em>, <em>specs</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.Optimizer.register" title="Permalink to this definition">¶</a></dt>
+<dd><p>Register the param specs, including creating regularizer and
+constraint per param object. Param specific regularizer and constraint
+have higher priority than the global ones.</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>name</strong> (<em>str</em>) &#8211; parameter name</li>
+<li><strong>specs</strong> (<em>ParamSpec</em>) &#8211; protobuf obj, including regularizer and
+constraint, multipliers for learning rate and weight decay.</li>
+</ul>
+</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+<dl class="method">
+<dt id="singa.optimizer.Optimizer.apply_regularizer_constraint">
+<code class="descname">apply_regularizer_constraint</code><span class="sig-paren">(</span><em>epoch</em>, <em>value</em>, <em>grad</em>, <em>name=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.Optimizer.apply_regularizer_constraint" title="Permalink to this definition">¶</a></dt>
+<dd><p>Apply regularization and constraint if available.</p>
+<p>If there are both global regularizer (constraint) and param specific
+regularizer (constraint), it would use the param specific one.</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>value</strong> (<a class="reference internal" href="tensor.html#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; parameter value Tensor</li>
+<li><strong>grad</strong> (<a class="reference internal" href="tensor.html#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; parameter gradient Tensor</li>
+<li><strong>name</strong> (<em>string</em>) &#8211; to get parameter specific regularizer or constraint</li>
+<li><strong>epoch</strong> (<em>int</em>) &#8211; some regularizer or constraint would use epoch</li>
+</ul>
+</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">the updated gradient Tensor</p>
+</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+<dl class="method">
+<dt id="singa.optimizer.Optimizer.apply_with_lr">
+<code class="descname">apply_with_lr</code><span class="sig-paren">(</span><em>epoch</em>, <em>lr</em>, <em>grad</em>, <em>value</em>, <em>name=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.Optimizer.apply_with_lr" title="Permalink to this definition">¶</a></dt>
+<dd><p>Do update with given learning rate.</p>
+<p>The subclass optimizer must override this function.</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>epoch</strong> (<em>int</em>) &#8211; training epoch (could be iteration or epoch)</li>
+<li><strong>lr</strong> (<em>float</em>) &#8211; learning rate</li>
+<li><strong>grad</strong> (<a class="reference internal" href="tensor.html#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; parameter gradient</li>
+<li><strong>value</strong> (<em>Tesnor</em>) &#8211; parameter value</li>
+<li><strong>name</strong> (<em>string</em>) &#8211; paramter name to retrieval parameter specific
+updating rules (including regularizer and constraint)</li>
+</ul>
+</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">updated parameter value</p>
+</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+<dl class="method">
+<dt id="singa.optimizer.Optimizer.apply">
+<code class="descname">apply</code><span class="sig-paren">(</span><em>epoch</em>, <em>grad</em>, <em>value</em>, <em>name=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.Optimizer.apply" title="Permalink to this definition">¶</a></dt>
+<dd><p>Do update assuming the learning rate generator is set.</p>
+<p>The subclass optimizer does not need to override this function.</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>epoch</strong> (<em>int</em>) &#8211; training epoch (could be iteration or epoch)</li>
+<li><strong>grad</strong> (<a class="reference internal" href="tensor.html#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; parameter gradient</li>
+<li><strong>value</strong> (<em>Tesnor</em>) &#8211; parameter value</li>
+<li><strong>name</strong> (<em>string</em>) &#8211; paramter name to retrieval parameter specific
+updating rules (including regularizer and constraint)</li>
+</ul>
+</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">updated parameter value</p>
+</td>
+</tr>
+</tbody>
+</table>
+</dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="singa.optimizer.SGD">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">SGD</code><span class="sig-paren">(</span><em>lr=None</em>, <em>momentum=None</em>, <em>weight_decay=None</em>, <em>lr_gen=None</em>, <em>regularizer=None</em>, <em>constraint=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.SGD" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <a class="reference internal" href="#singa.optimizer.Optimizer" title="singa.optimizer.Optimizer"><code class="xref py py-class docutils literal"><span class="pre">singa.optimizer.Optimizer</span></code></a></p>
+<p>The vallina Stochasitc Gradient Descent algorithm with momentum.</p>
+<p>See the base Optimizer for all arguments.</p>
+<dl class="method">
+<dt id="singa.optimizer.SGD.apply_with_lr">
+<code class="descname">apply_with_lr</code><span class="sig-paren">(</span><em>epoch</em>, <em>lr</em>, <em>grad</em>, <em>value</em>, <em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.SGD.apply_with_lr" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="singa.optimizer.Nesterov">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">Nesterov</code><span class="sig-paren">(</span><em>lr=None</em>, <em>momentum=0.9</em>, <em>weight_decay=None</em>, <em>lr_gen=None</em>, <em>regularizer=None</em>, <em>constraint=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.Nesterov" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <a class="reference internal" href="#singa.optimizer.Optimizer" title="singa.optimizer.Optimizer"><code class="xref py py-class docutils literal"><span class="pre">singa.optimizer.Optimizer</span></code></a></p>
+<p>The SGD with Nesterov momentum.</p>
+<p>See the base Optimizer for all arguments.</p>
+<dl class="method">
+<dt id="singa.optimizer.Nesterov.apply_with_lr">
+<code class="descname">apply_with_lr</code><span class="sig-paren">(</span><em>epoch</em>, <em>lr</em>, <em>grad</em>, <em>value</em>, <em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.Nesterov.apply_with_lr" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="singa.optimizer.AdaGrad">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">AdaGrad</code><span class="sig-paren">(</span><em>epsilon=1e-08</em>, <em>lr=None</em>, <em>weight_decay=None</em>, <em>lr_gen=None</em>, <em>regularizer=None</em>, <em>constraint=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.AdaGrad" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <a class="reference internal" href="#singa.optimizer.Optimizer" title="singa.optimizer.Optimizer"><code class="xref py py-class docutils literal"><span class="pre">singa.optimizer.Optimizer</span></code></a></p>
+<p>AdaGrad optimizer.</p>
+<p>See the base Optimizer for all constructor args.</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>epsilon</strong> (<em>float</em>) &#8211; small number for preventing numeric error.</td>
+</tr>
+</tbody>
+</table>
+<dl class="method">
+<dt id="singa.optimizer.AdaGrad.apply_with_lr">
+<code class="descname">apply_with_lr</code><span class="sig-paren">(</span><em>epoch</em>, <em>lr</em>, <em>grad</em>, <em>value</em>, <em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.AdaGrad.apply_with_lr" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="singa.optimizer.RMSProp">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">RMSProp</code><span class="sig-paren">(</span><em>rho=0.9</em>, <em>epsilon=1e-08</em>, <em>lr=None</em>, <em>weight_decay=None</em>, <em>lr_gen=None</em>, <em>regularizer=None</em>, <em>constraint=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.RMSProp" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <a class="reference internal" href="#singa.optimizer.Optimizer" title="singa.optimizer.Optimizer"><code class="xref py py-class docutils literal"><span class="pre">singa.optimizer.Optimizer</span></code></a></p>
+<p>RMSProp optimizer.</p>
+<p>See the base Optimizer for all constructor args.</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>rho</strong> (<em>float</em>) &#8211; float within [0, 1]</li>
+<li><strong>epsilon</strong> (<em>float</em>) &#8211; small value for preventing numeric error</li>
+</ul>
+</td>
+</tr>
+</tbody>
+</table>
+<dl class="method">
+<dt id="singa.optimizer.RMSProp.apply_with_lr">
+<code class="descname">apply_with_lr</code><span class="sig-paren">(</span><em>epoch</em>, <em>lr</em>, <em>grad</em>, <em>value</em>, <em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.RMSProp.apply_with_lr" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="singa.optimizer.Regularizer">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">Regularizer</code><a class="headerlink" href="#singa.optimizer.Regularizer" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
+<p>Base Python regularizer for parameter gradients.</p>
+<dl class="method">
+<dt id="singa.optimizer.Regularizer.apply">
+<code class="descname">apply</code><span class="sig-paren">(</span><em>value</em>, <em>grad</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.Regularizer.apply" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="singa.optimizer.CppRegularizer">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">CppRegularizer</code><span class="sig-paren">(</span><em>conf</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.CppRegularizer" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <a class="reference internal" href="#singa.optimizer.Regularizer" title="singa.optimizer.Regularizer"><code class="xref py py-class docutils literal"><span class="pre">singa.optimizer.Regularizer</span></code></a></p>
+<p>Wrapper for regularizer implemented using 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"><strong>conf</strong> (<em>RegularizerConf</em>) &#8211; protobuf message for the configuration.</td>
+</tr>
+</tbody>
+</table>
+<dl class="method">
+<dt id="singa.optimizer.CppRegularizer.apply">
+<code class="descname">apply</code><span class="sig-paren">(</span><em>epoch</em>, <em>value</em>, <em>grad</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.CppRegularizer.apply" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="singa.optimizer.L2Regularizer">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">L2Regularizer</code><span class="sig-paren">(</span><em>coefficient</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.L2Regularizer" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <a class="reference internal" href="#singa.optimizer.Regularizer" title="singa.optimizer.Regularizer"><code class="xref py py-class docutils literal"><span class="pre">singa.optimizer.Regularizer</span></code></a></p>
+<p>L2 regularization</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>coefficient</strong> (<em>float</em>) &#8211; regularization coefficient.</td>
+</tr>
+</tbody>
+</table>
+<dl class="method">
+<dt id="singa.optimizer.L2Regularizer.apply">
+<code class="descname">apply</code><span class="sig-paren">(</span><em>epoch</em>, <em>value</em>, <em>grad</em>, <em>coefficient=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.L2Regularizer.apply" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="singa.optimizer.Constraint">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">Constraint</code><a class="headerlink" href="#singa.optimizer.Constraint" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
+<p>Base Python constraint class for paramter gradients</p>
+<dl class="method">
+<dt id="singa.optimizer.Constraint.apply">
+<code class="descname">apply</code><span class="sig-paren">(</span><em>epoch</em>, <em>value</em>, <em>grad</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.Constraint.apply" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="singa.optimizer.CppConstraint">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">CppConstraint</code><span class="sig-paren">(</span><em>conf</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.CppConstraint" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <a class="reference internal" href="#singa.optimizer.Constraint" title="singa.optimizer.Constraint"><code class="xref py py-class docutils literal"><span class="pre">singa.optimizer.Constraint</span></code></a></p>
+<p>Wrapper for constraints implemented using 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"><strong>conf</strong> (<em>ConstraintConf</em>) &#8211; protobuf message for the configuration.</td>
+</tr>
+</tbody>
+</table>
+<dl class="method">
+<dt id="singa.optimizer.CppConstraint.apply">
+<code class="descname">apply</code><span class="sig-paren">(</span><em>epoch</em>, <em>value</em>, <em>grad</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.CppConstraint.apply" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</dd></dl>
+
+<dl class="class">
+<dt id="singa.optimizer.L2Constraint">
+<em class="property">class </em><code class="descclassname">singa.optimizer.</code><code class="descname">L2Constraint</code><span class="sig-paren">(</span><em>threshold=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.L2Constraint" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <a class="reference internal" href="#singa.optimizer.Constraint" title="singa.optimizer.Constraint"><code class="xref py py-class docutils literal"><span class="pre">singa.optimizer.Constraint</span></code></a></p>
+<p>Rescale the gradient to make the L2 norm &lt;= a given threshold</p>
+<dl class="method">
+<dt id="singa.optimizer.L2Constraint.apply">
+<code class="descname">apply</code><span class="sig-paren">(</span><em>epoch</em>, <em>value</em>, <em>grad</em>, <em>threshold=None</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.optimizer.L2Constraint.apply" title="Permalink to this definition">¶</a></dt>
+<dd></dd></dl>
+
+</dd></dl>
+
 </div>
 
 
@@ -171,7 +493,7 @@
   
     <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
       
-        <a href="../develop/schedule.html" class="btn btn-neutral float-right" title="Development Schedule" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
+        <a href="examples/index.html" class="btn btn-neutral float-right" title="Examples" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
       
       
         <a href="metric.html" class="btn btn-neutral" title="Metric" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>

Modified: incubator/singa/site/trunk/en/docs/software_stack.html
URL: http://svn.apache.org/viewvc/incubator/singa/site/trunk/en/docs/software_stack.html?rev=1756485&r1=1756484&r2=1756485&view=diff
==============================================================================
--- incubator/singa/site/trunk/en/docs/software_stack.html (original)
+++ incubator/singa/site/trunk/en/docs/software_stack.html Tue Aug 16 07:30:21 2016
@@ -105,6 +105,7 @@
 <li class="toctree-l2"><a class="reference internal" href="loss.html">Loss</a></li>
 <li class="toctree-l2"><a class="reference internal" href="metric.html">Metric</a></li>
 <li class="toctree-l2"><a class="reference internal" href="optimizer.html">Optimizer</a></li>
+<li class="toctree-l2"><a class="reference internal" href="examples/index.html">Examples</a></li>
 </ul>
 </li>
 </ul>

Modified: incubator/singa/site/trunk/en/docs/tensor.html
URL: http://svn.apache.org/viewvc/incubator/singa/site/trunk/en/docs/tensor.html?rev=1756485&r1=1756484&r2=1756485&view=diff
==============================================================================
--- incubator/singa/site/trunk/en/docs/tensor.html (original)
+++ incubator/singa/site/trunk/en/docs/tensor.html Tue Aug 16 07:30:21 2016
@@ -96,7 +96,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>
@@ -105,6 +105,7 @@
 <li class="toctree-l2"><a class="reference internal" href="loss.html">Loss</a></li>
 <li class="toctree-l2"><a class="reference internal" href="metric.html">Metric</a></li>
 <li class="toctree-l2"><a class="reference internal" href="optimizer.html">Optimizer</a></li>
+<li class="toctree-l2"><a class="reference internal" href="examples/index.html">Examples</a></li>
 </ul>
 </li>
 </ul>
@@ -182,8 +183,1091 @@ type of Device.</p>
 <li>&#8216;tensor_math_opencl.h&#8217; 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"><div class="highlight"><pre><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="c"># 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="c"># create a tensor from a numpy array</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="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">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="n">z</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="c"># gemm -&gt; z of shape (2, 3)</span>
+
+<span class="n">x</span> <span class="o">+=</span> <span class="n">z</span> <span class="c"># 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">create_cuda_gpu</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="c"># move the data to a gpu device</span>
+
+<span class="n">r</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">r</span><span class="o">.</span><span class="n">to_host</span><span class="p">()</span>  <span class="c"># move the data back to host cpu</span>
+<span class="n">s</span> <span class="o">=</span> <span class="n">r</span><span class="o">.</span><span class="n">to_numpy</span><span class="p">()</span>  <span class="c"># tensor -&gt; numpy array, r must be on cpu</span>
+</pre></div>
+</div>
+<p>There are two set 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.Tensor">
+<em class="property">class </em><code class="descclassname">singa.tensor.</code><code class="descname">Tensor</code><span class="sig-paren">(</span><em>shape=None</em>, <em>device=None</em>, <em>dtype=0</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.Tensor" title="Permalink to this definition">¶</a></dt>
+<dd><p>Create a Py Tensor, which wraps a swig converted Tensor from CPP Tensor</p>
+<p>The three arguments are three attributes of the 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>list&lt;int&gt;</em>) &#8211; a list of integers for the tensor shape. If shape is
+not specified, the created tensor is called a dummy tensor.</li>
+<li><strong>device</strong> &#8211; a swig converted Device instance using the device moduel . If it
+is None, then the default host device would be used.</li>
+<li><strong>dtype</strong> &#8211; data type. currently, most operations only accept kFloat32.</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>) &#8211; 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>) &#8211; 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>) &#8211; 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>) &#8211; 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> &#8211; source numpy array</li>
+<li><strong>offset</strong> (<em>int</em>) &#8211; 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>) &#8211; 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>) &#8211; 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>) &#8211; mean of the distribution</li>
+<li><strong>std</strong> (<em>float</em>) &#8211; standard variance of the distribution</li>
+</ul>
+</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>) &#8211; 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>) &#8211; 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>) &#8211; </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&lt;int&gt;</em>) &#8211; 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>) &#8211; </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> &#8211; 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>) &#8211; the lower bound</li>
+<li><strong>high</strong> (<em>float</em>) &#8211; 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>) &#8211; 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>) &#8211; </li>
+<li><strong>rhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; </li>
+<li><strong>ret</strong> (<em>Tensor, optional</em>) &#8211; 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>) &#8211; </li>
+<li><strong>v</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; </li>
+<li><strong>beta</strong> (<em>float</em>) &#8211; </li>
+<li><strong>M</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; 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>) &#8211; </li>
+<li><strong>v</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; </li>
+<li><strong>beta</strong> (<em>float</em>) &#8211; </li>
+<li><strong>M</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; 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>) &#8211; input Tensor</li>
+<li><strong>axis</strong> (<em>int, optional</em>) &#8211; 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>) &#8211; </li>
+<li><strong>x</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; </li>
+<li><strong>y</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; </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>) &#8211; 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>) &#8211; 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>) &#8211; destination Tensor</li>
+<li><strong>src</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; source Tensor</li>
+<li><strong>size</strong> (<em>int</em>) &#8211; number of elements to copy</li>
+<li><strong>dst_offset</strong> (<em>int</em>) &#8211; offset in terms of elements to the start of dst</li>
+<li><strong>src_offset</strong> (<em>int</em>) &#8211; 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.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>) &#8211; </li>
+<li><strong>rhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; </li>
+<li><strong>ret</strong> (<em>Tensor, optional</em>) &#8211; 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.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>) &#8211; </li>
+<li><strong>rhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; </li>
+<li><strong>ret</strong> (<em>Tensor, optional</em>) &#8211; 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>) &#8211; 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> &#8211; 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>) &#8211; the mean of the Gaussian distribution.</li>
+<li><strong>std</strong> (<em>float</em>) &#8211; 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>) &#8211; 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 &gt;= 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>) &#8211; left hand side operand</li>
+<li><strong>x</strong> (<em>Tensor or float</em>) &#8211; 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] &gt;= 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] &gt;= 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 &gt; 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>) &#8211; left hand side operand</li>
+<li><strong>x</strong> (<em>Tensor or float</em>) &#8211; 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] &gt; 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] &gt; 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 &lt;= 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>) &#8211; left hand side operand</li>
+<li><strong>x</strong> (<em>Tensor or float</em>) &#8211; 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] &lt;= 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] &lt;= 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>) &#8211; 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 &lt; 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>) &#8211; left hand side operand</li>
+<li><strong>x</strong> (<em>Tensor or float</em>) &#8211; 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] &lt; 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] &lt; 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>) &#8211; 2d Tensor</li>
+<li><strong>B</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; If B is a 1d Tensor, GEMV would be invoked for matrix-vector
+multiplication; otherwise GEMM would be invoked.</li>
+<li><strong>C</strong> (<em>Tensor, optional</em>) &#8211; for storing the result; If None, a new Tensor
+would be created.</li>
+<li><strong>alpha</strong> (<em>float</em>) &#8211; </li>
+<li><strong>beta</strong> (<em>float</em>) &#8211; </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>) &#8211; input tensor</li>
+<li><strong>x</strong> (<em>float or Tensor</em>) &#8211; 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 or Tensor</em>) &#8211; 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.relu">
+<code class="descclassname">singa.tensor.</code><code class="descname">relu</code><span class="sig-paren">(</span><em>t</em><span class="sig-paren">)</span><a class="headerlink" href="#singa.tensor.relu" 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>) &#8211; 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 if x &gt;0; otherwise 0; x is an element
+of t</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>) &#8211; the tensor to be changed</li>
+<li><strong>s</strong> (<em>list&lt;int&gt;</em>) &#8211; 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>) &#8211; 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.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.</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>) &#8211; the input 1d or 2d tensor</li>
+<li><strong>out</strong> (<em>Tensor, optional</em>) &#8211; if not None, it is used to store 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.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>) &#8211; 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>) &#8211; </li>
+<li><strong>rhs</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; </li>
+<li><strong>ret</strong> (<em>Tensor, optional</em>) &#8211; 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>) &#8211; input Tensor</li>
+<li><strong>axis</strong> (<em>int, optional</em>) &#8211; if None, the summation is done over all elements;
+if axis is provided, then it is calculated along the given axis,
+e.g. 0 &#8211; sum each column; 1 &#8211; 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>) &#8211; 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>) &#8211; 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>) &#8211; 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_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>Convert the tensor into a numpy array.</p>
+<p>Since numpy array is allocated on CPU devices, the input Tensor instance
+must be on the default CppCPU 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>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; </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>) &#8211; the lower bound</li>
+<li><strong>hight</strong> (<em>float</em>) &#8211; the higher bound</li>
+<li><strong>t</strong> (<a class="reference internal" href="#singa.tensor.Tensor" title="singa.tensor.Tensor"><em>Tensor</em></a>) &#8211; 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>




Mime
View raw message